Convert remaining update code to LDAPEntry API.

This commit is contained in:
Jan Cholasta 2013-10-31 16:55:07 +00:00 committed by Petr Viktorin
parent 08051f1651
commit 97c1c95f20
8 changed files with 25 additions and 28 deletions

View File

@ -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

View File

@ -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)

View File

@ -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",

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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:

View File

@ -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)