/
Using the PBS IFL API via Python
Using the PBS IFL API via Python
- Ensure swig, python-devel, and gcc are installed
Create a file named
pbs_ifl.i
, with the below content (let’s say file is/tmp/pbsapi/pbs_ifl.i
):%module pbs_ifl %typemap(out) char ** { int len,i; len = 0; while ($1[len]) len++; $result = PyList_New(len); for (i = 0; i < len; i++) { PyList_SetItem($result,i,PyString_FromString($1[i])); } } %typemap(in) char ** { if (PyList_Check($input)) { int size = PyList_Size($input); int i = 0; $1 = (char **) malloc((size+1)*sizeof(char *)); for (i = 0; i < size; i++) { PyObject *o = PyList_GetItem($input,i); if (PyString_Check(o)) $1[i] = PyString_AsString(PyList_GetItem($input,i)); else { PyErr_SetString(PyExc_TypeError,"list must contain strings"); free($1); return NULL; } } $1[i] = 0; } else { PyErr_SetString(PyExc_TypeError,"not a list"); return NULL; } } %typemap(out) struct batch_status * { struct batch_status *head_bs, *bs; struct attrl *attribs; char *resource; char *str; int i, j; int len; char buf[4096]; static char *id = "id"; head_bs = $1; bs = $1; for (len=0; bs != NULL; len++) bs = bs->next; $result = PyList_New(len); bs = head_bs; for (i=0; i < len; i++) { PyObject *dict; PyObject *a, *v, *tmpv; dict = PyDict_New(); PyList_SetItem($result, i, dict); a = PyString_FromString(id); v = PyString_FromString(bs->name); PyDict_SetItem(dict, a, v); attribs = bs->attribs; while (attribs) { resource = attribs->resource; if (resource != NULL) { str = malloc(strlen(attribs->name) + strlen(resource) + 2); sprintf(str, "%s.%s", attribs->name, attribs->resource); a = PyString_FromString(str); } else { a = PyString_FromString(attribs->name); } tmpv = PyDict_GetItem(dict, a); if (tmpv != NULL) { char *s = PyString_AsString(tmpv); str = malloc(strlen(attribs->value) + strlen(s) + 4); sprintf(str, "%s,%s", attribs->value, s); v = PyString_FromString(str); } else { v = PyString_FromString(attribs->value); } PyDict_SetItem(dict, a, v); attribs = attribs->next; } bs = bs->next; } } %{ #include "pbs_ifl.h" %} %include "pbs_ifl.h"
cd /tmp/pbsapi
source /etc/pbs.conf
(Change /etc/pbs.conf according to location of pbs.conf in your system)swig -python -I${PBS_EXEC}/include ./pbs_ifl.i
(This command should generate pbs_ifl.py and pbs_ifl_wrap.c in current directory)gcc -Wall -Wno-unused-variable -fPIC -shared -I${PBS_EXEC}/include -I/usr/include/python2.7 -L${PBS_EXEC}/lib -lpbs -o _pbs_ifl.so ./pbs_ifl_wrap.c
(This should generate _pbs_ifl.so in current directory)export LD_LIBRARY_PATH=${PBS_EXEC}/lib:${LD_LIBRARY_PATH}
export PYTHONPATH=/tmp/pbsapi:${PYTHONPATH}
(This is required only when PWD is not /tmp/pbsapi)(Optional) Run
ldd /tmp/pbsapi/_pbs_ifl.so
and check output, and ensure that no missing lib is reported.
Now you can use the PBS IFL API from python, for example:python -c "from pbs_ifl import *;import json;c=pbs_connect(None);print json.dumps(pbs_statserver(c, None, None), indent=2)" [ { "eligible_time_enable": "False", "default_chunk.ncpus": "1", "license_count": "Avail_Global:10000000 Avail_Local:10000000 Used:0 High_Use:0", "pbs_license_min": "0", "scheduling": "True", "id": "testdev", "total_jobs": "0", "server_host": "testdev.pbspro.com", "FLicenses": "20000000", "node_fail_requeue": "310", "resv_enable": "True", "power_provisioning": "False", "query_other_jobs": "True", "state_count": "Transit:0 Queued:0 Held:0 Waiting:0 Running:0 Exiting:0 Begun:0 ", "default_queue": "workq", "server_state": "Active", "max_concurrent_provision": "5", "scheduler_iteration": "600", "pbs_license_linger_time": "31536000", "mail_from": "adm", "log_events": "511", "pbs_version": "18.1.0", "resources_default.ncpus": "1", "pbs_license_max": "2147483647", "max_array_size": "10000" } ]
, multiple selections available,
Related content
Building PBS Professional Under Windows: PBS v. <19.4
Building PBS Professional Under Windows: PBS v. <19.4
More like this
User Documentation
User Documentation
Read with this
Using pbs_swigify
Using pbs_swigify
More like this
Using Docker to Instantiate PBS
Using Docker to Instantiate PBS
Read with this
OpenPBS Coding Standards
OpenPBS Coding Standards
More like this
Building OpenPBS Using rpmbuild
Building OpenPBS Using rpmbuild
Read with this