Add a replace option to ipa-ldap-updater.

We have no way to say "replace value X with Y". This would be useful
for us to replace a default value only if the user hasn't already
updated it.

related to ticket 930
This commit is contained in:
Rob Crittenden 2011-02-11 13:29:55 -05:00
parent 5341a22ba2
commit 77e1ef2f80

View File

@ -218,7 +218,7 @@ class LDAPUpdate:
def parse_update_file(self, data, all_updates, dn_list):
"""Parse the update file into a dictonary of lists and apply the update
for each DN in the file."""
valid_keywords = ["default", "add", "remove", "only", "deleteentry"]
valid_keywords = ["default", "add", "remove", "only", "deleteentry", "replace"]
update = {}
d = ""
index = ""
@ -441,6 +441,19 @@ class LDAPUpdate:
elif utype == 'deleteentry':
# skip this update type, it occurs in __delete_entries()
return None
elif utype == 'replace':
# v has the format "old: new"
try:
(old, new) = v.split(':', 1)
except ValueError:
raise BadSyntax, "bad syntax in replace, needs to be in the format old: new in %s" % new_entry.dn
try:
e.remove(old)
e.append(new)
logging.debug('replace: updated value %s', e)
entry.setValues(k, e)
except ValueError:
logging.debug('replace: %s not found, skipping', old)
self.print_entity(entry)