diff options
author | Rob Crittenden <rcritten@redhat.com> | 2011-02-11 13:29:55 -0500 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2011-02-14 13:55:30 -0500 |
commit | 77e1ef2f808f86656a4b6a80a154dd5fe58dc295 (patch) | |
tree | 92cce1ba7d9fd8af42f4f392e5edc6c6c1b5e858 /ipaserver/install/ldapupdate.py | |
parent | 5341a22ba2dec5099c8a14c0903c7770884ee6be (diff) | |
download | freeipa-77e1ef2f808f86656a4b6a80a154dd5fe58dc295.tar.gz freeipa-77e1ef2f808f86656a4b6a80a154dd5fe58dc295.tar.xz freeipa-77e1ef2f808f86656a4b6a80a154dd5fe58dc295.zip |
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
Diffstat (limited to 'ipaserver/install/ldapupdate.py')
-rw-r--r-- | ipaserver/install/ldapupdate.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py index 939f0455..f8128fc3 100644 --- a/ipaserver/install/ldapupdate.py +++ b/ipaserver/install/ldapupdate.py @@ -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) |