Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions lsinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from pythonlsf import lsf
import sys

def printLsInfo(argList):
if lsf.lsb_init("test") > 0:
return -1;

valueList=["Boolean","Numeric","String","Dynamic","External"]
orderList=["Inc","Dec","N/A"]
allInfo = lsf.ls_info_py()
print("Current cluster has {} resources in total.".format(allInfo["nRes"]))
print("Current cluster has {} types in total.".format(allInfo["nTypes"]))
print("Current cluster has {} models in total.".format(allInfo["nModels"]))
resTable = allInfo["resTable"]

matchList = []
unMatchList = []
showAll = 0
mFlag = 0
mmFlag = 0
rFlag = 0
tFlag = 0
resFound = 0
if "-m" in argList:
mFlag = 1
if "-M" in argList:
mFlag = 1
mmFlag = 1
if "-r" in argList:
rFlag = 1
if "-t" in argList:
tFlag = 1

if len(argList) > 0:
for target in argList:
if target[0] != "-":
resFound = 0
for i in range(len(resTable)):
if resTable[i].name == target :
matchList.append(i)
resFound = 1
break
if resFound == 0:
unMatchList.append(target)

if len(argList) == 0 and len(unMatchList) == 0:
showAll = 1

if (showAll == 1 or rFlag > 0 or len(matchList) > 0 or len(unMatchList) > 0) :
print("ESOURCE_NAME TYPE ORDER DESCRIPTION")
if len(matchList) == 0 and len(unMatchList) == 0:
for i in range(len(resTable)):
print("{} {} {} {}".format(resTable[i].name, valueList[resTable[i].valueType], orderList[resTable[i].orderType], resTable[i].des))

else:
for i in range(len(resTable)):
if i in matchList :
print("{} {} {} {}".format(resTable[i].name, valueList[resTable[i].valueType], orderList[resTable[i].orderType], resTable[i].des))
for target in unMatchList :
print("{}: resource name not found.".format(target))
if (showAll == 1 or tFlag > 0):
hostTypes = allInfo["hostTypes"]
print("TYPE_NAME")
for i in range(len(hostTypes)):
print("{}".format(hostTypes[i]))
if mFlag > 0 :
hostModels = allInfo["hostModels"]
hostArchs = allInfo["hostArchs"]
modelRefs = allInfo["modelRefs"]
cpuFactor = allInfo["cpuFactor"]
print("MODEL_NAME CPU_FACTOR ARCHITECTURE")
for i in range(allInfo["nModels"]):
if (mmFlag > 0 or modelRefs[i] > 0):
print("{} {} {}".format(hostModels[i],cpuFactor[i],hostArchs[i]))
if (showAll == 0 and len(matchList) == 0 and mFlag == 0 and mmFlag == 0 and rFlag == 0 and tFlag == 0):
print("No match resource found.")


return 0

if __name__ == '__main__':
print("LSF Clustername is : {}".format(lsf.ls_getclustername()))
argList = []
if len(sys.argv) > 1 :
for i in range(1,len(sys.argv)):
argList.append(sys.argv[i])
printLsInfo(argList)

104 changes: 104 additions & 0 deletions pythonlsf/lsf.i
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,111 @@ PyObject * ls_load_py(char *resreq, int *numhosts, int options, char *fromhost)
return result;
}

PyObject * ls_info_py() {
struct resItem * allRes = NULL;
struct lsInfo * allInfo = NULL;
char *type = NULL;
char *model = NULL;
char *arch = NULL;

int i = 0, j = 0;

allInfo = ls_info();
if (allInfo == NULL) {
ls_perror("ls_info_py");
exit(-1);
}

PyObject * result = PyDict_New();
PyObject * nRes = Py_BuildValue("i",allInfo->nRes);
PyDict_SetItemString(result, "nRes",nRes);
PyObject * nTypes = Py_BuildValue("i", allInfo->nTypes);
PyDict_SetItemString(result, "nTypes", nTypes);
PyObject * nModels = Py_BuildValue("i", allInfo->nModels);
PyDict_SetItemString(result, "nModels", nModels);
PyObject * numIndx = Py_BuildValue("i", allInfo->numIndx);
PyDict_SetItemString(result, "numIndx", numIndx);
PyObject * numUsrIndx = Py_BuildValue("i", allInfo->numUsrIndx);
PyDict_SetItemString(result, "numUsrIndx", numUsrIndx);

allRes = allInfo->resTable;
for (i = 0; i < allInfo->nRes; i++) {
int size_string = sizeof(allRes[i].name);
int len_string = strlen(allRes[i].name);
for (j = len_string; j < size_string; j++) {
allRes[i].name[j] = 0;
}
size_string = sizeof(allRes[i].des);
len_string = strlen(allRes[i].des);
for (j = len_string; j < size_string; j++) {
allRes[i].des[j] = 0;
}
}

PyObject * resRst = PyList_New(allInfo->nRes);
for (i = 0; i < allInfo->nRes; i++) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&allRes[i]),
SWIGTYPE_p_resItem, 0 | 0);
PyList_SetItem(resRst,i,o);
}
PyDict_SetItemString(result, "resTable", resRst);

PyObject * typeRst = PyList_New(allInfo->nTypes);
for (i = 0; i < allInfo->nTypes; i++) {
type = strdup(allInfo->hostTypes[i]);
int size_string = sizeof(type);
int len_string = strlen(type);
for (j = len_string; j < size_string; j++) {
type[j] = 0;
}
PyObject * pyType = Py_BuildValue("s",type);
PyList_SetItem(typeRst,i,pyType);
if (type != NULL) {
free(type);
}
}
PyDict_SetItemString(result, "hostTypes", typeRst);

PyObject * modelRst = PyList_New(allInfo->nModels);
PyObject * archRst = PyList_New(allInfo->nModels);
PyObject * refRst = PyList_New(allInfo->nModels);
PyObject * factorRst = PyList_New(allInfo->nModels);

for (i = 0; i < allInfo->nModels; i++) {
model = strdup(allInfo->hostModels[i]);
int size_string = sizeof(model);
int len_string = strlen(model);
for (j = len_string; j < size_string; j++) {
model[j] = 0;
}
PyObject *pyModel = Py_BuildValue("s",model);
PyList_SetItem(modelRst,i,pyModel);

arch = strdup(allInfo->hostArchs[i]);
size_string = sizeof(arch);
len_string = strlen(arch);
for (j = len_string; j < size_string; j++) {
arch[j] = 0;
}
PyObject *pyArch = Py_BuildValue("s",arch);
PyList_SetItem(archRst,i,pyArch);

PyObject *pyRef = Py_BuildValue("i",allInfo->modelRefs[i]);
PyList_SetItem(refRst,i,pyRef);

PyObject *pyFactor = Py_BuildValue("f",allInfo->cpuFactor[i]);
PyList_SetItem(factorRst,i,pyFactor);
}

PyDict_SetItemString(result,"hostModels",modelRst);
PyDict_SetItemString(result,"hostArchs",archRst);
PyDict_SetItemString(result,"modelRefs",refRst);
PyDict_SetItemString(result,"cpuFactor",factorRst);

return result;
}


PyObject * get_queue_info_by_name(char** name, int num) {
struct queueInfoEnt* queueinfo;
int numqueues = num;
Expand Down