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

Re: [libvirt] [PATCH 6/6] node_memory: Expose the APIs to Python bindings



On Fri, Sep 14, 2012 at 02:42:20PM +0800, Osier Yang wrote:
> * python/libvirt-override-api.xml: (Add document to describe
>   the APIs).
> * python/libvirt-override.c: (Implement the API wrappers manually)
> ---
>  python/libvirt-override-api.xml |   13 ++++
>  python/libvirt-override.c       |  125 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 138 insertions(+), 0 deletions(-)
> 
> diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
> index ab6f407..abc0b81 100644
> --- a/python/libvirt-override-api.xml
> +++ b/python/libvirt-override-api.xml
> @@ -511,5 +511,18 @@
>        <arg name='domain' type='virDomainPtr' info='a domain object'/>
>        <arg name='flags' type='unsigned int' info='unused, always pass 0'/>
>      </function>
> +    <function name='virNodeSetMemoryParameters' file='python'>
> +      <info>Change the node memory tunables</info>
> +      <return type='int' info='-1 in case of error, 0 in case of success.'/>
> +      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
> +      <arg name='params' type='virTypedParameterPtr' info='pointer to the memory tunable objects'/>
> +      <arg name='flags'  type='int' info='unused, always pass 0'/>
> +    </function>
> +    <function name='virNodeGetMemoryParameters' file='python'>
> +      <info>Get the node memory parameters</info>
> +      <return type='str *' info='None in case of error, returns a dictionary of params'/>
> +      <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
> +      <arg name='flags' type='int' info='unused, always pass 0'/>
> +    </function>
>    </symbols>
>  </api>
> diff --git a/python/libvirt-override.c b/python/libvirt-override.c
> index d07e7cb..ca32f80 100644
> --- a/python/libvirt-override.c
> +++ b/python/libvirt-override.c
> @@ -6005,6 +6005,129 @@ cleanup:
>      return py_retval;
>  }
>  
> +static PyObject *
> +libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
> +                                   PyObject *args)
> +{
> +    virConnectPtr conn;
> +    PyObject *pyobj_conn, *info;
> +    PyObject *ret = NULL;
> +    int i_retval;
> +    int nparams = 0;
> +    Py_ssize_t size = 0;
> +    unsigned int flags;
> +    virTypedParameterPtr params, new_params;
> +
> +    if (!PyArg_ParseTuple(args,
> +                          (char *)"OOi:virNodeSetMemoryParameters",
> +                          &pyobj_conn, &info, &flags))
> +        return NULL;
> +    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
> +
> +    if ((size = PyDict_Size(info)) < 0)
> +        return NULL;
> +
> +    if (size == 0) {
> +        PyErr_Format(PyExc_LookupError,
> +                     "Need non-empty dictionary to set attributes");
> +        return NULL;
> +    }
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +
> +    if (i_retval < 0)
> +        return VIR_PY_INT_FAIL;
> +
> +    if (nparams == 0) {
> +        PyErr_Format(PyExc_LookupError,
> +                     "no settable attributes");
> +        return NULL;
> +    }
> +
> +    if (VIR_ALLOC_N(params, nparams) < 0)
> +        return PyErr_NoMemory();
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +
> +    if (i_retval < 0) {
> +        ret = VIR_PY_INT_FAIL;
> +        goto cleanup;
> +    }
> +
> +    new_params = setPyVirTypedParameter(info, params, nparams);
> +    if (!new_params)
> +        goto cleanup;
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    i_retval = virNodeSetMemoryParameters(conn, new_params, size, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +
> +    if (i_retval < 0) {
> +        ret = VIR_PY_INT_FAIL;
> +        goto cleanup;
> +    }
> +
> +    ret = VIR_PY_INT_SUCCESS;
> +
> +cleanup:
> +    virTypedParameterArrayClear(params, nparams);
> +    VIR_FREE(params);
> +    VIR_FREE(new_params);
> +    return ret;
> +}
> +
> +static PyObject *
> +libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
> +                                   PyObject *args)
> +{
> +    virConnectPtr conn;
> +    PyObject *pyobj_conn;
> +    PyObject *ret = NULL;
> +    int i_retval;
> +    int nparams = 0;
> +    unsigned int flags;
> +    virTypedParameterPtr params;
> +
> +    if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetMemoryParameters",
> +                          &pyobj_conn, &flags))
> +        return NULL;
> +    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    i_retval = virNodeGetMemoryParameters(conn, NULL, &nparams, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +
> +    if (i_retval < 0)
> +        return VIR_PY_NONE;
> +
> +    if (!nparams)
> +        return PyDict_New();
> +
> +    if (VIR_ALLOC_N(params, nparams) < 0)
> +        return PyErr_NoMemory();
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    i_retval = virNodeGetMemoryParameters(conn, params, &nparams, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +
> +    if (i_retval < 0) {
> +        ret = VIR_PY_NONE;
> +        goto cleanup;
> +    }
> +
> +    ret = getPyVirTypedParameter(params, nparams);
> +
> +cleanup:
> +    virTypedParameterArrayClear(params, nparams);
> +    VIR_FREE(params);
> +    return ret;
> +}
> +
> +
>  /************************************************************************
>   *									*
>   *			The registration stuff				*
> @@ -6116,6 +6239,8 @@ static PyMethodDef libvirtMethods[] = {
>      {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL},
>      {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL},
>      {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
> +    {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
> +    {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
>      {NULL, NULL, 0, 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]