Example #1
0
def detachVolume(vm_id, vol_id):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2016-01-07 16:27
    Description : Detach a disk specified by mounted target from a VM;
    '''
    vol = VBDHelper.retrieveVolume({"_id": vol_id})
    target = vol["target"]
    try:
        vm = conn.lookupByUUIDString(vm_id)
    except Exception, e:
        logNotFound("VM", vm_id, e)
        return None
Example #2
0
def attachVolume(vm_id, vol_id, target, driver='qemu', driverType='qcow2'):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2016-01-07 10:54
    Description : Attaching a volume to a VM;
    '''
    vol = VBDHelper.retrieveVolume({"_id": vol_id})
    volName = vol["volName"]
    poolName = vol["poolName"]
    try:
        pool = conn.storagePoolLookupByName(poolName)
    except Exception, e:
        logNotFound("Pool", poolName, e)
        return None
Example #3
0
def deleteVolume(_id):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-30 10 : 31
    Description : Used to delete a volume in a specified pool;
    '''
    vol = VBDHelper.retrieveVolume({"_id": _id})
    poolName = vol["poolName"]
    volName = vol["volName"]
    try:
        pool = conn.storagePoolLookupByName(poolName)
    except libvirtError, e:
        logNotFound("Pool", poolName, e)
        return None
Example #4
0
def listVolumes(_id):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-30 16:24
    Description : Used to list volume names in a pool;
    '''
    pool0 = VBDHelper.retrievePool({'_id': _id})
    print pool0
    poolName = pool0["name"]
    try:
        pool = conn.storagePoolLookupByName(poolName)
    except libvirtError, e:
        logNotFound("Pool", poolName, e)
        return None
Example #5
0
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-30 10 : 17
    Description : Delete the pool specified by a name;
    '''
    try:
        pool = conn.storagePoolLookupByUUIDString(_id)
    except libvirtError, e:
        logNotFound("Pool", _id, e)
        return None
    if pool.isActive():
        pool.destroy()
    try:
        pool.undefine()
        filterDict = {"_id": _id}
        VBDHelper.removePool(filterDict)
    except libvirtError, e:
        log.debug("pool %s cannot be removed! Message: %s" % (_id, e))
        return None
    return True

def listPools():
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-30 10 : 25
    Description : Used to list all known pools;
    '''
    try:
        poolNames = conn.listAllStoragePoolsNames()
    except libvirtError, e: