def getDetails():
     try:
         obj = OvmHost()
         masterIp = successToMap(get_master_ip())
         safeSetAttr(obj, 'masterIp', masterIp['ip'])
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo['total_memory']))
         safeSetAttr(obj, 'totalMemory', totalMemory)
         freeMemory = MtoBytes(long(xmInfo['free_memory']))
         safeSetAttr(obj, 'freeMemory', freeMemory)
         dom0Memory = totalMemory - freeMemory
         safeSetAttr(obj, 'dom0Memory', dom0Memory)
         cpuNum = int(xmInfo['nr_cpus'])
         safeSetAttr(obj, 'cpuNum', cpuNum)
         cpuSpeed = int(xmInfo['cpu_mhz'])
         safeSetAttr(obj, 'cpuSpeed', cpuSpeed)
         name = xmInfo['host']
         safeSetAttr(obj, 'name', name)
         dom0KernelVersion = xmInfo['release']
         safeSetAttr(obj, 'dom0KernelVersion', dom0KernelVersion)
         hypervisorVersion = xmInfo['xen_major'] + '.' + xmInfo['xen_minor'] + xmInfo['xen_extra']
         safeSetAttr(obj, 'hypervisorVersion', hypervisorVersion)
         agtVersion = successToMap(get_agent_version())
         safeSetAttr(obj, 'agentVersion', agtVersion['agent_version'])
         res = fromOvmHost(obj)
         logger.debug(OvmHost.getDetails, res)
         return res
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getDetails, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getDetails), errmsg)
 def getDetails():
     try:
         obj = OvmHost()
         masterIp = successToMap(get_master_ip())
         safeSetAttr(obj, 'masterIp', masterIp['ip'])
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo['total_memory']))
         safeSetAttr(obj, 'totalMemory', totalMemory)
         freeMemory = MtoBytes(long(xmInfo['free_memory']))
         safeSetAttr(obj, 'freeMemory', freeMemory)
         dom0Memory = totalMemory - freeMemory
         safeSetAttr(obj, 'dom0Memory', dom0Memory)
         cpuNum = int(xmInfo['nr_cpus'])
         safeSetAttr(obj, 'cpuNum', cpuNum)
         cpuSpeed = int(xmInfo['cpu_mhz'])
         safeSetAttr(obj, 'cpuSpeed', cpuSpeed)
         name = xmInfo['host']
         safeSetAttr(obj, 'name', name)
         dom0KernelVersion = xmInfo['release']
         safeSetAttr(obj, 'dom0KernelVersion', dom0KernelVersion)
         hypervisorVersion = xmInfo['xen_major'] + '.' + xmInfo['xen_minor'] + xmInfo['xen_extra']
         safeSetAttr(obj, 'hypervisorVersion', hypervisorVersion)
         agtVersion = successToMap(get_agent_version())
         safeSetAttr(obj, 'agentVersion', agtVersion['agent_version'])
         res = fromOvmHost(obj)
         logger.debug(OvmHost.getDetails, res)
         return res
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getDetails, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getDetails), errmsg)
Exemple #3
0
 def getDetails():
     try:
         obj = OvmHost()
         masterIp = successToMap(get_master_ip())
         safeSetAttr(obj, "masterIp", masterIp["ip"])
         xmInfo = successToMap(xen_get_xm_info())
         totalMemory = MtoBytes(long(xmInfo["total_memory"]))
         safeSetAttr(obj, "totalMemory", totalMemory)
         freeMemory = MtoBytes(long(xmInfo["free_memory"]))
         safeSetAttr(obj, "freeMemory", freeMemory)
         dom0Memory = totalMemory - freeMemory
         safeSetAttr(obj, "dom0Memory", dom0Memory)
         cpuNum = int(xmInfo["nr_cpus"])
         safeSetAttr(obj, "cpuNum", cpuNum)
         cpuSpeed = int(xmInfo["cpu_mhz"])
         safeSetAttr(obj, "cpuSpeed", cpuSpeed)
         name = xmInfo["host"]
         safeSetAttr(obj, "name", name)
         dom0KernelVersion = xmInfo["release"]
         safeSetAttr(obj, "dom0KernelVersion", dom0KernelVersion)
         hypervisorVersion = xmInfo["xen_major"] + "." + xmInfo["xen_minor"] + xmInfo["xen_extra"]
         safeSetAttr(obj, "hypervisorVersion", hypervisorVersion)
         agtVersion = successToMap(get_agent_version())
         safeSetAttr(obj, "agentVersion", agtVersion["agent_version"])
         res = fromOvmHost(obj)
         logger.debug(OvmHost.getDetails, res)
         return res
     except Exception, e:
         errmsg = fmt_err_msg(e)
         logger.error(OvmHost.getDetails, errmsg)
         raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getDetails), errmsg)
        def configureHostName(nodes):
            myIp = successToMap(get_master_ip())['ip']
            nodeName = None
            for n in nodes:
                if myIp == n["ip_address"]:
                    nodeName = n["name"]
                    break

            if nodeName == None:
                raise Exception("Cannot find node equals to my ip address:%s" %
                                myIp)
            if not exists(HOSTNAME_FILE):
                originalConf = ""
            else:
                fd = open(HOSTNAME_FILE, "r")
                originalConf = fd.read()
                fd.close()

            pattern = r"HOSTNAME=(.*)"
            # remove any old hostname
            originalConf = re.sub(pattern, "", originalConf)
            # remove extra empty lines
            originalConf = re.sub(
                r"\n\s*\n*", "\n",
                originalConf) + "\n" + "HOSTNAME=%s" % nodeName
            logger.debug(OvmStoragePool.prepareOCFS2Nodes,
                         "Configure %s:%s\n" % (HOSTNAME_FILE, originalConf))
            fd = open(HOSTNAME_FILE, "w")
            fd.write(originalConf)
            fd.close()
            doCmd(['hostname', nodeName])
Exemple #5
0
 def configureHostName(nodes):
     myIp = successToMap(get_master_ip())['ip']
     nodeName = None
     for n in nodes:
         if myIp == n["ip_address"]:
             nodeName = n["name"]
             break
     
     if nodeName == None: raise Exception("Cannot find node equals to my ip address:%s"%myIp)
     if not exists(HOSTNAME_FILE):
         originalConf = ""
     else:
         fd = open(HOSTNAME_FILE, "r")
         originalConf = fd.read()
         fd.close()
     
     pattern = r"HOSTNAME=(.*)"
     # remove any old hostname
     originalConf = re.sub(pattern, "", originalConf)
     # remove extra empty lines
     originalConf = re.sub(r"\n\s*\n*", "\n", originalConf) + "\n" + "HOSTNAME=%s"%nodeName
     logger.debug(OvmStoragePool.prepareOCFS2Nodes, "Configure %s:%s\n"%(HOSTNAME_FILE,originalConf))
     fd = open(HOSTNAME_FILE, "w")
     fd.write(originalConf)
     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, successToMap(get_master_ip())['ip'], dir)
                        raise Exception(errMsg)
        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, successToMap(get_master_ip())['ip'], dir)
                        raise Exception(errMsg)
Exemple #8
0
 def cdBoot(vm, vmPath):
     isoMountPath = None
     try:
         cdrom = None
         for disk in vm.disks:
             if disk.isIso == True:
                 cdrom = disk
                 break
         if not cdrom: raise Exception("Cannot find Iso in disks")
         
         isoOnSecStorage = dirname(cdrom.path)
         isoName = basename(cdrom.path)
         isoMountPath = OvmVm()._getIsoMountPath(vmPath)
         OvmStoragePool()._mount(isoOnSecStorage, isoMountPath)
         isoPath = join(isoMountPath, isoName)
         if not exists(isoPath):
             raise Exception("Cannot found iso %s at %s which mounts to %s"%(isoName, isoOnSecStorage, isoMountPath))
         
         stdout = run_cmd(args=['file', isoPath])
         if not stdout.strip().endswith("(bootable)"): raise Exception("ISO %s is not bootable"%cdrom.path)
         
         #now alter cdrom to correct path
         cdrom.path = isoPath
         if len(vm.vifs) != 0:
             vif = vm.vifs[0]
             #ISO boot must be HVM
             vifCfg = ','.join([vif.mac, vif.bridge, 'ioemu'])
         else:
             vifCfg = ''
         
         rootDiskSize = os.path.getsize(vm.rootDisk.path)
         rooDiskCfg = ':'.join([join(vmPath, basename(vm.rootDisk.path)), str(BytesToG(rootDiskSize)), 'True'])
         disks = [rooDiskCfg]
         for d in vm.disks:
             if d.isIso: continue
             size = os.path.getsize(d.path)
             cfg = ':'.join([d.path, str(BytesToG(size)), 'True'])
             disks.append(cfg)
         disksCfg = ','.join(disks)
         server = successToMap(get_master_ip())['ip']
            
         raiseExceptionIfFail(install_vm_hvm(vmPath, BytesToM(vm.memory), vm.cpuNum, vifCfg, disksCfg, cdrom.path, vncpassword='', dedicated_server=server))
         rs = SUCC()
         return rs
     except Exception, e:
         if isoMountPath and OvmStoragePool()._isMounted(isoMountPath):
             doCmd(['umount', '-f', isoMountPath])
         errmsg = fmt_err_msg(e)
         raise Exception(errmsg)
        def cdBoot(vm, vmPath):
            isoMountPath = None
            try:
                cdrom = None
                for disk in vm.disks:
                    if disk.isIso == True:
                        cdrom = disk
                        break
                if not cdrom: raise Exception("Cannot find Iso in disks")

                isoOnSecStorage = dirname(cdrom.path)
                isoName = basename(cdrom.path)
                isoMountPath = OvmVm()._getIsoMountPath(vmPath)
                OvmStoragePool()._mount(isoOnSecStorage, isoMountPath)
                isoPath = join(isoMountPath, isoName)
                if not exists(isoPath):
                    raise Exception("Cannot found iso %s at %s which mounts to %s"%(isoName, isoOnSecStorage, isoMountPath))

                stdout = run_cmd(args=['file', isoPath])
                if not stdout.strip().endswith("(bootable)"): raise Exception("ISO %s is not bootable"%cdrom.path)

                #now alter cdrom to correct path
                cdrom.path = isoPath
                if len(vm.vifs) != 0:
                    vif = vm.vifs[0]
                    #ISO boot must be HVM
                    vifCfg = ','.join([vif.mac, vif.bridge, 'ioemu'])
                else:
                    vifCfg = ''

                rootDiskSize = os.path.getsize(vm.rootDisk.path)
                rooDiskCfg = ':'.join([join(vmPath, basename(vm.rootDisk.path)), str(BytesToG(rootDiskSize)), 'True'])
                disks = [rooDiskCfg]
                for d in vm.disks:
                    if d.isIso: continue
                    size = os.path.getsize(d.path)
                    cfg = ':'.join([d.path, str(BytesToG(size)), 'True'])
                    disks.append(cfg)
                disksCfg = ','.join(disks)
                server = successToMap(get_master_ip())['ip']

                raiseExceptionIfFail(install_vm_hvm(vmPath, BytesToM(vm.memory), vm.cpuNum, vifCfg, disksCfg, cdrom.path, vncpassword='', dedicated_server=server))
                rs = SUCC()
                return rs
            except Exception, e:
                if isoMountPath and OvmStoragePool()._isMounted(isoMountPath):
                    doCmd(['umount', '-f', isoMountPath])
                errmsg = fmt_err_msg(e)
                raise Exception(errmsg)
Exemple #10
0
        def hddBoot(vm, vmPath):
            vmType = vm.type
            if vmType == "FROMCONFIGFILE":
                vmType = OvmVm()._getVmTypeFromConfigFile(vmPath)
                
            cfgDict = {}
            if vmType == "HVM":
                cfgDict['builder'] = "'hvm'"
                cfgDict['acpi'] = "1"
                cfgDict['apic'] = "1"
                cfgDict['device_model'] = "'/usr/lib/xen/bin/qemu-dm'"
                cfgDict['kernel'] = "'/usr/lib/xen/boot/hvmloader'"
                vifType = 'ioemu'
            else:
                cfgDict['bootloader'] = "'/usr/bin/pygrub'"
                vifType = 'netfront'
            
            cfgDict['name'] = "'%s'"%vm.name
            cfgDict['disk'] = "[]"
            cfgDict['vcpus'] = "''"
            cfgDict['memory'] = "''"
            cfgDict['on_crash'] = "'destroy'"
            cfgDict['on_reboot'] = "'restart'"
            cfgDict['vif'] = "[]"
            
            items = []
            for k in cfgDict.keys():
                item = " = ".join([k, cfgDict[k]])
                items.append(item)
            vmSpec = "\n".join(items)
                
            vmCfg = open(join(vmPath, 'vm.cfg'), 'w')
            vmCfg.write(vmSpec)
            vmCfg.close()
            
            setVifsType(vm.vifs, vifType)
            raiseExceptionIfFail(xen_set_vcpus(vmPath, vm.cpuNum))
            raiseExceptionIfFail(xen_set_memory(vmPath, BytesToM(vm.memory)))
            raiseExceptionIfFail(xen_add_disk(vmPath, vm.rootDisk.path, mode=vm.rootDisk.type))
            vifs = [OvmVif.toXenString(v) for v in vm.vifs]
            for vif in vifs:
                raiseExceptionIfFail(xen_set_vifs(vmPath, vif))
                
            for disk in vm.disks:
                raiseExceptionIfFail(xen_add_disk(vmPath, disk.path, mode=disk.type))

            raiseExceptionIfFail(xen_set_vm_vnc_password(vmPath, ""))
            cfgFile = join(vmPath, 'vm.cfg')
            # only HVM supports attaching cdrom
            if vmType == 'HVM':
                # Add an empty "hdc:cdrom" entry in config. Fisrt we set boot order to 'd' that is cdrom boot,
                # then 'hdc:cdrom' entry will be in disk list. Second, change boot order to 'c' which
                # is harddisk boot. VM can not start with an empty 'hdc:cdrom' when boot order is 'd'.
                # it's tricky !
                raiseExceptionIfFail(xen_config_boot_sequence(vmPath, 'd'))
                raiseExceptionIfFail(xen_config_boot_sequence(vmPath, 'c'))
                
            raiseExceptionIfFail(xen_correct_cfg(cfgFile, vmPath))
            xen_correct_qos_cfg(cfgFile)
            dumpCfg(vm.name, cfgFile)
            server = successToMap(get_master_ip())['ip']
            raiseExceptionIfFail(start_vm(vmPath, server))
            rs = SUCC()
            return rs
Exemple #11
0
def makeOwnerFileName():
    hostIp = successToMap(get_master_ip())['ip']
    ownerFileName = OWNER_FILE_PREFIX + hostIp.replace('.', '_')
    return ownerFileName
Exemple #12
0
def makeOwnerFileName():
    hostIp = successToMap(get_master_ip())['ip']
    ownerFileName = OWNER_FILE_PREFIX + hostIp.replace('.', '_')
    return ownerFileName
        def hddBoot(vm, vmPath):
            vmType = vm.type
            if vmType == "FROMCONFIGFILE":
                vmType = OvmVm()._getVmTypeFromConfigFile(vmPath)

            cfgDict = {}
            if vmType == "HVM":
                cfgDict['builder'] = "'hvm'"
                cfgDict['acpi'] = "1"
                cfgDict['apic'] = "1"
                cfgDict['device_model'] = "'/usr/lib/xen/bin/qemu-dm'"
                cfgDict['kernel'] = "'/usr/lib/xen/boot/hvmloader'"
                vifType = 'ioemu'
            else:
                cfgDict['bootloader'] = "'/usr/bin/pygrub'"
                vifType = 'netfront'

            cfgDict['name'] = "'%s'" % vm.name
            cfgDict['disk'] = "[]"
            cfgDict['vcpus'] = "''"
            cfgDict['memory'] = "''"
            cfgDict['on_crash'] = "'destroy'"
            cfgDict['on_reboot'] = "'restart'"
            cfgDict['vif'] = "[]"

            items = []
            for k in cfgDict.keys():
                item = " = ".join([k, cfgDict[k]])
                items.append(item)
            vmSpec = "\n".join(items)

            vmCfg = open(join(vmPath, 'vm.cfg'), 'w')
            vmCfg.write(vmSpec)
            vmCfg.close()

            setVifsType(vm.vifs, vifType)
            raiseExceptionIfFail(xen_set_vcpus(vmPath, vm.cpuNum))
            raiseExceptionIfFail(xen_set_memory(vmPath, BytesToM(vm.memory)))
            raiseExceptionIfFail(
                xen_add_disk(vmPath, vm.rootDisk.path, mode=vm.rootDisk.type))
            vifs = [OvmVif.toXenString(v) for v in vm.vifs]
            for vif in vifs:
                raiseExceptionIfFail(xen_set_vifs(vmPath, vif))

            for disk in vm.disks:
                raiseExceptionIfFail(
                    xen_add_disk(vmPath, disk.path, mode=disk.type))

            raiseExceptionIfFail(xen_set_vm_vnc_password(vmPath, ""))
            cfgFile = join(vmPath, 'vm.cfg')
            # only HVM supports attaching cdrom
            if vmType == 'HVM':
                # Add an empty "hdc:cdrom" entry in config. Fisrt we set boot order to 'd' that is cdrom boot,
                # then 'hdc:cdrom' entry will be in disk list. Second, change boot order to 'c' which
                # is harddisk boot. VM can not start with an empty 'hdc:cdrom' when boot order is 'd'.
                # it's tricky !
                raiseExceptionIfFail(xen_config_boot_sequence(vmPath, 'd'))
                raiseExceptionIfFail(xen_config_boot_sequence(vmPath, 'c'))

            raiseExceptionIfFail(xen_correct_cfg(cfgFile, vmPath))
            xen_correct_qos_cfg(cfgFile)
            dumpCfg(vm.name, cfgFile)
            server = successToMap(get_master_ip())['ip']
            raiseExceptionIfFail(start_vm(vmPath, server))
            rs = SUCC()
            return rs