Exemple #1
0
def createVolume(_id, poolName, volName, volSize):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-30 15 : 43
    Description : Create a volume in a existed pool specified by a pool name;
    '''
    if len(_id) < 5:
        from utils.UUIDGenerator import createString
        _id = createString()
    volName = volName if volName else _id
    global VolumeUUIDString
    VolumeUUIDString = _id
    global VolName
    VolName = volName
    try:
        pool = conn.storagePoolLookupByName(poolName)
    except libvirtError, e:
        logNotFound("Pool", poolName, e)
        return None
Exemple #2
0
def create(_id, name, source, macString):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2016-01-05 09:40
    Description : Used to create a virtual network card;
    '''
    if len(_id) < 5:
        from utils.UUIDGenerator import createString
        global VIFUUIDString
        _id = createString()
    name = name if name else _id
    VIFUUIDString = _id
    xmlConfig = XmlConverter.toNetXml(_id, name, source, macString)
    try:
        conn.networkDefineXML(xmlConfig)
    except Exception:
        log.exception(traceback.print_exc())
        return None
    return True
Exemple #3
0
def createPool(_id, name, target):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-30 10 : 17
    Description : Using indispensible factors to create a pool;
    '''
    if len(_id) < 5:
        from utils.UUIDGenerator import createString
        _id = createString()
    name = name if name else _id
    global PoolName
    PoolName = name
    global PoolUUIDString
    PoolUUIDString = _id
    config = XmlConverter.toSRXml(_id, name, target)
    try:
        conn.poolCreateXML(config)
    except libvirtError, e:
        log.debug("pool %s creation failed! Message: %s" % (name, e))
        return None
Exemple #4
0
def create(_id, name, memory, vcpu, mac, diskDir, isoDir, bridgeSrc):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-16 09 : 43
    Description : Using limited parameters to create a VM and return its UUIDString;
    '''
    uuid = _id
    if len(uuid) < 5:
        uuid = createString()
    name = name if name else uuid
    global UUIDString
    UUIDString = uuid
    global Name
    Name = name
    hvm = {"loader": "/usr/lib/xen/boot/hvmloader"}
    hvm["boot"] = "cdrom"
    hvm["device_model"] = "/usr/lib/xen/bin/qemu-system-i386"
    image = {"hvm": hvm}

    tap2 = {"dev": "hdc:cdrom"}
    tap2["uname"] = "tap:aio:" + isoDir
    tap2["mode"] = "r"

    vif = {"bridge": bridgeSrc}
    if mac is not None:
        vif["mac"] = mac;

    vbd = {"dev": "hda:disk"}
    vbd["uname"] = "tap:aio:" + diskDir
    vbd["mode"] = "w"

    vfb = {"location": "0.0.0.0:5900"}
    vfb["vnclisten"] = "0.0.0.0"

    console = {"location": "0"}
    xmlConfig = XmlConverter.toVMXml(uuid, name, memory, vcpu, image, tap2,
                                        vif, vbd, vfb, console)
    # print xmlConfig
    return define_VM_by_xml(xmlConfig)