Example #1
0
def createVM(name):
    """"""
    try:
        global vmmap,vmpool,config,mod_log
        #should select a host ip!
        ip=mod_monitor.selectHostIP(vmpool)
        #ip="127.0.0.1"
        param="qemu+ssh://root@"+ip+"/system"
        conn=libvirt.open(param)
        vmconfig=mod_config.setName(config['Windows2k8'],name)
        vm=conn.createLinux(vmconfig,0)
        #add to list
        vmmap[vm.UUIDString()]=ip
        if(vmpool.has_key(ip)):
            vmpool[ip].append(vm.UUIDString())
        else:
            vmpool[ip]=[]
            vmpool[ip].append(vm.UUIDString())
        conn.close()
        #log
        mod_log.write(time.ctime()+" Info "+"create vm on host:"+ip+"\n")
        mod_log.flush()
        return vm.UUIDString()
    except Exception,e:
        mod_log.write(time.ctime()+" Error "+e+"\n")
        mod_log.flush()
        return None
Example #2
0
import os,sys
import libvirt
import mod_vm
import mod_config

mod_vm.mod_init()
conn=libvirt.open("qemu:///system")
vmconfig=mod_config.setName(mod_vm.config["Windows2k8"],"testname hello")
print vmconfig
dom=conn.createLinux(vmconfig,0)