Skip to content

Commit 25bdb46

Browse files
author
80333521
committed
add get_host_info_all function and example
signed off: tangliangliang@oppo.com
1 parent 15b9043 commit 25bdb46

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

examples/disp_host.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pythonlsf import lsf
2+
import inspect
3+
4+
if __name__ == '__main__':
5+
if lsf.lsb_init("test") > 0:
6+
exit - 1;
7+
8+
for hostInfoEnt in lsf.get_host_info_all():
9+
attributes = [d for d in dir(hostInfoEnt)
10+
if not d.startswith('__')]
11+
item = {}
12+
for a in attributes:
13+
v = getattr(hostInfoEnt, a)
14+
if not inspect.ismethod(v) and isinstance(v, (int, str, float)):
15+
item[a] = v
16+
print(item)

pythonlsf/lsf.i

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,25 @@ PyObject * get_pids_from_stream(struct jRusage * jrusage) {
707707
PyList_SetItem(result, i, o);
708708
}
709709
return result;
710-
}
710+
}
711+
712+
PyObject * get_host_info_all() {
713+
struct hostInfoEnt *hostinfo;
714+
char **hosts = NULL;
715+
int numhosts = 0;
716+
717+
// Return queries as C hostInfoEnt*
718+
hostinfo = lsb_hostinfo(hosts, &numhosts);
719+
720+
PyObject *result = PyList_New(numhosts); // Create PyObject * to get C returns
721+
int i;
722+
for (i = 0; i < numhosts; i++) { // Save queries in a loop to result
723+
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hostinfo[i]),
724+
SWIGTYPE_p_hostInfoEnt, 0 | 0 );
725+
PyList_SetItem(result,i,o);
726+
}
727+
728+
return result;
729+
}
711730

712731
%}

0 commit comments

Comments
 (0)