diff --git a/ovm/scripts/vm/hypervisor/ovm/OvmCommonModule.py b/ovm/scripts/vm/hypervisor/ovm/OvmCommonModule.py index 26086db20b6..7eb2454239e 100755 --- a/ovm/scripts/vm/hypervisor/ovm/OvmCommonModule.py +++ b/ovm/scripts/vm/hypervisor/ovm/OvmCommonModule.py @@ -113,16 +113,15 @@ def raiseExceptionIfFail(res): def ipToHeartBeatFileName(ip): return ip.replace('.', '_') + "_HEARTBEAT" -def parseVmConfigureFile(cfgPath): - if not isfile(cfgPath): return {} - - res = {} +def getVmNameFromConfigureFile(cfgPath): fd = open(cfgPath) for i in fd.readlines(): - (key, value) = i.split("=", 1) - key = key.strip().strip("'") - value = value.strip().strip("'") - res[key] = value + i = i.strip() + if i.startswith('name'): + (key, value) = i.split("=", 1) + value = value.strip().strip("'") + fd.close() + return value fd.close() - return res + raise Exception('Cannot find vm name in %s'%cfgPath) diff --git a/ovm/scripts/vm/hypervisor/ovm/OvmStoragePoolModule.py b/ovm/scripts/vm/hypervisor/ovm/OvmStoragePoolModule.py index 5b6dd29fcf7..ad97861094a 100755 --- a/ovm/scripts/vm/hypervisor/ovm/OvmStoragePoolModule.py +++ b/ovm/scripts/vm/hypervisor/ovm/OvmStoragePoolModule.py @@ -276,7 +276,22 @@ class OvmStoragePool(OvmObject): fd.close() doCmd(['hostname', nodeName]) + def checkStaleCluster(clusterName): + if exists('/sys/kernel/config/cluster/'): + dirs = os.listdir('/sys/kernel/config/cluster/') + for dir in dirs: + if dir != clusterName: + errMsg = '''CloudStack detected there is a stale cluster(%s) on host %s. Please manually clean up it first then add again by +1) remove the host from cloudstack +2) umount all OCFS2 device on host +3) /etc/init.d/o2cb offline %s +4) /etc/init.d/o2cb restart +if this doesn't resolve the problem, please check oracle manual to see how to offline a cluster + ''' % (dir, get_master_ip, dir) + raise Exception(errMsg) + try: + checkStaleCluster(clusterName) nodeString = nodeString.strip(";") nodes = [] for n in nodeString.split(";"): @@ -327,9 +342,7 @@ class OvmStoragePool(OvmObject): secMountPoint = "" if not isfile(volumePath): raise Exception("Cannot find %s"%volumePath) vmCfg = join(dirname(volumePath), 'vm.cfg') - cfgs = parseVmConfigureFile(vmCfg) - if len(cfgs) == 0: raise Exception("Cannot find vm.cfg, this volume(%s) seems not the ROOT volume. We don't support create template from non-ROOT volume"%volumePath) - vmName = cfgs['name'] + vmName = getVmNameFromConfigureFile(vmCfg) if vmName in doCmd(['xm', 'list']): raise Exception("%s is still running, please stop it first then create template again"%vmName)