def deletePool(_id): ''' 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
def detach(vm_id, vif_id): ''' Author : LHearen E-mail : [email protected] Time : 2016-01-06 15:35 Description : Detaching a vif from a VM; ''' dom = None try: dom = conn.lookupByUUIDString(vm_id) except Exception, e: logNotFound("VM", vm_id, e) return None
def delete(_id, flags=0): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-16 14 : 00 Description : destory the VM first if it's still active and then undefine it and delete the document in db; ''' dom = None try: dom = conn.lookupByUUIDString(_id) except Exception, e: logNotFound("VM", _id, e) return None
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
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
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
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
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
def reboot(_id, flags=0): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-16 14 : 00 Description : waiting for a period of time until vm is off, after which destroy it and then start it; ''' unit = 2 dom = None try: dom = conn.lookupByUUIDString(_id) except Exception: logNotFound("VM", _id, e) return None try: dom.shutdownFlags(int(flags)) except: pass for i in range(3): sleep(unit) if not dom.isActive(): break; if dom.isActive(): try: dom.destroy() except: pass if not dom.isActive(): try: dom.createWithFlags(int(flags)) except: pass else: return None if not dom.isActive(): return None else: return True
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 try: volume = pool.storageVolLookupByName(volName) except libvirtError, e: logNotFound("Volume", volName, e) return None try: volume.delete() filterDict = {"_id": _id} VBDHelper.removeVolume(filterDict) except libvirtError, e: log.debug("Volume %s deletion failed! Message: %s" % (volName, e)) return None return True def listVolumes(_id): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-30 16:24