From 97c1c95f20762055932a83cb7ac08a408437a661 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Thu, 31 Oct 2013 16:55:07 +0000 Subject: Convert remaining update code to LDAPEntry API. --- ipaserver/install/plugins/adtrust.py | 4 ++-- ipaserver/install/plugins/dns.py | 2 +- ipaserver/install/plugins/fix_replica_agreements.py | 4 ++-- ipaserver/install/plugins/rename_managed.py | 10 +++++----- ipaserver/install/plugins/update_anonymous_aci.py | 4 ++-- ipaserver/install/plugins/update_idranges.py | 16 +++++++--------- ipaserver/install/plugins/update_services.py | 11 +++++------ ipaserver/install/plugins/upload_cacrt.py | 2 +- 8 files changed, 25 insertions(+), 28 deletions(-) (limited to 'ipaserver/install/plugins') diff --git a/ipaserver/install/plugins/adtrust.py b/ipaserver/install/plugins/adtrust.py index 28358588b..d567aea8e 100644 --- a/ipaserver/install/plugins/adtrust.py +++ b/ipaserver/install/plugins/adtrust.py @@ -46,7 +46,7 @@ class update_default_range(PostUpdate): dn = DN(('cn', 'admins'), api.env.container_group, api.env.basedn) try: - (dn, admins_entry) = ldap.get_entry(dn, ['gidnumber']) + admins_entry = ldap.get_entry(dn, ['gidnumber']) except errors.NotFound: root_logger.error("default_range: No local ID range and no admins " "group found. Cannot create default ID range") @@ -88,7 +88,7 @@ class update_default_range(PostUpdate): else: masters = set() remaining_values_sum = 0 - for entry_dn, entry in entries: + for entry in entries: hostname = entry.get('dnahostname', [None])[0] if hostname is None or hostname in masters: continue diff --git a/ipaserver/install/plugins/dns.py b/ipaserver/install/plugins/dns.py index b875ff019..6e6c52f26 100644 --- a/ipaserver/install/plugins/dns.py +++ b/ipaserver/install/plugins/dns.py @@ -160,7 +160,7 @@ class update_dns_limits(PostUpdate): self.env.basedn) try: - (dn, entry) = ldap.get_entry(dns_service_dn, self.limit_attributes) + entry = ldap.get_entry(dns_service_dn, self.limit_attributes) except errors.NotFound: # this host may not have DNS service set root_logger.debug("DNS: service %s not found, no need to update limits" % dns_service_dn) diff --git a/ipaserver/install/plugins/fix_replica_agreements.py b/ipaserver/install/plugins/fix_replica_agreements.py index bfd6356bf..a5ff4819f 100644 --- a/ipaserver/install/plugins/fix_replica_agreements.py +++ b/ipaserver/install/plugins/fix_replica_agreements.py @@ -89,7 +89,7 @@ class update_replica_attribute_lists(PreUpdate): replica[attribute] = [template % " ".join(values)] try: - repl.conn.update_entry(replica.dn, replica) + repl.conn.update_entry(replica) self.log.debug("Updated") except Exception, e: self.log.error("Error caught updating replica: %s", str(e)) @@ -107,7 +107,7 @@ class update_replica_attribute_lists(PreUpdate): '%s %s' % (attrlist, ' '.join(missing))] try: - repl.conn.update_entry(replica.dn, replica) + repl.conn.update_entry(replica) self.log.debug("Updated %s", attribute) except Exception, e: self.log.error("Error caught updating %s: %s", diff --git a/ipaserver/install/plugins/rename_managed.py b/ipaserver/install/plugins/rename_managed.py index dad9259da..13e6dae5d 100644 --- a/ipaserver/install/plugins/rename_managed.py +++ b/ipaserver/install/plugins/rename_managed.py @@ -77,15 +77,15 @@ class GenerateUpdateMixin(object): old_dn = entry['managedtemplate'][0] assert isinstance(old_dn, DN) try: - (old_dn, entry) = ldap.get_entry(old_dn, ['*']) + entry = ldap.get_entry(old_dn, ['*']) except errors.NotFound, e: pass else: # Compute the new dn by replacing the old container with the new container - new_dn = EditableDN(old_dn) + new_dn = EditableDN(entry.dn) if new_dn.replace(old_template_container, new_template_container) != 1: self.error("unable to replace '%s' with '%s' in '%s'", - old_template_container, new_template_container, old_dn) + old_template_container, new_template_container, entry.dn) continue new_dn = DN(new_dn) @@ -95,10 +95,10 @@ class GenerateUpdateMixin(object): 'default': entry_to_update(entry)} # Delete the old entry - old_update = {'dn': old_dn, 'deleteentry': None} + old_update = {'dn': entry.dn, 'deleteentry': None} # Add the delete and replacement updates to the list of all updates - update_list.append({old_dn: old_update, new_dn: new_update}) + update_list.append({entry.dn: old_update, new_dn: new_update}) else: # Update the template dn by replacing the old containter with the new container diff --git a/ipaserver/install/plugins/update_anonymous_aci.py b/ipaserver/install/plugins/update_anonymous_aci.py index 2e01217f5..0425754d5 100644 --- a/ipaserver/install/plugins/update_anonymous_aci.py +++ b/ipaserver/install/plugins/update_anonymous_aci.py @@ -38,7 +38,7 @@ class update_anonymous_aci(PostUpdate): targetfilter = '(&(!(objectClass=ipaToken))(!(objectClass=ipatokenTOTP))(!(objectClass=ipatokenRadiusConfiguration)))' filter = None - (dn, entry_attrs) = ldap.get_entry(api.env.basedn, ['aci']) + entry_attrs = ldap.get_entry(api.env.basedn, ['aci']) acistrs = entry_attrs.get('aci', []) acilist = aci._convert_strings_to_acis(entry_attrs.get('aci', [])) @@ -87,7 +87,7 @@ class update_anonymous_aci(PostUpdate): entry_attrs['aci'] = acistrs try: - ldap.update_entry(dn, entry_attrs) + ldap.update_entry(entry_attrs) except Exception, e: root_logger.error("Failed to update Anonymous ACI: %s" % e) diff --git a/ipaserver/install/plugins/update_idranges.py b/ipaserver/install/plugins/update_idranges.py index c3df98af9..9e97c9f74 100644 --- a/ipaserver/install/plugins/update_idranges.py +++ b/ipaserver/install/plugins/update_idranges.py @@ -71,27 +71,25 @@ class update_idrange_type(PostUpdate): error = False # Set the range type - for dn, entry in entries: - update = {} - + for entry in entries: objectclasses = [o.lower() for o in entry.get('objectclass', [])] if 'ipatrustedaddomainrange' in objectclasses: # NOTICE: assumes every AD range does not use POSIX # attributes - update['ipaRangeType'] = 'ipa-ad-trust' + entry['ipaRangeType'] = ['ipa-ad-trust'] elif 'ipadomainidrange' in objectclasses: - update['ipaRangeType'] = 'ipa-local' + entry['ipaRangeType'] = ['ipa-local'] else: - update['ipaRangeType'] = 'unknown' + entry['ipaRangeType'] = ['unknown'] root_logger.error("update_idrange_type: could not detect " - "range type for entry: %s" % str(dn)) + "range type for entry: %s" % str(entry.dn)) root_logger.error("update_idrange_type: ID range type set " - "to 'unknown' for entry: %s" % str(dn)) + "to 'unknown' for entry: %s" % str(entry.dn)) try: - ldap.update_entry(dn, update) + ldap.update_entry(entry) except (errors.EmptyModlist, errors.NotFound): pass except errors.ExecutionError, e: diff --git a/ipaserver/install/plugins/update_services.py b/ipaserver/install/plugins/update_services.py index c384af52f..2122abb10 100644 --- a/ipaserver/install/plugins/update_services.py +++ b/ipaserver/install/plugins/update_services.py @@ -66,13 +66,12 @@ class update_service_principalalias(PostUpdate): len(entries), truncated) error = False - for dn, entry in entries: - update = {} - update['objectclass'] = (entry['objectclass'] + - ['ipakrbprincipal']) - update['ipakrbprincipalalias'] = entry['krbprincipalname'] + for entry in entries: + entry['objectclass'] = (entry['objectclass'] + + ['ipakrbprincipal']) + entry['ipakrbprincipalalias'] = entry['krbprincipalname'] try: - ldap.update_entry(dn, update) + ldap.update_entry(entry) except (errors.EmptyModlist, errors.NotFound): pass except errors.ExecutionError, e: diff --git a/ipaserver/install/plugins/upload_cacrt.py b/ipaserver/install/plugins/upload_cacrt.py index a82fc36bf..1da8e886c 100644 --- a/ipaserver/install/plugins/upload_cacrt.py +++ b/ipaserver/install/plugins/upload_cacrt.py @@ -33,7 +33,7 @@ class update_upload_cacrt(PostUpdate): def execute(self, **options): ldap = self.obj.backend - (cdn, ipa_config) = ldap.get_ipa_config() + ipa_config = ldap.get_ipa_config() subject_base = ipa_config.get('ipacertificatesubjectbase', [None])[0] dirname = config_dirname(realm_to_serverid(api.env.realm)) certdb = certs.CertDB(api.env.realm, nssdir=dirname, subject_base=subject_base) -- cgit