[libvirt] [PATCH] Fixup python binding for virDomainSnapshot APIs

Daniel Veillard veillard at redhat.com
Wed Apr 14 14:36:47 UTC 2010


On Wed, Apr 14, 2010 at 03:03:45PM +0100, Daniel P. Berrange wrote:
> The generator code was totally wrong for the virDomainSnapshot
> APIs, not generating the wrapper class, and giving methods the
> wrong names
> 
> * generator.py: Set metadata for virDomainSnapshot type & APIs
> * libvirt-override-api.xml, libvirt-override.c: Hand-code the
>   virDomainSnapshotListNames glue layer
> ---
>  python/generator.py             |   27 ++++++++++++++++++++++-
>  python/libvirt-override-api.xml |    6 +++++
>  python/libvirt-override.c       |   46 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 78 insertions(+), 1 deletions(-)
> 
> diff --git a/python/generator.py b/python/generator.py
> index cb9f3d9..6f082e8 100755
> --- a/python/generator.py
> +++ b/python/generator.py
> @@ -243,6 +243,9 @@ py_types = {
>      'const virStream *':  ('O', "virStream", "virStreamPtr", "virStreamPtr"),
>  
>      'virDomainSnapshotPtr':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
> +    'const virDomainSnapshotPtr':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
> +    'virDomainSnapshot *':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
> +    'const virDomainSnapshot *':  ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
>  }
>  
>  py_return_types = {
> @@ -277,6 +280,7 @@ skip_impl = (
>      'virConnectListDefinedStorageVols',
>      'virConnectListDefinedInterfaces',
>      'virConnectListNWFilters',
> +    'virDomainSnapshotListNames',
>      'virConnGetLastError',
>      'virGetLastError',
>      'virDomainGetInfo',
> @@ -643,6 +647,8 @@ classes_type = {
>      "virStream *": ("._o", "virStream(self, _obj=%s)", "virStream"),
>      "virConnectPtr": ("._o", "virConnect(_obj=%s)", "virConnect"),
>      "virConnect *": ("._o", "virConnect(_obj=%s)", "virConnect"),
> +    "virDomainSnapshotPtr": ("._o", "virDomainSnapshot(self,_obj=%s)", "virDomainSnapshot"),
> +    "virDomainSnapshot *": ("._o", "virDomainSnapshot(self, _obj=%s)", "virDomainSnapshot"),
>  }
>  
>  converter_type = {
> @@ -651,7 +657,7 @@ converter_type = {
>  primary_classes = ["virDomain", "virNetwork", "virInterface",
>                     "virStoragePool", "virStorageVol",
>                     "virConnect", "virNodeDevice", "virSecret",
> -                   "virStream"]
> +                   "virStream", "virDomainSnapshot"]
>  
>  classes_ancestor = {
>  }
> @@ -663,6 +669,7 @@ classes_destructors = {
>      "virStorageVol": "virStorageVolFree",
>      "virNodeDevice" : "virNodeDeviceFree",
>      "virSecret": "virSecretFree",
> +    "virDomainSnapshot": "virDomainSnapshotFree",
>      # We hand-craft __del__ for this one
>      #"virStream": "virStreamFree",
>  }
> @@ -767,6 +774,24 @@ def nameFixup(name, classe, type, file):
>      elif name[0:12] == "virDomainGet":
>          func = name[12:]
>          func = string.lower(func[0:1]) + func[1:]
> +    elif name[0:29] == "virDomainSnapshotLookupByName":
> +        func = name[9:]
> +        func = string.lower(func[0:1]) + func[1:]
> +    elif name[0:26] == "virDomainSnapshotListNames":
> +        func = name[9:]
> +        func = string.lower(func[0:1]) + func[1:]
> +    elif name[0:20] == "virDomainSnapshotNum":
> +        func = name[9:]
> +        func = string.lower(func[0:1]) + func[1:]
> +    elif name[0:26] == "virDomainSnapshotCreateXML":
> +        func = name[9:]
> +        func = string.lower(func[0:1]) + func[1:]
> +    elif name[0:24] == "virDomainSnapshotCurrent":
> +        func = name[9:]
> +        func = string.lower(func[0:1]) + func[1:]
> +    elif name[0:17] == "virDomainSnapshot":
> +        func = name[17:]
> +        func = string.lower(func[0:1]) + func[1:]
>      elif name[0:9] == "virDomain":
>          func = name[9:]
>          func = string.lower(func[0:1]) + func[1:]
> diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
> index e95c46a..6f1bc04 100644
> --- a/python/libvirt-override-api.xml
> +++ b/python/libvirt-override-api.xml
> @@ -243,5 +243,11 @@
>        <arg name='xmlCPUs' type='const char **' info='array of XML descriptions of host CPUs'/>
>        <arg name='flags' type='unsigned int' info='fine-tuning flags, currently unused, pass 0.'/>
>      </function>
> +    <function name='virDomainSnapshotListNames' file='python'>
> +      <info>collect the list of snapshots for the given domain</info>
> +      <arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
> +      <arg name='flags' type='unsigned int' info='flags, curently unused'/>
> +      <return type='str *' info='the list of Names of None in case of error'/>
> +    </function>
>    </symbols>
>  </api>
> diff --git a/python/libvirt-override.c b/python/libvirt-override.c
> index 02bc313..ce21f60 100644
> --- a/python/libvirt-override.c
> +++ b/python/libvirt-override.c
> @@ -943,6 +943,51 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
>  }
>  
>  static PyObject *
> +libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
> +                                   PyObject *args) {
> +    PyObject *py_retval;
> +    char **names = NULL;
> +    int c_retval, i;
> +    virDomainPtr dom;
> +    PyObject *pyobj_dom;
> +    int flags;
> +
> +    if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainSnapshotListNames", &pyobj_dom, &flags))
> +        return(NULL);
> +    dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    c_retval = virDomainSnapshotNum(dom, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +    if (c_retval < 0)
> +        return VIR_PY_NONE;
> +
> +    if (c_retval) {
> +        names = malloc(sizeof(*names) * c_retval);
> +        if (!names)
> +            return VIR_PY_NONE;
> +        LIBVIRT_BEGIN_ALLOW_THREADS;
> +        c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags);
> +        LIBVIRT_END_ALLOW_THREADS;
> +        if (c_retval < 0) {
> +            free(names);
> +            return VIR_PY_NONE;
> +        }
> +    }
> +    py_retval = PyList_New(c_retval);
> +
> +    if (names) {
> +        for (i = 0;i < c_retval;i++) {
> +            PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
> +            free(names[i]);
> +        }
> +        free(names);
> +    }
> +
> +    return(py_retval);
> +}
> +
> +static PyObject *
>  libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
>      PyObject *py_retval;
>      int c_retval;
> @@ -3275,6 +3320,7 @@ static PyMethodDef libvirtMethods[] = {
>      {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
>      {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
>      {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
> +    {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
>      {NULL, NULL, 0, NULL}
>  };
>  

  Arghh ... the first brown paper bag bug of 0.8.0, but that was to be
  expected !

Looks fine,

ACK,

Daniel

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




More information about the libvir-list mailing list