From 8f6a43d7cfe0d6e5b8b4bf14f296f85d3fa654c5 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Wed, 15 Jun 2011 19:20:05 -0400 Subject: [PATCH] bug 9985: add more checking during setup cloudzone: host os must be ubuntu 10.04, 64bit, free disk space must be larger than 30G, memory must be larger than 1G status 9985: resolved fixed --- python/lib/cloudutils/globalEnv.py | 2 ++ python/lib/cloudutils/syscfg.py | 37 +++++++++++++++++++++++++++--- python/lib/cloudutils/utilities.py | 13 ++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/python/lib/cloudutils/globalEnv.py b/python/lib/cloudutils/globalEnv.py index e51803b5271..ad5efaff81b 100644 --- a/python/lib/cloudutils/globalEnv.py +++ b/python/lib/cloudutils/globalEnv.py @@ -22,3 +22,5 @@ class globalEnv: self.uuid = None #default private network self.privateNet = "cloudbr0" + #distribution + self.distribution = None diff --git a/python/lib/cloudutils/syscfg.py b/python/lib/cloudutils/syscfg.py index 375f86e2170..36d9398fe20 100644 --- a/python/lib/cloudutils/syscfg.py +++ b/python/lib/cloudutils/syscfg.py @@ -1,4 +1,4 @@ -from utilities import DistributionDetector, serviceOpsRedhat,serviceOpsUbuntu +from utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu from serviceConfig import * class sysConfigFactory: @staticmethod @@ -15,7 +15,8 @@ class sysConfigFactory: class sysConfigAgentFactory: @staticmethod def getAgent(glbEnv): - distribution = DistributionDetector().getVersion() + glbEnv.distribution = Distribution() + distribution = glbEnv.distribution.getVersion() if distribution == "Ubuntu": return sysConfigAgentUbuntu(glbEnv) elif distribution == "Fedora" or distribution == "RHEL6": @@ -29,7 +30,8 @@ class sysConfigAgentFactory: class sysConfigServerFactory: @staticmethod def getServer(glbEnv): - distribution = DistributionDetector().getVersion() + glbEnv.distribution = Distribution() + distribution = glbEnv.distribution.getVersion() if distribution == "Ubuntu": return sysConfigServerUbuntu(glbEnv) elif distribution != "Unknown": @@ -70,6 +72,35 @@ class sysConfigAgent(sysConfig): def check(self): if self.env.debug: return True + + if 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.getRelease() != "10.04": + raise CloudInternalException("Need to run myCloud agent on an Ubuntu 10.04\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 disk + if os.path.exists("/var/lib/libvirt/images"): + size = -1 + try: + size = int(bash("df -P /var/lib/libvirt/images | tail -1 |awk '{print $4}'").getStdout()) + except: + pass + + if size != -1 and size < (30 * 1024 * 1024): + raise CloudRuntimeException("Need at least 30G free disk space under /var/lib/libvirt/images") + + #check memory + mem = -1 + try: + mem = int(bash("free -g|grep Mem|awk '{print $2}'").getStdout()) + except: + pass + + if 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") diff --git a/python/lib/cloudutils/utilities.py b/python/lib/cloudutils/utilities.py index 4510128c6fa..30df9781001 100644 --- a/python/lib/cloudutils/utilities.py +++ b/python/lib/cloudutils/utilities.py @@ -80,9 +80,10 @@ def writeProgressBar(msg, result): sys.stdout.write(output) sys.stdout.flush() -class DistributionDetector: +class Distribution: def __init__(self): self.distro = "Unknown" + self.release = "Unknown" if os.path.exists("/etc/fedora-release"): self.distro = "Fedora" @@ -98,11 +99,21 @@ class DistributionDetector: self.distro = "RHEL5" elif os.path.exists("/etc/legal") and "Ubuntu" in file("/etc/legal").read(-1): self.distro = "Ubuntu" + kernel = bash("uname -r").getStdout() + if kernel.find("2.6.32") != -1: + self.release = "10.04" + self.arch = bash("uname -m").getStdout() + else: self.distro = "Unknown" def getVersion(self): return self.distro + def getRelease(self): + return self.release + def getArch(self): + return self.arch + class serviceOps: pass