Added a method getCPUMapFlags to virConnect. It can be used as follows: import libvirt import sys import os conn = libvirt.openReadOnly(None) if conn == None: print 'Failed to open connection to the hypervisor' sys.exit(1) try: (cpus, cpumap, online) = conn.getCPUMapFlags(0) except: print 'Failed to extract the node cpu map information' sys.exit(1) print 'CPUs total %d, online %d' % (cpus, online) print 'CPU map %s' % str(cpumap) del conn print "OK" sys.exit(0) Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx> --- python/libvirt-override-api.xml | 6 ++++ python/libvirt-override.c | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-) diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml index b76fb4e..59ac190 100644 --- a/python/libvirt-override-api.xml +++ b/python/libvirt-override-api.xml @@ -542,5 +542,11 @@ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='flags' type='int' info='unused, always pass 0'/> </function> + <function name='virNodeGetCPUMapFlags' file='python'> + <info>Get node CPU information</info> + <return type='str *' info='(cpunum, online, cpumap) on success, None on error'/> + <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> + <arg name='flags' type='int' info='unused, pass 0'/> + </function> </symbols> </api> diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 81099b1..9d86964 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -6347,6 +6347,61 @@ cleanup: return ret; } +static PyObject * +libvirt_virNodeGetCPUMapFlags(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) +{ + virConnectPtr conn; + PyObject *pyobj_conn; + PyObject *ret = NULL; + PyObject *pycpumap = NULL; + PyObject *pyused = NULL; + int i_retval; + unsigned char *cpumap = NULL; + unsigned int online = 0; + unsigned int flags; + int i; + + if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetCPUMapFlags", + &pyobj_conn, &flags)) + return NULL; + conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); + + LIBVIRT_BEGIN_ALLOW_THREADS; + i_retval = virNodeGetCPUMapFlags(conn, &cpumap, &online, flags); + LIBVIRT_END_ALLOW_THREADS; + + if (i_retval < 0) + goto error; + + if ((ret = PyTuple_New(3)) == NULL) + goto error; + + if ((pycpumap = PyList_New(i_retval)) == NULL) + goto error; + + for (i = 0; i < i_retval; i++) { + if ((pyused = PyBool_FromLong(VIR_CPU_USED(cpumap, i))) == NULL) + goto error; + if (PyList_SetItem(pycpumap, i, pyused) < 0) + goto error; + } + + PyTuple_SetItem(ret, 0, PyLong_FromLong(i_retval)); + PyTuple_SetItem(ret, 1, pycpumap); + PyTuple_SetItem(ret, 2, PyLong_FromLong(online)); + +cleanup: + VIR_FREE(cpumap); + return ret; +error: + Py_XDECREF(ret); + Py_XDECREF(pycpumap); + Py_XDECREF(pyused); + ret = VIR_PY_NONE; + goto cleanup; +} + /************************************************************************ * * @@ -6464,6 +6519,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL}, {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL}, {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL}, + {(char *) "virNodeGetCPUMapFlags", libvirt_virNodeGetCPUMapFlags, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; -- 1.7.0.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list