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>
This commit is contained in:
Mark McLoughlin 2008-01-22 11:58:06 +00:00
parent 5fd10b5f98
commit 11266d039f
6 changed files with 41 additions and 66 deletions

View File

@ -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)

View File

@ -9,7 +9,6 @@ app_PYTHON = \
krbinstance.py \
httpinstance.py \
ntpinstance.py \
webguiinstance.py \
service.py \
installutils.py \
replication.py \

View File

@ -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")

View File

@ -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")

View File

@ -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()

View File

@ -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()