提交 49556023 编写于 作者: P Peter Krempa

python: Expose binding for virNodeGetCPUStats()

This patch adds binding for virNodeGetCPUStats method of libvirtd.
Return value is represented as a python dictionary mapping field names
to values.
上级 3a9ce767
......@@ -375,9 +375,11 @@ struct _virNodeInfo {
/**
* VIR_NODE_CPU_STATS_ALL_CPUS:
*
* Macro for the total CPU time/utilization
* Value for specifying request for the total CPU time/utilization
*/
#define VIR_NODE_CPU_STATS_ALL_CPUS (-1)
typedef enum {
VIR_NODE_CPU_STATS_ALL_CPUS = -1,
} virNodeGetCPUStatsAllCPUs;
/**
* VIR_NODE_CPU_STATS_KERNEL:
......
......@@ -77,6 +77,13 @@
<return type='int *' info='the list of information or None in case of error'/>
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
</function>
<function name='virNodeGetCPUStats' file='python'>
<info>Extract node's CPU statistics.</info>
<return type='virNodeCPUStats' info='dictionary mapping field names to values or None in case of error'/>
<arg name='conn' type='virConnectPtr' info='pointer to hypervisor connection'/>
<arg name='cpuNum' type='int' info='number of node cpu. (VIR_NODE_CPU_STATS_ALL_CPUS means total cpu statistics)'/>
<arg name='flags' type='unsigned int' info='additional flags'/>
</function>
<function name='virDomainGetUUID' file='python'>
<info>Extract the UUID unique Identifier of a domain.</info>
<return type='char *' info='the 16 bytes string or None in case of error'/>
......
......@@ -2256,6 +2256,52 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg
return(py_retval);
}
static PyObject *
libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
{
PyObject *ret;
PyObject *pyobj_conn;
virConnectPtr conn;
unsigned int flags;
int cpuNum, c_retval, i;
int nparams = 0;
virNodeCPUStatsPtr stats = NULL;
if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeGetCPUStats", &pyobj_conn, &cpuNum, &flags))
return(NULL);
conn = (virConnectPtr)(PyvirConnect_Get(pyobj_conn));
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, flags);
LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0)
return VIR_PY_NONE;
if (nparams) {
if (!(stats = malloc(sizeof(*stats) * nparams)))
return VIR_PY_NONE;
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virNodeGetCPUStats(conn, cpuNum, stats, &nparams, flags);
LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0) {
free(stats);
return VIR_PY_NONE;
}
}
if (!(ret = PyDict_New())) {
free(stats);
return VIR_PY_NONE;
}
for (i = 0; i < nparams; i++) {
PyDict_SetItem(ret,
libvirt_constcharPtrWrap(stats[i].field),
libvirt_ulonglongWrap(stats[i].value));
}
free(stats);
return ret;
}
static PyObject *
libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
......@@ -4949,6 +4995,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},
{(char *) "virDomainGetBlockInfo", libvirt_virDomainGetBlockInfo, METH_VARARGS, NULL},
{(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL},
{(char *) "virNodeGetCPUStats", libvirt_virNodeGetCPUStats, METH_VARARGS, NULL},
{(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL},
{(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL},
{(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册