summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2008-01-22 11:58:06 +0000
committerMark McLoughlin <markmc@redhat.com>2008-01-22 11:58:06 +0000
commit11266d039f6c59be1bf8ce888972d012ce49ddf6 (patch)
tree4b251571c8ef18ec1484808d0bf5c34c5b471098
parent5fd10b5f98588892cdd832c0c71dc4a98cc135ee (diff)
downloadfreeipa-11266d039f6c59be1bf8ce888972d012ce49ddf6.tar.gz
freeipa-11266d039f6c59be1bf8ce888972d012ce49ddf6.tar.xz
freeipa-11266d039f6c59be1bf8ce888972d012ce49ddf6.zip
Re-factor the ipa_webgui and ipa_kpasswd instance code
The ipa_webgui and ipa_kpasswd instance code is identical and I want to add another similar instance down the line, so re-factor the code into a service.SimpleServiceInstance class. Signed-off-by: Mark McLoughlin <markmc@redhat.com>
-rw-r--r--ipa-server/ipa-install/ipa-server-install5
-rw-r--r--ipa-server/ipaserver/Makefile.am1
-rw-r--r--ipa-server/ipaserver/httpinstance.py4
-rw-r--r--ipa-server/ipaserver/krbinstance.py28
-rw-r--r--ipa-server/ipaserver/service.py23
-rw-r--r--ipa-server/ipaserver/webguiinstance.py46
6 files changed, 41 insertions, 66 deletions
diff --git a/ipa-server/ipa-install/ipa-server-install b/ipa-server/ipa-install/ipa-server-install
index 95b7790e7..dcfa20111 100644
--- a/ipa-server/ipa-install/ipa-server-install
+++ b/ipa-server/ipa-install/ipa-server-install
@@ -44,7 +44,6 @@ import ipaserver.krbinstance
import ipaserver.bindinstance
import ipaserver.httpinstance
import ipaserver.ntpinstance
-import ipaserver.webguiinstance
from ipaserver import service
from ipaserver import sysrestore
@@ -275,7 +274,7 @@ def check_dirsrv():
def uninstall():
ipaserver.ntpinstance.NTPInstance().uninstall()
ipaserver.bindinstance.BindInstance().uninstall()
- ipaserver.webguiinstance.WebGuiInstance().uninstall()
+ ipaserver.httpinstance.WebGuiInstance().uninstall()
ipaserver.httpinstance.HTTPInstance().uninstall()
ipaserver.krbinstance.KrbInstance().uninstall()
ipaserver.dsinstance.DsInstance().uninstall()
@@ -432,7 +431,7 @@ def main():
http.create_instance(realm_name, host_name)
# Create a Web Gui instance
- webgui = ipaserver.webguiinstance.WebGuiInstance()
+ webgui = ipaserver.httpinstance.WebGuiInstance()
webgui.create_instance()
bind.setup(host_name, ip_address, realm_name)
diff --git a/ipa-server/ipaserver/Makefile.am b/ipa-server/ipaserver/Makefile.am
index ac8b9818f..4a33b9542 100644
--- a/ipa-server/ipaserver/Makefile.am
+++ b/ipa-server/ipaserver/Makefile.am
@@ -9,7 +9,6 @@ app_PYTHON = \
krbinstance.py \
httpinstance.py \
ntpinstance.py \
- webguiinstance.py \
service.py \
installutils.py \
replication.py \
diff --git a/ipa-server/ipaserver/httpinstance.py b/ipa-server/ipaserver/httpinstance.py
index 8577a25bc..12e5ae105 100644
--- a/ipa-server/ipaserver/httpinstance.py
+++ b/ipa-server/ipaserver/httpinstance.py
@@ -47,6 +47,10 @@ successfully change with the command:
Try updating the policycoreutils and selinux-policy packages.
"""
+class WebGuiInstance(service.SimpleServiceInstance):
+ def __init__(self):
+ service.SimpleServiceInstance.__init__(self, "ipa_webgui")
+
class HTTPInstance(service.Service):
def __init__(self):
service.Service.__init__(self, "httpd")
diff --git a/ipa-server/ipaserver/krbinstance.py b/ipa-server/ipaserver/krbinstance.py
index 17bb4f6ff..52c675e7c 100644
--- a/ipa-server/ipaserver/krbinstance.py
+++ b/ipa-server/ipaserver/krbinstance.py
@@ -71,6 +71,10 @@ def update_key_val_in_file(filename, key, val):
f = open(filename, "a")
f.write("%s=%s\n" % (key, val))
f.close()
+
+class KpasswdInstance(service.SimpleServiceInstance):
+ def __init__(self):
+ service.SimpleServiceInstance.__init__(self, "ipa_kpasswd")
class KrbInstance(service.Service):
def __init__(self):
@@ -86,6 +90,8 @@ class KrbInstance(service.Service):
self.kdc_password = None
self.sub_dict = None
+ self.kpasswd = KpasswdInstance()
+
def __common_setup(self, ds_user, realm_name, host_name, admin_password):
self.ds_user = ds_user
self.fqdn = host_name
@@ -117,7 +123,6 @@ class KrbInstance(service.Service):
def __common_post_setup(self):
self.step("starting the KDC", self.__start_instance)
self.step("configuring KDC to start on boot", self.__enable)
- self.step("enabling and starting ipa_kpasswd", self.__enable_kpasswd)
def create_instance(self, ds_user, realm_name, host_name, admin_password, master_password):
self.master_password = master_password
@@ -139,6 +144,8 @@ class KrbInstance(service.Service):
self.start_creation("Configuring Kerberos KDC")
+ self.kpasswd.create_instance()
+
def create_replica(self, ds_user, realm_name, host_name, admin_password, ldap_passwd_filename):
self.__copy_ldap_passwd(ldap_passwd_filename)
@@ -155,6 +162,8 @@ class KrbInstance(service.Service):
self.start_creation("Configuring Kerberos KDC")
+ self.kpasswd.create_instance()
+
def __copy_ldap_passwd(self, filename):
sysrestore.backup_file("/var/kerberos/krb5kdc/ldappwd")
shutil.copy(filename, "/var/kerberos/krb5kdc/ldappwd")
@@ -181,12 +190,6 @@ class KrbInstance(service.Service):
except:
logging.critical("krb5kdc service failed to start")
- def __enable_kpasswd(self):
- sysrestore.backup_state("ipa_kpasswd", "enabled", service.is_enabled("ipa_kpasswd"))
- sysrestore.backup_state("ipa_kpasswd", "running", service.is_running("ipa_kpasswd"))
- service.chkconfig_on("ipa_kpasswd")
- service.start("ipa_kpasswd")
-
def __setup_sub_dict(self):
self.sub_dict = dict(FQDN=self.fqdn,
IP=self.ip,
@@ -379,21 +382,16 @@ class KrbInstance(service.Service):
os.chown("/var/kerberos/krb5kdc/kpasswd.keytab", pent.pw_uid, pent.pw_gid)
def uninstall(self):
+ self.kpasswd.uninstall()
+
running = self.restore_state("running")
enabled = self.restore_state("enabled")
- kpasswd_running = sysrestore.restore_state("ipa_kpasswd", "running")
- kpasswd_enabled = sysrestore.restore_state("ipa_kpasswd", "enabled")
-
if not running is None:
self.stop()
- if not kpasswd_running is None:
- service.stop("ipa_kpasswd")
if not enabled is None and not enabled:
self.chkconfig_off()
- if not kpasswd_enabled is None and not kpasswd_enabled:
- service.chkconfig_off("ipa_kpasswd")
for f in ["/var/kerberos/krb5kdc/ldappwd",
"/var/kerberos/krb5kdc/kdc.conf",
@@ -410,5 +408,3 @@ class KrbInstance(service.Service):
if not running is None and running:
self.start()
- if not kpasswd_running is None and kpasswd_running:
- service.start("ipa_kpasswd")
diff --git a/ipa-server/ipaserver/service.py b/ipa-server/ipaserver/service.py
index e960c43d7..e9dc1dcde 100644
--- a/ipa-server/ipaserver/service.py
+++ b/ipa-server/ipaserver/service.py
@@ -125,3 +125,26 @@ class Service:
self.print_msg("done configuring %s." % self.service_name)
self.steps = []
+
+class SimpleServiceInstance(Service):
+ def create_instance(self):
+ self.step("starting %s " % self.service_name, self.__start)
+ self.step("configuring %s to start on boot" % self.service_name, self.__enable)
+ self.start_creation("Configuring %s" % self.service_name)
+
+ def __start(self):
+ self.backup_state("running", self.is_running())
+ self.restart()
+
+ def __enable(self):
+ self.backup_state("enabled", self.is_enabled())
+ self.chkconfig_on()
+
+ def uninstall(self):
+ running = self.restore_state("running")
+ enabled = not self.restore_state("enabled")
+
+ if not running is None and not running:
+ self.stop()
+ if not enabled is None and not enabled:
+ self.chkconfig_off()
diff --git a/ipa-server/ipaserver/webguiinstance.py b/ipa-server/ipaserver/webguiinstance.py
deleted file mode 100644
index 58969cb74..000000000
--- a/ipa-server/ipaserver/webguiinstance.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# Authors: Karl MacMillan <kmacmillan@mentalrootkit.com>
-#
-# Copyright (C) 2007 Red Hat
-# see file 'COPYING' for use and warranty information
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2 or later
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-
-import service
-
-class WebGuiInstance(service.Service):
- def __init__(self):
- service.Service.__init__(self, "ipa_webgui")
-
- def create_instance(self):
- self.step("starting ipa_webgui", self.__start)
- self.step("configuring ipa_webgui to start on boot", self.__enable)
- self.start_creation("Configuring ipa_webgui")
-
- def __start(self):
- self.backup_state("running", self.is_running())
- self.restart()
-
- def __enable(self):
- self.backup_state("enabled", self.is_enabled())
- self.chkconfig_on()
-
- def uninstall(self):
- running = self.restore_state("running")
- enabled = not self.restore_state("enabled")
-
- if not running is None and not running:
- self.stop()
- if not enabled is None and not enabled:
- self.chkconfig_off()