summaryrefslogtreecommitdiffstats
path: root/server/config/SSSDConfig.py
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2009-12-08 23:27:52 -0500
committerStephen Gallagher <sgallagh@redhat.com>2009-12-08 23:35:25 -0500
commite51458f89be94b86d6b5dab0c8ebe0e7ba197003 (patch)
treea0f1a1b1e70acc6a8b7ae47e4b90ebc9cff158c9 /server/config/SSSDConfig.py
parentcb58da00f547c5a78718ec35ec27ae83d2b59099 (diff)
downloadsssd-e51458f89be94b86d6b5dab0c8ebe0e7ba197003.tar.gz
sssd-e51458f89be94b86d6b5dab0c8ebe0e7ba197003.tar.xz
sssd-e51458f89be94b86d6b5dab0c8ebe0e7ba197003.zip
Add SSSDDomain.set_name() function to SSSDConfig API
This function will change the name of an existing domain
Diffstat (limited to 'server/config/SSSDConfig.py')
-rw-r--r--server/config/SSSDConfig.py44
1 files changed, 41 insertions, 3 deletions
diff --git a/server/config/SSSDConfig.py b/server/config/SSSDConfig.py
index 2abafe15a..3b8c128e2 100644
--- a/server/config/SSSDConfig.py
+++ b/server/config/SSSDConfig.py
@@ -743,6 +743,29 @@ class SSSDDomain(SSSDConfigObject):
else:
self.options[option] = value
+ def set_name(self, newname):
+ """
+ Change the name of the domain
+
+ newname:
+ New name for this domain
+
+ === Returns ===
+ No return value.
+
+ === Errors ===
+ TypeError:
+ newname was not a string
+ """
+
+ if type(newname) != str:
+ raise TypeError
+
+ if not self.oldname:
+ # Only set the oldname once
+ self.oldname = self.name
+ self.name = newname
+
def add_provider(self, provider, provider_type):
"""
Add a new provider type to the domain
@@ -819,14 +842,14 @@ class SSSDDomain(SSSDConfigObject):
# Remove any unused options when removing the provider.
options = self.list_provider_options(provider, provider_type)
-
+
# Trim any options that are used by other providers,
# if that provider is in use
for (prov, ptype) in self.providers:
# Ignore the one being removed
if (prov, ptype) == (provider, provider_type):
continue
-
+
provider_options = self.list_provider_options(prov, ptype)
overlap = options_overlap(options.keys(), provider_options.keys())
for opt in overlap:
@@ -1286,6 +1309,18 @@ class SSSDConfig(SSSDChangeConf):
raise TypeError
name = domain.get_name()
+
+ oldindex = None
+ if domain.oldname and domain.oldname != name:
+ # We are renaming this domain
+ # Remove the old section
+ oldindex = self.delete_option('section', 'domain/%s' %
+ domain.oldname)
+
+ # Reset the oldname, in case we're not done with
+ # this domain object.
+ domain.oldname = None;
+
sectionname = 'domain/%s' % name
# Ensure that the existing section is removed
# This way we ensure that we are getting a
@@ -1300,7 +1335,10 @@ class SSSDConfig(SSSDChangeConf):
addkw.append( { 'type' : 'option',
'name' : option,
'value' : str(value) } )
- self.add_section(sectionname, addkw, index)
+ if oldindex:
+ self.add_section(sectionname, addkw, oldindex)
+ else:
+ self.add_section(sectionname, addkw, index)
if domain.active:
if domain.get_name not in self.list_active_domains():