Ejemplo n.º 1
0
def delete(_id):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2016-01-05 10:23
    Description : Used to delete or undefine a virtual network card;
    '''
    try:
        vif = conn.networkLookupByUUIDString(_id)
        if vif.isActive():
            vif.destroy()
        vif.undefine()
        VIFHelper.remove({"_id": _id})
    except Exception, e:
        log.debug("VIF.delete Failed! Message: %s" % e)
        return None
Ejemplo n.º 2
0
        return None
    return True
def attach(vm_id, vif_id):
    '''
    Author      : LHearen
    E-mail      : [email protected]
    Time        : 2016-01-06 15:35
    Description : Attaching a vif to a VM;
    '''
    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