Skip to content

Commit 85bd403

Browse files
authored
support for retrieve data correctly ls_info() api
1 parent 2ecc74a commit 85bd403

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

pythonlsf/lsf.i

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,140 @@ PyObject * ls_load_py(char *resreq, int *numhosts, int options, char *fromhost)
463463
return result;
464464
}
465465

466+
PyObject * ls_load_py(char *resreq, int *numhosts, int options, char *fromhost) {
467+
468+
struct hostLoad * hosts = NULL;
469+
int i = 0, j = 0;
470+
471+
hosts = ls_load(resreq, numhosts, options, fromhost);
472+
473+
if (hosts == NULL) {
474+
ls_perror("ls_load_py");
475+
exit(-1);
476+
}
477+
478+
/* Python3 can not handle dirty string.*/
479+
for (i = 0; i < *numhosts; i++) {
480+
int size_string = sizeof(hosts[i].hostName);
481+
int len_string = strlen(hosts[i].hostName);
482+
for ( j = len_string; j < size_string; j++) hosts[i].hostName[j] = 0;
483+
}
484+
485+
PyObject * result = PyList_New(*numhosts);
486+
for (i = 0; i < *numhosts; i++) {
487+
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hosts[i]),
488+
SWIGTYPE_p_hostLoad, 0 | 0 );
489+
PyList_SetItem(result,i,o);
490+
}
491+
492+
return result;
493+
}
494+
495+
PyObject * ls_info_py() {
496+
struct resItem * allRes = NULL;
497+
struct lsInfo * allInfo = NULL;
498+
char *type = NULL;
499+
char *model = NULL;
500+
char *arch = NULL;
501+
502+
int i = 0, j = 0;
503+
504+
allInfo = ls_info();
505+
if (allInfo == NULL) {
506+
ls_perror("ls_info_py");
507+
exit(-1);
508+
}
509+
510+
PyObject * result = PyDict_New();
511+
PyObject * nRes = Py_BuildValue("i",allInfo->nRes);
512+
PyDict_SetItemString(result, "nRes",nRes);
513+
PyObject * nTypes = Py_BuildValue("i", allInfo->nTypes);
514+
PyDict_SetItemString(result, "nTypes", nTypes);
515+
PyObject * nModels = Py_BuildValue("i", allInfo->nModels);
516+
PyDict_SetItemString(result, "nModels", nModels);
517+
PyObject * numIndx = Py_BuildValue("i", allInfo->numIndx);
518+
PyDict_SetItemString(result, "numIndx", numIndx);
519+
PyObject * numUsrIndx = Py_BuildValue("i", allInfo->numUsrIndx);
520+
PyDict_SetItemString(result, "numUsrIndx", numUsrIndx);
521+
522+
allRes = allInfo->resTable;
523+
for (i = 0; i < allInfo->nRes; i++) {
524+
int size_string = sizeof(allRes[i].name);
525+
int len_string = strlen(allRes[i].name);
526+
for (j = len_string; j < size_string; j++) {
527+
allRes[i].name[j] = 0;
528+
}
529+
size_string = sizeof(allRes[i].des);
530+
len_string = strlen(allRes[i].des);
531+
for (j = len_string; j < size_string; j++) {
532+
allRes[i].des[j] = 0;
533+
}
534+
}
535+
536+
PyObject * resRst = PyList_New(allInfo->nRes);
537+
for (i = 0; i < allInfo->nRes; i++) {
538+
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&allRes[i]),
539+
SWIGTYPE_p_resItem, 0 | 0);
540+
PyList_SetItem(resRst,i,o);
541+
}
542+
PyDict_SetItemString(result, "resTable", resRst);
543+
544+
PyObject * typeRst = PyList_New(allInfo->nTypes);
545+
for (i = 0; i < allInfo->nTypes; i++) {
546+
type = strdup(allInfo->hostTypes[i]);
547+
int size_string = sizeof(type);
548+
int len_string = strlen(type);
549+
for (j = len_string; j < size_string; j++) {
550+
type[j] = 0;
551+
}
552+
PyObject * pyType = Py_BuildValue("s",type);
553+
PyList_SetItem(typeRst,i,pyType);
554+
if (type != NULL) {
555+
free(type);
556+
}
557+
}
558+
PyDict_SetItemString(result, "hostTypes", typeRst);
559+
560+
PyObject * modelRst = PyList_New(allInfo->nModels);
561+
PyObject * archRst = PyList_New(allInfo->nModels);
562+
PyObject * refRst = PyList_New(allInfo->nModels);
563+
PyObject * factorRst = PyList_New(allInfo->nModels);
564+
565+
for (i = 0; i < allInfo->nModels; i++) {
566+
model = strdup(allInfo->hostModels[i]);
567+
int size_string = sizeof(model);
568+
int len_string = strlen(model);
569+
for (j = len_string; j < size_string; j++) {
570+
model[j] = 0;
571+
}
572+
PyObject *pyModel = Py_BuildValue("s",model);
573+
PyList_SetItem(modelRst,i,pyModel);
574+
575+
arch = strdup(allInfo->hostArchs[i]);
576+
size_string = sizeof(arch);
577+
len_string = strlen(arch);
578+
for (j = len_string; j < size_string; j++) {
579+
arch[j] = 0;
580+
}
581+
PyObject *pyArch = Py_BuildValue("s",arch);
582+
PyList_SetItem(archRst,i,pyArch);
583+
584+
PyObject *pyRef = Py_BuildValue("i",allInfo->modelRefs[i]);
585+
PyList_SetItem(refRst,i,pyRef);
586+
587+
PyObject *pyFactor = Py_BuildValue("f",allInfo->cpuFactor[i]);
588+
PyList_SetItem(factorRst,i,pyFactor);
589+
}
590+
591+
PyDict_SetItemString(result,"hostModels",modelRst);
592+
PyDict_SetItemString(result,"hostArchs",archRst);
593+
PyDict_SetItemString(result,"modelRefs",refRst);
594+
PyDict_SetItemString(result,"cpuFactor",factorRst);
595+
596+
return result;
597+
}
466598

599+
467600
PyObject * get_queue_info_by_name(char** name, int num) {
468601
struct queueInfoEnt* queueinfo;
469602
int numqueues = num;

0 commit comments

Comments
 (0)