Esempio n. 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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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