python: make python APIs use these helper functions
*setPyVirTypedParameter *libvirt_virDomainGetCPUStats
This commit is contained in:
parent
384ebd3fc5
commit
1aeb3d9e7f
@ -151,11 +151,11 @@
|
|||||||
</function>
|
</function>
|
||||||
<function name='virDomainGetCPUStats' file='python'>
|
<function name='virDomainGetCPUStats' file='python'>
|
||||||
<info>Extracts CPU statistics for a running domain. On success it will
|
<info>Extracts CPU statistics for a running domain. On success it will
|
||||||
return a list of data of dictionary type. If boolean total is False, the
|
return a list of data of dictionary type. If boolean total is False or 0, the
|
||||||
first element of the list refers to CPU0 on the host, second element is
|
first element of the list refers to CPU0 on the host, second element is
|
||||||
CPU1, and so on. The format of data struct is as follows:
|
CPU1, and so on. The format of data struct is as follows:
|
||||||
[{cpu_time:xxx}, {cpu_time:xxx}, ...]
|
[{cpu_time:xxx}, {cpu_time:xxx}, ...]
|
||||||
If it is True, it returns total domain CPU statistics in the format of
|
If it is True or 1, it returns total domain CPU statistics in the format of
|
||||||
[{cpu_time:xxx, user_time:xxx, system_time:xxx}]</info>
|
[{cpu_time:xxx, user_time:xxx, system_time:xxx}]</info>
|
||||||
<return type='str *' info='returns a list of dictionary in case of success, None in case of error'/>
|
<return type='str *' info='returns a list of dictionary in case of success, None in case of error'/>
|
||||||
<arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
|
<arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
|
||||||
|
@ -194,76 +194,38 @@ setPyVirTypedParameter(PyObject *info,
|
|||||||
|
|
||||||
switch(params[i].type) {
|
switch(params[i].type) {
|
||||||
case VIR_TYPED_PARAM_INT:
|
case VIR_TYPED_PARAM_INT:
|
||||||
{
|
if (libvirt_intUnwrap(value, &temp->value.i) < 0)
|
||||||
long long_val = PyInt_AsLong(value);
|
|
||||||
if ((long_val == -1) && PyErr_Occurred())
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if ((int)long_val == long_val) {
|
break;
|
||||||
temp->value.i = long_val;
|
|
||||||
} else {
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
|
||||||
"The value of "
|
|
||||||
"attribute \"%s\" is out of int range", keystr);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VIR_TYPED_PARAM_UINT:
|
case VIR_TYPED_PARAM_UINT:
|
||||||
{
|
if (libvirt_uintUnwrap(value, &temp->value.ui) < 0)
|
||||||
long long_val = PyInt_AsLong(value);
|
|
||||||
if ((long_val == -1) && PyErr_Occurred())
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if ((unsigned int)long_val == long_val) {
|
break;
|
||||||
temp->value.ui = long_val;
|
|
||||||
} else {
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
|
||||||
"The value of "
|
|
||||||
"attribute \"%s\" is out of int range", keystr);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VIR_TYPED_PARAM_LLONG:
|
case VIR_TYPED_PARAM_LLONG:
|
||||||
{
|
if (libvirt_longlongUnwrap(value, &temp->value.l) < 0)
|
||||||
long long llong_val = PyLong_AsLongLong(value);
|
|
||||||
if ((llong_val == -1) && PyErr_Occurred())
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
temp->value.l = llong_val;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VIR_TYPED_PARAM_ULLONG:
|
case VIR_TYPED_PARAM_ULLONG:
|
||||||
{
|
if (libvirt_ulonglongUnwrap(value, &temp->value.ul) < 0)
|
||||||
unsigned long long ullong_val = PyLong_AsUnsignedLongLong(value);
|
|
||||||
if ((ullong_val == -1) && PyErr_Occurred())
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
temp->value.ul = ullong_val;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VIR_TYPED_PARAM_DOUBLE:
|
case VIR_TYPED_PARAM_DOUBLE:
|
||||||
{
|
if (libvirt_doubleUnwrap(value, &temp->value.d) < 0)
|
||||||
double double_val = PyFloat_AsDouble(value);
|
|
||||||
if ((double_val == -1) && PyErr_Occurred())
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
temp->value.d = double_val;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VIR_TYPED_PARAM_BOOLEAN:
|
case VIR_TYPED_PARAM_BOOLEAN:
|
||||||
{
|
{
|
||||||
/* Hack - Python's definition of Py_True breaks strict
|
bool b;
|
||||||
* aliasing rules, so can't directly compare
|
if (libvirt_boolUnwrap(value, &b) < 0)
|
||||||
*/
|
|
||||||
if (PyBool_Check(value)) {
|
|
||||||
PyObject *hacktrue = PyBool_FromLong(1);
|
|
||||||
temp->value.b = hacktrue == value ? 1 : 0;
|
|
||||||
Py_DECREF(hacktrue);
|
|
||||||
} else {
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
|
||||||
"The value type of "
|
|
||||||
"attribute \"%s\" must be bool", keystr);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
temp->value.b = b;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case VIR_TYPED_PARAM_STRING:
|
case VIR_TYPED_PARAM_STRING:
|
||||||
{
|
{
|
||||||
char *string_val = PyString_AsString(value);
|
char *string_val = PyString_AsString(value);
|
||||||
@ -388,7 +350,8 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
|
|||||||
int ncpus = -1, start_cpu = 0;
|
int ncpus = -1, start_cpu = 0;
|
||||||
int sumparams = 0, nparams = -1;
|
int sumparams = 0, nparams = -1;
|
||||||
int i, i_retval;
|
int i, i_retval;
|
||||||
unsigned int flags, totalflag;
|
unsigned int flags;
|
||||||
|
bool totalflag;
|
||||||
virTypedParameterPtr params = NULL, cpuparams;
|
virTypedParameterPtr params = NULL, cpuparams;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainGetCPUStats",
|
if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainGetCPUStats",
|
||||||
@ -396,18 +359,8 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
|
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
|
||||||
|
|
||||||
if (!PyBool_Check(totalbool)) {
|
if (libvirt_boolUnwrap(totalbool, &totalflag) < 0)
|
||||||
PyErr_Format(PyExc_TypeError,
|
|
||||||
"The \"total\" attribute must be bool");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
|
||||||
/* Hack - Python's definition of Py_True breaks strict
|
|
||||||
* aliasing rules, so can't directly compare
|
|
||||||
*/
|
|
||||||
PyObject *hacktrue = PyBool_FromLong(1);
|
|
||||||
totalflag = hacktrue == totalbool ? 1 : 0;
|
|
||||||
Py_DECREF(hacktrue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ret = PyList_New(0)) == NULL)
|
if ((ret = PyList_New(0)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user