Skip to content

Commit 4dfbd18

Browse files
authored
Merge pull request #44 from lleiiell/master
add get_host_info_all function and example
2 parents 65fe2f9 + aeccac0 commit 4dfbd18

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

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

731+
return result;
732+
}
733+
715734
%}

0 commit comments

Comments
 (0)