Example #1
0
def unsetTemplate(_id):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2016-01-06 14:02
    Description : Used to set the VM specified by _id not template;
    '''
    ret = VMHelper.update({"_id": _id}, {"isTemplate": False})
    if ret['ok'] > 0:
        return True
    return None
Example #2
0
def isTemplate(_id):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2015-12-17 11 : 20
    Description : Used to retrieve the isTemplate attribute from DB;
    '''
    print "inside isTemplate ****************"
    ret = VMHelper.retrieve({"_id": _id})["isTemplate"]
    if str(ret).lower() == 'false':
        return False
    else: return True
Example #3
0
    dom = None
    try:
        dom = conn.lookupByUUIDString(vm_id)
    except Exception, e:
        logNotFound("VM", vm_id, e)
        return None
    ret = VIFHelper.retrieve({"_id": vif_id})
    macString = ret['macString']
    source = ret['source']
    interfaceXmlConfig = XmlConverter.toVIFXml(source, macString)
    try:
        dom.attachDeviceFlags(interfaceXmlConfig, 0)
        dataDict = {"busy": True, "attachedVM": vm_id}
        VIFHelper.update({"_id": vif_id}, dataDict)
        dataDict = {"vifs.vif_id": vif_id, "vifs.macString": macString}
        VMHelper.update({"_id": vm_id}, dataDict)
        return True
    except Exception, e:
        log.debug("Attaching VIF %s to VM %s failed! Message: %s" %
                  (vif_id, vm_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
Example #4
0
        dom = conn.lookupByUUIDString(_id)
    except Exception, e:
        logNotFound("VM", _id, e)
        return None
    if dom:
        if dom.isActive(): dom.destroyFlags(int(flags))
        try:
            dom.undefineFlags(int(flags))
        except Exception, e:
            log.debug("VM %s deletion failed! Message: %s" % (_id, e))
        try:
            conn.lookupByUUIDString(_id)
        except Exception, e:
            log.error("VM %s deletion failed! Message: %s" % (_id, e))
            filterDict = {"_id": _id}
            ret = VMHelper.remove(filterDict)
            if ret['ok'] > 0:
                return True
            else:
                log.debug("mongodb deletion failed!")
                return None
    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;
    '''
Example #5
0
        logNotFound("Volume", vol_id, e)
        return None
    root = ET.fromstring(vol.XMLDesc())
    volDir = root.find('key').text
    diskXmlConfig = XmlConverter.toDiskXml(volDir, target, driver, driverType)
    try:
        vm = conn.lookupByUUIDString(vm_id)
    except Exception, e:
        logNotFound("VM", vm_id, e)
        return None
    try:
        vm.attachDeviceFlags(diskXmlConfig)
        dataDict = {"busy": True, "attachedVM": vm_id, "target": target}
        VBDHelper.updateVolume({"_id": vol_id}, dataDict)
        dataDic = {"Volumes": {"vol_id": vol_id, "target": target}}
        VMHelper.update({"_id": vm_id}, dataDic)
    except Exception, e:
        log.debug("Attaching disk failed! Message: %s" % e)
        return None
    return True

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: