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 diff -r 8a7b6094fd43 ipa-server/ipa-install/ipa-server-install --- a/ipa-server/ipa-install/ipa-server-install Tue Jan 22 08:05:15 2008 +0000 +++ b/ipa-server/ipa-install/ipa-server-install Tue Jan 22 11:51:34 2008 +0000 @@ -44,7 +44,6 @@ import ipaserver.bindinstance 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 uninstall(): 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 -r 8a7b6094fd43 ipa-server/ipaserver/Makefile.am --- a/ipa-server/ipaserver/Makefile.am Tue Jan 22 08:05:15 2008 +0000 +++ b/ipa-server/ipaserver/Makefile.am Tue Jan 22 11:51:34 2008 +0000 @@ -9,7 +9,6 @@ app_PYTHON = \ krbinstance.py \ httpinstance.py \ ntpinstance.py \ - webguiinstance.py \ service.py \ installutils.py \ replication.py \ diff -r 8a7b6094fd43 ipa-server/ipaserver/httpinstance.py --- a/ipa-server/ipaserver/httpinstance.py Tue Jan 22 08:05:15 2008 +0000 +++ b/ipa-server/ipaserver/httpinstance.py Tue Jan 22 11:51:34 2008 +0000 @@ -46,6 +46,10 @@ successfully change with the command: /usr/sbin/setsebool -P httpd_can_network_connect true 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): diff -r 8a7b6094fd43 ipa-server/ipaserver/krbinstance.py --- a/ipa-server/ipaserver/krbinstance.py Tue Jan 22 08:05:15 2008 +0000 +++ b/ipa-server/ipaserver/krbinstance.py Tue Jan 22 11:51:34 2008 +0000 @@ -71,6 +71,10 @@ def update_key_val_in_file(filename, key 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) @@ -154,6 +161,8 @@ class KrbInstance(service.Service): self.__common_post_setup() self.start_creation("Configuring Kerberos KDC") + + self.kpasswd.create_instance() def __copy_ldap_passwd(self, filename): sysrestore.backup_file("/var/kerberos/krb5kdc/ldappwd") @@ -180,12 +189,6 @@ class KrbInstance(service.Service): self.start() 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, @@ -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 -r 8a7b6094fd43 ipa-server/ipaserver/service.py --- a/ipa-server/ipaserver/service.py Tue Jan 22 08:05:15 2008 +0000 +++ b/ipa-server/ipaserver/service.py Tue Jan 22 11:51:34 2008 +0000 @@ -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 -r 8a7b6094fd43 ipa-server/ipaserver/webguiinstance.py --- a/ipa-server/ipaserver/webguiinstance.py Tue Jan 22 08:05:15 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -# Authors: Karl MacMillan -# -# 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()