# Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# 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,serviceOpsRedhat7from serviceConfig import *class sysConfigFactory:@staticmethoddef getSysConfigFactory(glbEnv):if glbEnv.mode == "Agent":return sysConfigAgentFactory.getAgent(glbEnv)elif glbEnv.mode == "Server":return sysConfigServerFactory.getServer(glbEnv)elif glbEnv.mode == "HttpsServer":return sysConfigServerFactory.getServer(glbEnv)elif glbEnv.mode == "Db":return sysConfigDbFactory.getDb(glbEnv)else:raise CloudInternalException("Need to specify which mode are u running: Agent/Server/Db")class sysConfigAgentFactory:@staticmethoddef getAgent(glbEnv):glbEnv.distribution = Distribution()distribution = glbEnv.distribution.getVersion()if distribution == "Ubuntu":return sysConfigAgentUbuntu(glbEnv)elif distribution == "Fedora" or distribution == "RHEL6":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()class sysConfigServerFactory:@staticmethoddef getServer(glbEnv):glbEnv.distribution = Distribution()distribution = glbEnv.distribution.getVersion()if distribution == "Ubuntu":return sysConfigServerUbuntu(glbEnv)elif distribution != "Unknown":return sysConfigServerRedhat(glbEnv)else:print "Can't find the distribution version"return sysConfig()class sysConfigDbFactory:@staticmethoddef getDb(glbEnv):passclass sysConfig(object):def __init__(self, env):self.env = envself.services = []def registerService(self, service):self.services.append(service(self))def config(self):if not self.check():return Falsefor service in self.services:if not service.configration():raise CloudInternalException("Configuration failed for service %s" % service.serviceName)def restore(self):for service in self.services:service.backup()def check(self):return Trueclass sysConfigAgent(sysConfig):def __init__(self, env):super(sysConfigAgent, self).__init__(env)def check(self):if self.env.debug:return Trueif self.env.agentMode == "myCloud":if self.env.distribution.getVersion() != "Ubuntu":raise CloudInternalException("Need to run myCloud agent on an Ubuntu machine\n")elif self.env.distribution.getArch() != "x86_64":raise CloudInternalException("Need to run myCloud agent on an 64bit machine\n")#check free disk space on the local diskif os.path.exists("/var/lib/libvirt/images"):size = -1try:size = int(bash("df -P /var/lib/libvirt/images | tail -1 |awk '{print 4ドル}'").getStdout())except:passif size != -1 and size < (30 * 1024 * 1024):raise CloudRuntimeException("Need at least 30G free disk space under /var/lib/libvirt/images")#check memorymem = -1try:mem = int(bash("free -g|grep Mem|awk '{print 2ドル}'").getStdout())except:passif mem != -1 and mem < 1:raise CloudRuntimeException("Need at least 1G memory")if os.geteuid() != 0:raise CloudInternalException("Need to execute with root permission\n")hostname = bash("hostname -f")if not hostname.isSuccess():raise CloudInternalException("Checking hostname ... [Failed]\nPlease edit /etc/hosts, add a Fully Qualified Domain Name as your hostname\n")kvmEnabled = self.svo.isKVMEnabled()if not kvmEnabled:raise CloudInternalException("Checking KVM...[Failed]\nPlease enable KVM on this machine\n")return Trueclass 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)self.svo = serviceOpsUbuntu()self.services = [securityPolicyConfigUbuntu(self),networkConfigUbuntu(self),libvirtConfigUbuntu(self),firewallConfigUbuntu(self),nfsConfig(self),cloudAgentConfig(self)]#it covers RHEL6/Fedora13/Fedora14class sysConfigRedhat6(sysConfigAgentRedhatBase):def __init__(self, glbEnv):super(sysConfigRedhat6, self).__init__(glbEnv)self.services = [cgroupConfig(self),securityPolicyConfigRedhat(self),networkConfigRedhat(self),libvirtConfigRedhat(self),firewallConfigAgent(self),nfsConfig(self),cloudAgentConfig(self)]#It covers RHEL5/CentOS5, the mainly difference is that there is no cgroupclass sysConfigRedhat5(sysConfigAgentRedhatBase):def __init__(self, glbEnv):super(sysConfigRedhat5, self).__init__(glbEnv)self.services = [securityPolicyConfigRedhat(self),networkConfigRedhat(self),libvirtConfigRedhat(self),firewallConfigAgent(self),cloudAgentConfig(self)]#it covers RHEL7class 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:raise CloudInternalException("Need to execute with root permission")hostname = bash("hostname -f")if not hostname.isSuccess():raise CloudInternalException("Checking hostname ... [Failed]\nPlease edit /etc/hosts, add a Fully Qualified Domain Name as your hostname\n")return Trueclass sysConfigServerRedhat(sysConfigServer):def __init__(self, glbEnv):super(sysConfigServerRedhat, self).__init__(glbEnv)self.svo = serviceOpsRedhat()self.services = [firewallConfigServer(self)]class sysConfigServerUbuntu(sysConfigServer):def __init__(self, glbEnv):super(sysConfigServerUbuntu, self).__init__(glbEnv)self.svo = serviceOpsUbuntu()self.services = [ubuntuFirewallConfigServer(self)]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。