diff options
author | Osier Yang <jyang@redhat.com> | 2011-09-05 16:24:21 +0800 |
---|---|---|
committer | Osier Yang <jyang@redhat.com> | 2011-09-06 12:02:51 +0800 |
commit | 8cebfbb2f5855c970b1c642bcfd1f547b0ef41de (patch) | |
tree | 76cbefebd24cf99e0190062533c0108041b95afc | |
parent | ffcb4a3f7c89f15031e6077ad350bf4fc66d571c (diff) | |
download | libvirt-python-8cebfbb2f5855c970b1c642bcfd1f547b0ef41de.tar.gz |
latency: Expose the new API for Python bindingv0.9.5-rc1
-rwxr-xr-x | generator.py | 1 | ||||
-rw-r--r-- | libvirt-override-api.xml | 7 | ||||
-rw-r--r-- | libvirt-override.c | 85 |
3 files changed, 93 insertions, 0 deletions
diff --git a/generator.py b/generator.py index cc253cf..d17fb26 100755 --- a/generator.py +++ b/generator.py @@ -373,6 +373,7 @@ skip_impl = ( 'virNodeGetMemoryStats', 'virDomainGetBlockJobInfo', 'virDomainMigrateGetMaxSpeed', + 'virDomainBlockStatsFlags', ) diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml index 1cf115c..3013e46 100644 --- a/libvirt-override-api.xml +++ b/libvirt-override-api.xml @@ -128,6 +128,13 @@ <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='path' type='char *' info='the path for the block device'/> </function> + <function name='virDomainBlockStatsFlags' file='python'> + <info>Extracts block device statistics parameters of a running domain</info> + <return type='virTypedParameterPtr' info='None in case of error, returns a dictionary of params'/> + <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> + <arg name='path' type='char *' info='the path for the block device'/> + <arg name='flags' type='int' info='flags (unused; pass 0)'/> + </function> <function name='virDomainInterfaceStats' file='python'> <info>Extracts interface device statistics for a domain</info> <return type='virDomainInterfaceStats' info='a tuple of statistics'/> diff --git a/libvirt-override.c b/libvirt-override.c index b020342..d65423d 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -100,6 +100,90 @@ libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { } static PyObject * +libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) { + virDomainPtr domain; + PyObject *pyobj_domain, *info; + int i_retval; + int nparams = 0, i; + unsigned int flags; + virTypedParameterPtr params; + const char *path; + + if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainBlockStatsFlags", + &pyobj_domain, &path, &flags)) + return(NULL); + domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); + + LIBVIRT_BEGIN_ALLOW_THREADS; + i_retval = virDomainBlockStatsFlags(domain, path, NULL, &nparams, flags); + LIBVIRT_END_ALLOW_THREADS; + + if (i_retval < 0) + return VIR_PY_NONE; + + if ((params = malloc(sizeof(*params)*nparams)) == NULL) + return VIR_PY_NONE; + + LIBVIRT_BEGIN_ALLOW_THREADS; + i_retval = virDomainBlockStatsFlags(domain, path, params, &nparams, flags); + LIBVIRT_END_ALLOW_THREADS; + + if (i_retval < 0) { + free(params); + return VIR_PY_NONE; + } + + /* convert to a Python tuple of long objects */ + if ((info = PyDict_New()) == NULL) { + free(params); + return VIR_PY_NONE; + } + + for (i = 0 ; i < nparams ; i++) { + PyObject *key, *val; + + switch (params[i].type) { + case VIR_TYPED_PARAM_INT: + val = PyInt_FromLong((long)params[i].value.i); + break; + + case VIR_TYPED_PARAM_UINT: + val = PyInt_FromLong((long)params[i].value.ui); + break; + + case VIR_TYPED_PARAM_LLONG: + val = PyLong_FromLongLong((long long)params[i].value.l); + break; + + case VIR_TYPED_PARAM_ULLONG: + val = PyLong_FromLongLong((long long)params[i].value.ul); + break; + + case VIR_TYPED_PARAM_DOUBLE: + val = PyFloat_FromDouble((double)params[i].value.d); + break; + + case VIR_TYPED_PARAM_BOOLEAN: + val = PyBool_FromLong((long)params[i].value.b); + break; + + default: + free(params); + Py_DECREF(info); + return VIR_PY_NONE; + } + + key = libvirt_constcharPtrWrap(params[i].field); + PyDict_SetItem(info, key, val); + } + + free(params); + return(info); +} + + +static PyObject * libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { virDomainPtr domain; PyObject *pyobj_domain; @@ -4605,6 +4689,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL}, {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL}, {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL}, + {(char *) "virDomainBlockStatsFlags", libvirt_virDomainBlockStatsFlags, METH_VARARGS, NULL}, {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL}, {(char *) "virDomainMemoryStats", libvirt_virDomainMemoryStats, METH_VARARGS, NULL}, {(char *) "virNodeGetCellsFreeMemory", libvirt_virNodeGetCellsFreeMemory, METH_VARARGS, NULL}, |