diff options
author | Pavel Zuna <pzuna@redhat.com> | 2009-06-15 15:59:20 +0200 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2009-06-15 11:19:04 -0400 |
commit | 2ff4b3906ffbcd89330e40fa7f69f5c668996b72 (patch) | |
tree | 989cf3bf7e078c5a1d686e53a2c9d6ad3b4d2b73 /ipalib | |
parent | 48e1f47ed130110db953aaf6a765faab438e1305 (diff) | |
download | freeipa-2ff4b3906ffbcd89330e40fa7f69f5c668996b72.tar.gz freeipa-2ff4b3906ffbcd89330e40fa7f69f5c668996b72.tar.xz freeipa-2ff4b3906ffbcd89330e40fa7f69f5c668996b72.zip |
Change plugins2 using find_entries to support incomplete (truncated) search results.
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/plugins/basegroup2.py | 55 | ||||
-rw-r--r-- | ipalib/plugins/dns2.py | 38 | ||||
-rw-r--r-- | ipalib/plugins/host2.py | 15 | ||||
-rw-r--r-- | ipalib/plugins/service2.py | 15 | ||||
-rw-r--r-- | ipalib/plugins/user2.py | 16 |
5 files changed, 98 insertions, 41 deletions
diff --git a/ipalib/plugins/basegroup2.py b/ipalib/plugins/basegroup2.py index 79dbfa0b..159a0973 100644 --- a/ipalib/plugins/basegroup2.py +++ b/ipalib/plugins/basegroup2.py @@ -30,14 +30,6 @@ _default_attributes = ['cn', 'description', 'member', 'memberof'] _default_class = 'groupofnames' -def get_dn_by_attr(ldap, attr, value, object_class, parent_dn=''): - search_kw = {} - search_kw[attr] = value - search_kw['objectclass'] = object_class - filter = ldap.make_filter(search_kw, rules=ldap.MATCH_ALL) - (dn, entry_attrs) = ldap.find_entries(filter, [''], base_dn=parent_dn)[0] - return dn - def find_members(ldap, failed, members, attr, object_class, parent_dn=''): """ Search for a list of members to operate on. @@ -55,7 +47,9 @@ def find_members(ldap, failed, members, attr, object_class, parent_dn=''): for m in members: if not m: continue try: - member_dn = get_dn_by_attr(ldap, attr, m, object_class, parent_dn) + (member_dn, entry_attrs) = ldap.find_entry_by_attr( + attr, m, object_classs, parent_dn + ) found.append(member_dn) except errors.NotFound: failed.append(m) @@ -203,7 +197,10 @@ class basegroup2_delete(crud.Delete): assert self.container assert self.api.env.use_ldap2, 'use_ldap2 is False' ldap = self.api.Backend.ldap2 - dn = get_dn_by_attr(ldap, 'cn', cn, self.filter_class, self.container) + + (dn, entry_attrs) = ldap.find_entry_by_attr( + 'cn', cn, self.filter_class, self.container + ) ldap.delete_entry(dn) @@ -242,7 +239,10 @@ class basegroup2_mod(crud.Update): assert self.filter_class assert self.api.env.use_ldap2, 'use_ldap2 is False' ldap = self.api.Backend.ldap2 - dn = get_dn_by_attr(ldap, 'cn', cn, self.filter_class, self.container) + + (dn, entry_attrs) = ldap.find_entry_by_attr( + 'cn', cn, self.filter_class, self.container_dn + ) entry_attrs = self.args_options_2_entry(cn, **kw) if 'objectclass' in kw: @@ -311,22 +311,30 @@ class basegroup2_find(crud.Search): parent_dn = self.container or '' try: - entries = ldap.find_entries(filter, attrs_list, parent_dn) + (entries, truncated) = ldap.find_entries( + filter, attrs_list, parent_dn + ) except errors.NotFound: - entries = tuple() + (entries, truncated) = (tuple(), False) - return entries + return (entries, truncated) def output_for_cli(self, textui, result, criteria, **options): + (entries, truncated) = result + textui.print_name(self.name) - for e in result: - (dn, entry_attrs) = e + for (dn, entry_attrs) in entries: textui.print_attribute('dn', dn) textui.print_entry(entry_attrs) textui.print_plain('') textui.print_count( len(result), '%i group matched.', '%i groups matched.' ) + if truncated: + textui.print_dashed('These results are truncated.', below=False) + textui.print_dashed( + 'Please refine your search and try again.', above=False + ) class basegroup2_show(crud.Retrieve): @@ -358,7 +366,10 @@ class basegroup2_show(crud.Retrieve): assert self.container assert self.api.env.use_ldap2, 'use_ldap2 is False' ldap = self.api.Backend.ldap2 - dn = get_dn_by_attr(ldap, 'cn', cn, self.filter_class, self.container) + + (dn, entry_attrs) = ldap.find_entry_by_attr( + 'cn', cn, self.filter_class, self.container + ) if kw['all']: attrs_list = ['*'] @@ -415,11 +426,14 @@ class basegroup2_add_member(Command): assert self.container assert self.api.env.use_ldap2, 'use_ldap2 is False' ldap = self.api.Backend.ldap2 - dn = get_dn_by_attr(ldap, 'cn', cn, self.filter_class, self.container) to_add = [] add_failed = [] completed = 0 + (dn, entry_attrs) = ldap.find_entry_by_attrs( + 'cn', cn, self.filter_class, self.container + ) + members = kw.get('groups', []) (to_add, add_failed) = find_members( ldap, add_failed, members, 'cn', 'ipausergroup', @@ -492,11 +506,14 @@ class basegroup2_del_member(Command): assert self.container assert self.api.env.use_ldap2, 'use_ldap2 is False' ldap = self.api.Backend.ldap2 - dn = get_dn_by_attr(ldap, 'cn', cn, self.filter_class, self.container) to_remove = [] remove_failed = [] completed = 0 + (dn, entry_attrs) = ldap.find_entry_by_attrs( + 'cn', cn, self.filter_class, self.container + ) + members = kw.get('groups', []) (to_remove, remove_failed) = find_members( ldap, remove_failed, members, 'cn', 'ipausergroup', diff --git a/ipalib/plugins/dns2.py b/ipalib/plugins/dns2.py index 8b340879..17de2d7b 100644 --- a/ipalib/plugins/dns2.py +++ b/ipalib/plugins/dns2.py @@ -228,9 +228,11 @@ class dns2_delete(crud.Delete): # retrieve all subentries of zone - records try: - entries = ldap.find_entries(None, [''], dn, ldap.SCOPE_ONELEVEL) + (entries, truncated) = ldap.find_entries( + None, [''], dn, ldap.SCOPE_ONELEVEL + ) except errors.NotFound: - entries = tuple() + (entries, truncated) = (tuple(), False) # kill'em all, records first for e in entries: @@ -309,24 +311,30 @@ class dns2_find(crud.Search): # get matching entries try: - entries = ldap.find_entries( + (entries, truncated) = ldap.find_entries( filter, attrs_list, _zone_container_dn, ldap.SCOPE_ONELEVEL ) except errors.NotFound: - entries = tuple() + (entries, truncated) = (tuple(), False) return entries def output_for_cli(self, textui, result, term, **options): + (entries, truncated) = result + textui.print_name(self.name) - for e in result: - (dn, entry_attrs) = e + for (dn, entry_attrs) in entries: textui.print_attribute('dn', dn) textui.print_entry(entry_attrs) textui.print_plain('') textui.print_count( len(result), '%i DNS zone matched.', '%i DNS zones matched.' ) + if truncated: + textui.print_dashed('These results are truncated.', below=False) + textui.print_dashed( + 'Please refine your search and try again.', above=False + ) api.register(dns2_find) @@ -716,9 +724,11 @@ class dns2_find_rr(Command): # get matching entries try: - entries = ldap.find_entries(filter, attrs_list, base_dn) + (entries, truncated) = ldap.find_entries( + filter, attrs_list, base_dn + ) except errors.NotFound: - entries = tuple() + (entries, truncated) = (tuple(), False) # if the user is looking for a certain record type, don't display # entries that do not contain it @@ -730,12 +740,13 @@ class dns2_find_rr(Command): related_entries.append(e) entries = related_entries - return entries + return (entries, truncated) def output_for_cli(self, textui, result, zone, term, **options): + (entries, truncated) = result + textui.print_name(self.name) - for e in result: - (dn, entry_attrs) = e + for (dn, entry_attrs) in entries: textui.print_attribute('dn', dn) textui.print_entry(entry_attrs) textui.print_plain('') @@ -743,6 +754,11 @@ class dns2_find_rr(Command): len(result), '%i DNS resource record matched.', '%i DNS resource records matched.' ) + if truncated: + textui.print_dashed('These results are truncated.', below=False) + textui.print_dashed( + 'Please refine your search and try again.', above=False + ) api.register(dns2_find_rr) diff --git a/ipalib/plugins/host2.py b/ipalib/plugins/host2.py index 02a2a6ed..52f1d3a3 100644 --- a/ipalib/plugins/host2.py +++ b/ipalib/plugins/host2.py @@ -308,21 +308,30 @@ class host2_find(crud.Search): attrs_list = _default_attributes try: - entries = ldap.find_entries(filter, attrs_list, _container_dn) + (entries, truncated) = ldap.find_entries( + filter, attrs_list, _container_dn + ) except errors.NotFound: - entries = tuple() + (entries, truncated) = (tuple(), False) return entries def output_for_cli(self, textui, result, term, **options): + (entries, truncated) = result + textui.print_name(self.name) - for (dn, entry_attrs) in result: + for (dn, entry_attrs) in entries: textui.print_attribute('dn', dn) textui.print_entry(entry_attrs) textui.print_plain('') textui.print_count( len(result), '%i host matched.', '%i hosts matched.' ) + if truncated: + textui.print_dashed('These results are truncated.', below=False) + textui.print_dashed( + 'Please refine your search and try again.', above=False + ) api.register(host2_find) diff --git a/ipalib/plugins/service2.py b/ipalib/plugins/service2.py index 21b5a164..7b21b584 100644 --- a/ipalib/plugins/service2.py +++ b/ipalib/plugins/service2.py @@ -292,21 +292,30 @@ class service2_find(crud.Search): attrs_list = _default_attributes try: - entries = ldap.find_entries(filter, attrs_list, _container_dn) + (entries, truncated) = ldap.find_entries( + filter, attrs_list, _container_dn + ) except errors.NotFound: - entries = tuple() + (entries, truncated) = (tuple(), False) return entries def output_for_cli(self, textui, result, principal, **options): + (entries, truncated) = result + textui.print_name(self.name) - for (dn, entry_attrs) in result: + for (dn, entry_attrs) in entries: textui.print_attribute('dn', dn) textui.print_entry(entry_attrs) textui.print_plain('') textui.print_count( len(result), '%i service matched.', '%i services matched.' ) + if truncated: + textui.print_dashed('These results are truncated.', below=False) + textui.print_dashed( + 'Please refine your search and try again.', above=False + ) api.register(service2_find) diff --git a/ipalib/plugins/user2.py b/ipalib/plugins/user2.py index 2d74a6d1..bf24e4d0 100644 --- a/ipalib/plugins/user2.py +++ b/ipalib/plugins/user2.py @@ -274,24 +274,30 @@ class user2_find(crud.Search): # get matching entries try: - entries = ldap.find_entries( + (entries, truncated) = ldap.find_entries( filter, attrs_list, _container_dn, ldap.SCOPE_ONELEVEL ) except errors.NotFound: - entries = tuple() + (entries, truncated) = (tuple(), False) - return entries + return (entries, truncated) def output_for_cli(self, textui, result, term, **options): + (entries, truncated) = result + textui.print_name(self.name) - for e in result: - (dn, entry_attrs) = e + for (dn, entry_attrs) in entries: textui.print_attribute('dn', dn) textui.print_entry(entry_attrs) textui.print_plain('') textui.print_count( len(result), '%i user matched.', '%i users matched.' ) + if truncated: + textui.print_dashed('These results are truncated.', below=False) + textui.print_dashed( + 'Please refine your search and try again.', above=False + ) api.register(user2_find) |