示例#1
0
def CreateLab(configLab):
    res = StatusVLAB()
    res.Messages = []
    res.StatusOK = True

    xcp = XCPMethods(logging=res, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return
    xcp.ReadConfs()

    xvp = XVPMethods(logging=res, conf=config)
    xvp.ConnectDB()
    if not xvp.SQLConnect:
        return
    xvp.sqlCur = xvp.SQLConnect.cursor()

    if configLab.Action.lower() == "create":
        _createLab(xcp, xvp, configLab)
    elif configLab.Action.lower() == "delete":
        _deleteLab(xcp, xvp, configLab)
    else:
        res.Messages.append(
            "ERROR: Action is wrong!!! Action is 'create' or 'delete'")
        res.StatusOK = False

    xvp.SQLConnect.commit()
    xvp.SQLConnect.close()
    xcp.xapi.logout()

    return res
示例#2
0
def CreateLab(configLab):
    res = StatusVLAB()
    res.Messages = []
    res.StatusOK = True

    xcp = XCPMethods(logging=res, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return
    xcp.ReadConfs()

    xvp = XVPMethods(logging=res, conf=config)
    xvp.ConnectDB()
    if not xvp.SQLConnect:
        return
    xvp.sqlCur = xvp.SQLConnect.cursor()

    if configLab.Action.lower() == "create":
        _createLab(xcp, xvp, configLab)
    elif configLab.Action.lower() == "delete":
        _deleteLab(xcp, xvp, configLab)
    else:
        res.Messages.append("ERROR: Action is wrong!!! Action is 'create' or 'delete'")
        res.StatusOK = False

    xvp.SQLConnect.commit()
    xvp.SQLConnect.close()
    xcp.xapi.logout()

    return res
示例#3
0
def ChangeStateVM(uuid, state):
    res = StatusVLAB()
    res.Messages = []
    res.StatusOK = True

    xcp = XCPMethods(logging=res, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    if not xcp.ChangeStateVM(uuid, state):
        res.StatusOK = False

    return res
示例#4
0
def ChangeStateVM(uuid, state):
    res = StatusVLAB()
    res.Messages = []
    res.StatusOK = True

    xcp = XCPMethods(logging=res, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    if not xcp.ChangeStateVM(uuid, state):
        res.StatusOK = False

    return res
示例#5
0
def GetStudentsByLab(strLab):
    res = ValuesAD()
    res.Status = StatusVLAB()
    res.Values = []
    res.Status.Messages = []
    res.Status.StatusOK = True

    xcp = XCPMethods(logging=res.Status, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    xcp.ReadConfs()

    xvp = XVPMethods(logging=res.Status, conf=config)
    xvp.ConnectDB()
    if not xvp.SQLConnect:
        return
    xvp.sqlCur = xvp.SQLConnect.cursor()
    pool = xcp.GetPoolName()

    for obj in xcp.GetVMsByLab(strLab):
        for user in xvp.GetUsersByVMUUIDWithoutGroups(pool, obj['uuid']):
            res.Values.append(user)

    return res
示例#6
0
def GetUsersVM(uuid):
    res = ValuesAD()
    res.Status = StatusVLAB()
    res.Values = []
    res.Status.Messages = []
    res.Status.StatusOK = True

    xcp = XCPMethods(logging=res.Status, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    xvp = XVPMethods(logging=res.Status, conf=config)
    xvp.ConnectDB()
    if not xvp.SQLConnect:
        return
    xvp.sqlCur = xvp.SQLConnect.cursor()

    objs = xcp.GetGroupsByUUID(uuid)
    if not objs:
        res.Status.StatusOK = False
        return res

    pool = xcp.GetPoolName()

    for obj in xvp.GetUsersByVMUUID(pool, uuid, objs):
        res.Values.append(obj)

    return res
示例#7
0
def GetNetworks():

    res = ValuesXCP()
    res.Status = StatusVLAB()
    res.Values = []
    res.Status.Messages = []
    res.Status.StatusOK = True

    xcp = XCPMethods(logging=res.Status, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    objs = xcp.GetNetworks()
    if not objs:
        res.Status.StatusOK = False
        return res

    for obj in objs:
        valueXCP = ValueXCP()
        valueXCP.Ref = obj
        valueXCP.Value = xcp.xapi.network.get_name_label(obj)
        res.Values.append(valueXCP)

    return res
示例#8
0
def GetStudentsByGroup(group):
    res = ValuesAD()
    res.Status = StatusVLAB()
    res.Values = []
    res.Status.Messages = []
    res.Status.StatusOK = True

    ad = LDAPMethods(logging=res.Status, conf=config)
    ad.InitAD()

    for obj in ad.GetAdUsers(group):
        res.Values.append(obj)

    return res
示例#9
0
def GetVMsUsers(strUser):
    res = ValuesXCP()
    res.Status = StatusVLAB()
    res.Values = []
    res.Status.Messages = []
    res.Status.StatusOK = True

    xcp = XCPMethods(logging=res.Status, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    xvp = XVPMethods(logging=res.Status, conf=config)
    xvp.ConnectDB()
    if not xvp.SQLConnect:
        return
    xvp.sqlCur = xvp.SQLConnect.cursor()

    pool = xcp.GetPoolName()
    uuids = xvp.GetVMUUIDByUser(pool, strUser)
    if len(uuids) > 0:
        if uuids[0] == '*':
            return GetAllVM()

    for obj in uuids:
        vm = xcp.FindVMbyUUID(obj)

        if not res.Status.StatusOK:
            return res

        if not vm:
            continue

        valueXCP = ValueXCP()
        valueXCP.Ref = obj
        valueXCP.Value = xcp.xapi.VM.get_name_label(vm)
        res.Values.append(valueXCP)

    for group in xvp.GetVMGroupByUser(pool, strUser):
        for obj in xcp.GetVMByGroup(group):
            valueXCP = ValueXCP()
            valueXCP.Ref = xcp.xapi.VM.get_uuid(obj)
            valueXCP.Value = xcp.xapi.VM.get_name_label(obj)
            res.Values.append(valueXCP)

    return res
示例#10
0
def GetLabs():
    res = ValuesXCP()
    res.Status = StatusVLAB()
    res.Values = []
    res.Status.Messages = []
    res.Status.StatusOK = True

    xcp = XCPMethods(logging=res.Status, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res
    xcp.ReadConfs()
    for obj in xcp.GetLabs():
        valueXCP = ValueXCP()
        valueXCP.Value = obj
        res.Values.append(valueXCP)
    return res
示例#11
0
def GetStatusVM(uuid):
    res = SingleValueXCP()
    res.Status = StatusVLAB()
    res.Status.Messages = []
    res.Status.StatusOK = True

    xcp = XCPMethods(logging=res.Status, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    objs = xcp.GetStatusVM(uuid)
    if not objs:
        res.Status.StatusOK = False
        return res

    res.Values = objs

    return res
示例#12
0
def GetVMsByLab(strLab):
    res = ValuesXCP()
    res.Status = StatusVLAB()
    res.Values = []
    res.Status.Messages = []
    res.Status.StatusOK = True

    xcp = XCPMethods(logging=res.Status, conf=config)
    resOK = xcp.ConnectXCP()
    if not resOK:
        return res

    xcp.ReadConfs()

    for obj in xcp.GetVMsByLab(strLab):
        valueXCP = ValueXCP()
        valueXCP.Ref = obj['uuid']
        valueXCP.Value = obj['name_label']
        res.Values.append(valueXCP)

    return res