[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 7/8] latency: Expose the new API for Python binding



On Mon, Sep 05, 2011 at 04:38:34PM +0800, Osier Yang wrote:
> ---
>  python/generator.py             |    1 +
>  python/libvirt-override-api.xml |    7 +++
>  python/libvirt-override.c       |   85 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 93 insertions(+), 0 deletions(-)
> 
> diff --git a/python/generator.py b/python/generator.py
> index cc253cf..d17fb26 100755
> --- a/python/generator.py
> +++ b/python/generator.py
> @@ -373,6 +373,7 @@ skip_impl = (
>      'virNodeGetMemoryStats',
>      'virDomainGetBlockJobInfo',
>      'virDomainMigrateGetMaxSpeed',
> +    'virDomainBlockStatsFlags',
>  )
>  
>  
> diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
> index 1cf115c..3013e46 100644
> --- a/python/libvirt-override-api.xml
> +++ b/python/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/python/libvirt-override.c b/python/libvirt-override.c
> index b020342..d65423d 100644
> --- a/python/libvirt-override.c
> +++ b/python/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},

  ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]