diff options
author | Petr Viktorin <pviktori@redhat.com> | 2015-04-01 16:37:51 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-04-23 11:34:39 +0000 |
commit | 5b3ee6842f464119d41066b20959b05922249558 (patch) | |
tree | c70bdf78073cde527285b146bf679c307116dd2f /ipaserver/install/plugins | |
parent | 22d3a93bbcf86a610c772added9103ffc188964e (diff) | |
download | freeipa-5b3ee6842f464119d41066b20959b05922249558.tar.gz freeipa-5b3ee6842f464119d41066b20959b05922249558.tar.xz freeipa-5b3ee6842f464119d41066b20959b05922249558.zip |
rename_managed: Remove use of EditableDN
This was the last use of EditableDN in IPA; the class can now be removed.
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipaserver/install/plugins')
-rw-r--r-- | ipaserver/install/plugins/rename_managed.py | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/ipaserver/install/plugins/rename_managed.py b/ipaserver/install/plugins/rename_managed.py index 02f91e73b..f37f87d86 100644 --- a/ipaserver/install/plugins/rename_managed.py +++ b/ipaserver/install/plugins/rename_managed.py @@ -20,7 +20,7 @@ from ipalib import api, errors from ipalib import Updater from ipapython import ipautil -from ipapython.dn import DN, EditableDN +from ipapython.dn import DN def entry_to_update(entry): """ @@ -40,7 +40,19 @@ def entry_to_update(entry): return update + class GenerateUpdateMixin(object): + def _dn_suffix_replace(self, dn, old_suffix, new_suffix): + """Replace all occurences of "old" AVAs in a DN by "new" + + If the input DN doesn't end with old_suffix, log, an raise ValueError. + """ + if not dn.endswith(old_suffix): + self.error("unable to replace suffix '%s' with '%s' in '%s'", + old_suffix, new_suffix, dn) + raise ValueError('no replacement made') + return DN(*dn[:-len(old_suffix)]) + new_suffix + def generate_update(self, deletes=False): """ We need to separate the deletes that need to happen from the @@ -81,14 +93,14 @@ class GenerateUpdateMixin(object): pass else: # Compute the new dn by replacing the old container with the new container - 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, entry.dn) + try: + new_dn = self._dn_suffix_replace( + entry.dn, + old_suffix=old_template_container, + new_suffix=new_template_container) + except ValueError: continue - new_dn = DN(new_dn) - # The old attributes become defaults for the new entry new_update = {'dn': new_dn, 'default': entry_to_update(entry)} @@ -102,23 +114,23 @@ class GenerateUpdateMixin(object): else: # Update the template dn by replacing the old containter with the new container - old_dn = entry['managedtemplate'][0] - new_dn = EditableDN(old_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) + try: + new_dn = self._dn_suffix_replace( + entry['managedtemplate'][0], + old_suffix=old_template_container, + new_suffix=new_template_container) + except ValueError: continue - new_dn = DN(new_dn) entry['managedtemplate'] = new_dn - # Edit the dn, then convert it back to an immutable DN - old_dn = entry.dn - new_dn = EditableDN(old_dn) - if new_dn.replace(old_definition_container, new_definition_container) != 1: - self.error("unable to replace '%s' with '%s' in '%s'", - old_definition_container, new_definition_container, old_dn) + # Update the entry dn similarly + try: + new_dn = self._dn_suffix_replace( + entry.dn, + old_suffix=old_definition_container, + new_suffix=new_definition_container) + except ValueError: continue - new_dn = DN(new_dn) # The old attributes become defaults for the new entry new_update = {'dn': new_dn, |