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 /libvirt-override.c | |
parent | ffcb4a3f7c89f15031e6077ad350bf4fc66d571c (diff) | |
download | libvirt-python-v6-8cebfbb2f5855c970b1c642bcfd1f547b0ef41de.tar.gz libvirt-python-v6-8cebfbb2f5855c970b1c642bcfd1f547b0ef41de.tar.xz libvirt-python-v6-8cebfbb2f5855c970b1c642bcfd1f547b0ef41de.zip |
latency: Expose the new API for Python bindingv0.9.5-rc1
Diffstat (limited to 'libvirt-override.c')
-rw-r--r-- | libvirt-override.c | 85 |
1 files changed, 85 insertions, 0 deletions
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}, |