diff --git a/examples/disp_host.py b/examples/disp_host.py new file mode 100644 index 0000000..210ca9b --- /dev/null +++ b/examples/disp_host.py @@ -0,0 +1,16 @@ +from pythonlsf import lsf +import inspect + +if __name__ == '__main__': + if lsf.lsb_init("test") > 0: + exit - 1; + + for hostInfoEnt in lsf.get_host_info_all(): + attributes = [d for d in dir(hostInfoEnt) + if not d.startswith('__')] + item = {} + for a in attributes: + v = getattr(hostInfoEnt, a) + if not inspect.ismethod(v) and isinstance(v, (int, str, float)): + item[a] = v + print(item) diff --git a/pythonlsf/lsf.i b/pythonlsf/lsf.i old mode 100755 new mode 100644 index ba1e52e..cbff853 --- a/pythonlsf/lsf.i +++ b/pythonlsf/lsf.i @@ -710,6 +710,25 @@ PyObject * get_pids_from_stream(struct jRusage * jrusage) { PyList_SetItem(result, i, o); } return result; -} +} + +PyObject * get_host_info_all() { + struct hostInfoEnt *hostinfo; + char **hosts = NULL; + int numhosts = 0; + + // Return queries as C hostInfoEnt* + hostinfo = lsb_hostinfo(hosts, &numhosts); + + PyObject *result = PyList_New(numhosts); // Create PyObject * to get C returns + int i; + for (i = 0; i < numhosts; i++) { // Save queries in a loop to result + PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hostinfo[i]), + SWIGTYPE_p_hostInfoEnt, 0 | 0 ); + PyList_SetItem(result,i,o); + } + return result; +} + %}