From 983a3b80e2eb03dd967d38f2e46f4e07ac5dc1c6 Mon Sep 17 00:00:00 2001 From: Kishan Kavala Date: Wed, 17 Sep 2014 17:47:33 +0530 Subject: [PATCH] CLOUDSTACK-7568, CLOUDSTACK-7569: Use systemctl for managing services in RHEL7. chkconfig --del doesn't work in RHEL7. --- python/lib/cloudutils/syscfg.py | 22 +++++++++++++++-- python/lib/cloudutils/utilities.py | 38 +++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/python/lib/cloudutils/syscfg.py b/python/lib/cloudutils/syscfg.py index aa5119e0f4d..290f56ccdd6 100755 --- a/python/lib/cloudutils/syscfg.py +++ b/python/lib/cloudutils/syscfg.py @@ -14,7 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -from utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu +from utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu,serviceOpsRedhat7 from serviceConfig import * class sysConfigFactory: @staticmethod @@ -41,6 +41,8 @@ class sysConfigAgentFactory: return sysConfigRedhat6(glbEnv) elif distribution == "CentOS" or distribution == "RHEL5": return sysConfigRedhat5(glbEnv) + elif distribution == "RHEL7": + return sysConfigRedhat7(glbEnv) else: print "Can't find the distribution version" return sysConfig() @@ -139,7 +141,12 @@ class sysConfigAgentRedhatBase(sysConfigAgent): def __init__(self, env): self.svo = serviceOpsRedhat() super(sysConfigAgentRedhatBase, self).__init__(env) - + +class sysConfigAgentRedhat7Base(sysConfigAgent): + def __init__(self, env): + self.svo = serviceOpsRedhat7() + super(sysConfigAgentRedhat7Base, self).__init__(env) + class sysConfigAgentUbuntu(sysConfigAgent): def __init__(self, glbEnv): super(sysConfigAgentUbuntu, self).__init__(glbEnv) @@ -175,6 +182,17 @@ class sysConfigRedhat5(sysConfigAgentRedhatBase): firewallConfigAgent(self), cloudAgentConfig(self)] +#it covers RHEL7 +class sysConfigRedhat7(sysConfigAgentRedhat7Base): + def __init__(self, glbEnv): + super(sysConfigRedhat7, self).__init__(glbEnv) + self.services = [securityPolicyConfigRedhat(self), + networkConfigRedhat(self), + libvirtConfigRedhat(self), + firewallConfigAgent(self), + nfsConfig(self), + cloudAgentConfig(self)] + class sysConfigServer(sysConfig): def check(self): if os.geteuid() != 0: diff --git a/python/lib/cloudutils/utilities.py b/python/lib/cloudutils/utilities.py index ea0384b1439..88e2d1c6f9b 100755 --- a/python/lib/cloudutils/utilities.py +++ b/python/lib/cloudutils/utilities.py @@ -113,7 +113,7 @@ class Distribution: if version.find("Red Hat Enterprise Linux Server release 6") != -1 or version.find("Scientific Linux release 6") != -1 or version.find("CentOS Linux release 6") != -1 or version.find("CentOS release 6.") != -1: self.distro = "RHEL6" elif version.find("Red Hat Enterprise Linux Server release 7") != -1: - self.distro = "RHEL6" + self.distro = "RHEL7" elif version.find("CentOS release") != -1: self.distro = "CentOS" else: @@ -212,3 +212,39 @@ class serviceOpsUbuntu(serviceOps): def isKVMEnabled(self): return bash("kvm-ok").isSuccess() + +class serviceOpsRedhat7(serviceOps): + def isServiceRunning(self, servicename): + try: + o = bash("systemctl status " + servicename) + if "running" in o.getStdout() or "start" in o.getStdout() or "Running" in o.getStdout(): + return True + else: + return False + except: + return False + + def stopService(self, servicename,force=False): + if self.isServiceRunning(servicename) or force: + return bash("systemctl stop " + servicename).isSuccess() + + return True + def disableService(self, servicename): + result = self.stopService(servicename) + bash("systemctl disable " + servicename) + return result + + def startService(self, servicename,force=False): + if not self.isServiceRunning(servicename) or force: + return bash("systemctl start " + servicename).isSuccess() + return True + + def enableService(self, servicename,forcestart=False): + bash("systemctl enable " + servicename) + return self.startService(servicename,force=forcestart) + + def isKVMEnabled(self): + if os.path.exists("/dev/kvm"): + return True + else: + return False