From 795d9200283ab5a33d0005794c3bb77e96231f6e Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 30 Sep 2007 20:52:13 +0000 Subject: [PATCH] * python/generator.py python/libvir.c python/libvirt-python-api.xml: provide bindings for block and interface statistics Daniel --- ChangeLog | 5 +++ python/generator.py | 2 + python/libvir.c | 71 +++++++++++++++++++++++++++++++++++ python/libvirt-python-api.xml | 12 ++++++ 4 files changed, 90 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3ce29ce851..389aa9328e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Sep 30 22:51:11 CEST 2007 Daniel Veillard + + * python/generator.py python/libvir.c python/libvirt-python-api.xml: + provide bindings for block and interface statistics + Sun Sep 30 12:27:36 EST 2007 Daniel P. Berrange * src/xend_internal.c: Don't include for HVM guests diff --git a/python/generator.py b/python/generator.py index 3dc321234d..bf384e1c18 100755 --- a/python/generator.py +++ b/python/generator.py @@ -276,6 +276,8 @@ skip_impl = ( 'virDomainLookupByUUID', 'virNetworkGetUUID', 'virNetworkLookupByUUID', + 'virDomainBlockStats', + 'virDomainInterfaceStats', ) def skip_function(name): diff --git a/python/libvir.c b/python/libvir.c index f1281f19db..0621eb2a91 100644 --- a/python/libvir.c +++ b/python/libvir.c @@ -21,8 +21,77 @@ PyObject *libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *ar PyObject *libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args); PyObject *libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args); PyObject *libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args); +PyObject * libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args); +PyObject * libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args); +/************************************************************************ + * * + * Statistics * + * * + ************************************************************************/ + +PyObject * +libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + virDomainPtr domain; + PyObject *pyobj_domain; + char * path; + int c_retval; + virDomainBlockStatsStruct stats; + PyObject *info; + + if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainBlockStats", + &pyobj_domain,&path)) + return(NULL); + domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); + + c_retval = virDomainBlockStats(domain, path, &stats, sizeof(stats)); + if (c_retval < 0) { + Py_INCREF(Py_None); + return(Py_None); + } + /* convert to a Python tupple of long objects */ + info = PyTuple_New(5); + PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rd_req)); + PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rd_bytes)); + PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.wr_req)); + PyTuple_SetItem(info, 3, PyLong_FromLongLong(stats.wr_bytes)); + PyTuple_SetItem(info, 4, PyLong_FromLongLong(stats.errs)); + return(info); +} + +PyObject * +libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + virDomainPtr domain; + PyObject *pyobj_domain; + char * path; + int c_retval; + virDomainInterfaceStatsStruct stats; + PyObject *info; + + if (!PyArg_ParseTuple(args, (char *)"Oz:virDomainInterfaceStats", + &pyobj_domain,&path)) + return(NULL); + domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); + + c_retval = virDomainInterfaceStats(domain, path, &stats, sizeof(stats)); + if (c_retval < 0) { + Py_INCREF(Py_None); + return(Py_None); + } + + /* convert to a Python tupple of long objects */ + info = PyTuple_New(8); + PyTuple_SetItem(info, 0, PyLong_FromLongLong(stats.rx_bytes)); + PyTuple_SetItem(info, 1, PyLong_FromLongLong(stats.rx_packets)); + PyTuple_SetItem(info, 2, PyLong_FromLongLong(stats.rx_errs)); + PyTuple_SetItem(info, 3, PyLong_FromLongLong(stats.rx_drop)); + PyTuple_SetItem(info, 4, PyLong_FromLongLong(stats.tx_bytes)); + PyTuple_SetItem(info, 5, PyLong_FromLongLong(stats.tx_packets)); + PyTuple_SetItem(info, 6, PyLong_FromLongLong(stats.tx_errs)); + PyTuple_SetItem(info, 7, PyLong_FromLongLong(stats.tx_drop)); + return(info); +} /************************************************************************ * * * Global error handler at the Python level * @@ -677,6 +746,8 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL}, {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL}, {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL}, + {(char *) "virDomainBlockStats", libvirt_virDomainBlockStats, METH_VARARGS, NULL}, + {(char *) "virDomainInterfaceStats", libvirt_virDomainInterfaceStats, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; diff --git a/python/libvirt-python-api.xml b/python/libvirt-python-api.xml index 40cac6dc13..b6154e75ab 100644 --- a/python/libvirt-python-api.xml +++ b/python/libvirt-python-api.xml @@ -63,5 +63,17 @@ + + Extracts block device statistics for a domain + + + + + + Extracts interface device statistics for a domain + + + + -- GitLab