From 25bdb46e2e8f73ad8d05570aeb3ecffd4f7c1d91 Mon Sep 17 00:00:00 2001 From: 80333521 Date: Tue, 9 Aug 2022 09:39:41 +0800 Subject: [PATCH] add get_host_info_all function and example signed off: tangliangliang@oppo.com --- examples/disp_host.py | 16 ++++++++++++++++ pythonlsf/lsf.i | 21 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 examples/disp_host.py 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 index 145ef0a..5b1dd34 100755 --- a/pythonlsf/lsf.i +++ b/pythonlsf/lsf.i @@ -707,6 +707,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; +} %}