mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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:
parent
5fd10b5f98
commit
11266d039f
@ -44,7 +44,6 @@ import ipaserver.krbinstance
|
|||||||
import ipaserver.bindinstance
|
import ipaserver.bindinstance
|
||||||
import ipaserver.httpinstance
|
import ipaserver.httpinstance
|
||||||
import ipaserver.ntpinstance
|
import ipaserver.ntpinstance
|
||||||
import ipaserver.webguiinstance
|
|
||||||
|
|
||||||
from ipaserver import service
|
from ipaserver import service
|
||||||
from ipaserver import sysrestore
|
from ipaserver import sysrestore
|
||||||
@ -275,7 +274,7 @@ def check_dirsrv():
|
|||||||
def uninstall():
|
def uninstall():
|
||||||
ipaserver.ntpinstance.NTPInstance().uninstall()
|
ipaserver.ntpinstance.NTPInstance().uninstall()
|
||||||
ipaserver.bindinstance.BindInstance().uninstall()
|
ipaserver.bindinstance.BindInstance().uninstall()
|
||||||
ipaserver.webguiinstance.WebGuiInstance().uninstall()
|
ipaserver.httpinstance.WebGuiInstance().uninstall()
|
||||||
ipaserver.httpinstance.HTTPInstance().uninstall()
|
ipaserver.httpinstance.HTTPInstance().uninstall()
|
||||||
ipaserver.krbinstance.KrbInstance().uninstall()
|
ipaserver.krbinstance.KrbInstance().uninstall()
|
||||||
ipaserver.dsinstance.DsInstance().uninstall()
|
ipaserver.dsinstance.DsInstance().uninstall()
|
||||||
@ -432,7 +431,7 @@ def main():
|
|||||||
http.create_instance(realm_name, host_name)
|
http.create_instance(realm_name, host_name)
|
||||||
|
|
||||||
# Create a Web Gui instance
|
# Create a Web Gui instance
|
||||||
webgui = ipaserver.webguiinstance.WebGuiInstance()
|
webgui = ipaserver.httpinstance.WebGuiInstance()
|
||||||
webgui.create_instance()
|
webgui.create_instance()
|
||||||
|
|
||||||
bind.setup(host_name, ip_address, realm_name)
|
bind.setup(host_name, ip_address, realm_name)
|
||||||
|
@ -9,7 +9,6 @@ app_PYTHON = \
|
|||||||
krbinstance.py \
|
krbinstance.py \
|
||||||
httpinstance.py \
|
httpinstance.py \
|
||||||
ntpinstance.py \
|
ntpinstance.py \
|
||||||
webguiinstance.py \
|
|
||||||
service.py \
|
service.py \
|
||||||
installutils.py \
|
installutils.py \
|
||||||
replication.py \
|
replication.py \
|
||||||
|
@ -47,6 +47,10 @@ successfully change with the command:
|
|||||||
Try updating the policycoreutils and selinux-policy packages.
|
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):
|
class HTTPInstance(service.Service):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
service.Service.__init__(self, "httpd")
|
service.Service.__init__(self, "httpd")
|
||||||
|
@ -72,6 +72,10 @@ def update_key_val_in_file(filename, key, val):
|
|||||||
f.write("%s=%s\n" % (key, val))
|
f.write("%s=%s\n" % (key, val))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
class KpasswdInstance(service.SimpleServiceInstance):
|
||||||
|
def __init__(self):
|
||||||
|
service.SimpleServiceInstance.__init__(self, "ipa_kpasswd")
|
||||||
|
|
||||||
class KrbInstance(service.Service):
|
class KrbInstance(service.Service):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
service.Service.__init__(self, "krb5kdc")
|
service.Service.__init__(self, "krb5kdc")
|
||||||
@ -86,6 +90,8 @@ class KrbInstance(service.Service):
|
|||||||
self.kdc_password = None
|
self.kdc_password = None
|
||||||
self.sub_dict = None
|
self.sub_dict = None
|
||||||
|
|
||||||
|
self.kpasswd = KpasswdInstance()
|
||||||
|
|
||||||
def __common_setup(self, ds_user, realm_name, host_name, admin_password):
|
def __common_setup(self, ds_user, realm_name, host_name, admin_password):
|
||||||
self.ds_user = ds_user
|
self.ds_user = ds_user
|
||||||
self.fqdn = host_name
|
self.fqdn = host_name
|
||||||
@ -117,7 +123,6 @@ class KrbInstance(service.Service):
|
|||||||
def __common_post_setup(self):
|
def __common_post_setup(self):
|
||||||
self.step("starting the KDC", self.__start_instance)
|
self.step("starting the KDC", self.__start_instance)
|
||||||
self.step("configuring KDC to start on boot", self.__enable)
|
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):
|
def create_instance(self, ds_user, realm_name, host_name, admin_password, master_password):
|
||||||
self.master_password = master_password
|
self.master_password = master_password
|
||||||
@ -139,6 +144,8 @@ class KrbInstance(service.Service):
|
|||||||
|
|
||||||
self.start_creation("Configuring Kerberos KDC")
|
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):
|
def create_replica(self, ds_user, realm_name, host_name, admin_password, ldap_passwd_filename):
|
||||||
self.__copy_ldap_passwd(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.start_creation("Configuring Kerberos KDC")
|
||||||
|
|
||||||
|
self.kpasswd.create_instance()
|
||||||
|
|
||||||
def __copy_ldap_passwd(self, filename):
|
def __copy_ldap_passwd(self, filename):
|
||||||
sysrestore.backup_file("/var/kerberos/krb5kdc/ldappwd")
|
sysrestore.backup_file("/var/kerberos/krb5kdc/ldappwd")
|
||||||
shutil.copy(filename, "/var/kerberos/krb5kdc/ldappwd")
|
shutil.copy(filename, "/var/kerberos/krb5kdc/ldappwd")
|
||||||
@ -181,12 +190,6 @@ class KrbInstance(service.Service):
|
|||||||
except:
|
except:
|
||||||
logging.critical("krb5kdc service failed to start")
|
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):
|
def __setup_sub_dict(self):
|
||||||
self.sub_dict = dict(FQDN=self.fqdn,
|
self.sub_dict = dict(FQDN=self.fqdn,
|
||||||
IP=self.ip,
|
IP=self.ip,
|
||||||
@ -379,21 +382,16 @@ class KrbInstance(service.Service):
|
|||||||
os.chown("/var/kerberos/krb5kdc/kpasswd.keytab", pent.pw_uid, pent.pw_gid)
|
os.chown("/var/kerberos/krb5kdc/kpasswd.keytab", pent.pw_uid, pent.pw_gid)
|
||||||
|
|
||||||
def uninstall(self):
|
def uninstall(self):
|
||||||
|
self.kpasswd.uninstall()
|
||||||
|
|
||||||
running = self.restore_state("running")
|
running = self.restore_state("running")
|
||||||
enabled = self.restore_state("enabled")
|
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:
|
if not running is None:
|
||||||
self.stop()
|
self.stop()
|
||||||
if not kpasswd_running is None:
|
|
||||||
service.stop("ipa_kpasswd")
|
|
||||||
|
|
||||||
if not enabled is None and not enabled:
|
if not enabled is None and not enabled:
|
||||||
self.chkconfig_off()
|
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",
|
for f in ["/var/kerberos/krb5kdc/ldappwd",
|
||||||
"/var/kerberos/krb5kdc/kdc.conf",
|
"/var/kerberos/krb5kdc/kdc.conf",
|
||||||
@ -410,5 +408,3 @@ class KrbInstance(service.Service):
|
|||||||
|
|
||||||
if not running is None and running:
|
if not running is None and running:
|
||||||
self.start()
|
self.start()
|
||||||
if not kpasswd_running is None and kpasswd_running:
|
|
||||||
service.start("ipa_kpasswd")
|
|
||||||
|
@ -125,3 +125,26 @@ class Service:
|
|||||||
self.print_msg("done configuring %s." % self.service_name)
|
self.print_msg("done configuring %s." % self.service_name)
|
||||||
|
|
||||||
self.steps = []
|
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()
|
||||||
|
@ -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()
|
|
Loading…
Reference in New Issue
Block a user