The attached patch fixes a few issues in the python bindings. First, UUIDString has, to my understanding, never worked. It expected to be passed a buffer to fill with the uuid, which through my tests isn't realistically doable from python. I added custom bindings to fix this, and it now works as expected, taking no arguments and returning a string. UUID for a storage pool wasn't being generated with its custom function, so it too was broken. This is also fixed. I also removed some stale entries for virStorageVol UUID functions from generator.py which were probably just carried along from an old version of the storage api patches (storage volumes don't use UUID). Thanks, Cole
diff --git a/python/generator.py b/python/generator.py index 68a7203..1514c02 100755 --- a/python/generator.py +++ b/python/generator.py @@ -291,8 +291,10 @@ skip_impl = ( 'virDomainGetInfo', 'virNodeGetInfo', 'virDomainGetUUID', + 'virDomainGetUUIDString', 'virDomainLookupByUUID', 'virNetworkGetUUID', + 'virNetworkGetUUIDString', 'virNetworkLookupByUUID', 'virDomainGetAutostart', 'virNetworkGetAutostart', @@ -305,9 +307,8 @@ skip_impl = ( 'virDomainGetVcpus', 'virDomainPinVcpu', 'virStoragePoolGetUUID', + 'virStoragePoolGetUUIDString', 'virStoragePoolLookupByUUID', - 'virStorageVolGetUUID', - 'virStorageVolLookupByUUID', 'virStoragePoolGetInfo', 'virStorageVolGetInfo', 'virStoragePoolGetAutostart', diff --git a/python/libvir.c b/python/libvir.c index 8258cc2..9cc0c81 100644 --- a/python/libvir.c +++ b/python/libvir.c @@ -864,6 +864,33 @@ libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { } static PyObject * +libvirt_virDomainGetUUIDString(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) { + PyObject *py_retval; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDomainPtr dom; + PyObject *pyobj_dom; + int c_retval; + + if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetUUIDString", + &pyobj_dom)) + return(NULL); + dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom); + + if (dom == NULL) + return VIR_PY_NONE; + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virDomainGetUUIDString(dom, &uuidstr[0]); + LIBVIRT_END_ALLOW_THREADS; + + if (c_retval < 0) + return VIR_PY_NONE; + + py_retval = PyString_FromString((char *) &uuidstr[0]); + return(py_retval); +} + +static PyObject * libvirt_virDomainLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; virDomainPtr c_retval; @@ -997,6 +1024,33 @@ libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { } static PyObject * +libvirt_virNetworkGetUUIDString(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) { + PyObject *py_retval; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virNetworkPtr net; + PyObject *pyobj_net; + int c_retval; + + if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUIDString", + &pyobj_net)) + return(NULL); + net = (virNetworkPtr) PyvirNetwork_Get(pyobj_net); + + if (net == NULL) + return VIR_PY_NONE; + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virNetworkGetUUIDString(net, &uuidstr[0]); + LIBVIRT_END_ALLOW_THREADS; + + if (c_retval < 0) + return VIR_PY_NONE; + + py_retval = PyString_FromString((char *) &uuidstr[0]); + return(py_retval); +} + +static PyObject * libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; virNetworkPtr c_retval; @@ -1363,6 +1417,31 @@ libvirt_virStoragePoolGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return(py_retval); } +static PyObject * +libvirt_virStoragePoolGetUUIDString(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) { + PyObject *py_retval; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virStoragePoolPtr pool; + PyObject *pyobj_pool; + int c_retval; + + if (!PyArg_ParseTuple(args, (char *)"O:virStoragePoolGetUUIDString", &pyobj_pool)) + return(NULL); + pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool); + + if (pool == NULL) + return VIR_PY_NONE; + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virStoragePoolGetUUIDString(pool, &uuidstr[0]); + LIBVIRT_END_ALLOW_THREADS; + + if (c_retval < 0) + return VIR_PY_NONE; + + py_retval = PyString_FromString((char *) &uuidstr[0]); + return(py_retval); +} static PyObject * libvirt_virStoragePoolLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { @@ -1403,6 +1482,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL}, {(char *) "virNodeGetInfo", libvirt_virNodeGetInfo, METH_VARARGS, NULL}, {(char *) "virDomainGetUUID", libvirt_virDomainGetUUID, METH_VARARGS, NULL}, + {(char *) "virDomainGetUUIDString", libvirt_virDomainGetUUIDString, METH_VARARGS, NULL}, {(char *) "virDomainLookupByUUID", libvirt_virDomainLookupByUUID, METH_VARARGS, NULL}, {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL}, {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL}, @@ -1410,6 +1490,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL}, {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL}, + {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL}, {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL}, {(char *) "virDomainGetAutostart", libvirt_virDomainGetAutostart, METH_VARARGS, NULL}, {(char *) "virNetworkGetAutostart", libvirt_virNetworkGetAutostart, METH_VARARGS, NULL}, @@ -1428,6 +1509,7 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL}, {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL}, {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL}, + {(char *) "virStoragePoolGetUUIDString", libvirt_virStoragePoolGetUUIDString, METH_VARARGS, NULL}, {(char *) "virStoragePoolLookupByUUID", libvirt_virStoragePoolLookupByUUID, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; diff --git a/python/libvirt-python-api.xml b/python/libvirt-python-api.xml index f415c50..da643d7 100644 --- a/python/libvirt-python-api.xml +++ b/python/libvirt-python-api.xml @@ -48,11 +48,31 @@ <return type='char *' info='the 16 bytes string or None in case of error'/> <arg name='domain' type='virDomainPtr' info='a domain object'/> </function> + <function name='virDomainGetUUIDString' file='python'> + <info>Fetch globally unique ID of the domain as a string.</info> + <return type='char *' info='the UUID string or None in case of error'/> + <arg name='pool' type='virDomainPtr' info='a domain object'/> + </function> <function name='virNetworkGetUUID' file='python'> <info>Extract the UUID unique Identifier of a network.</info> <return type='char *' info='the 16 bytes string or None in case of error'/> <arg name='domain' type='virNetworkPtr' info='a network object'/> </function> + <function name='virNetworkGetUUIDString' file='python'> + <info>Fetch globally unique ID of the network as a string.</info> + <return type='char *' info='the UUID string or None in case of error'/> + <arg name='net' type='virNetworkPtr' info='a network object'/> + </function> + <function name='virStoragePoolGetUUID' file='python'> + <info>Extract the UUID unique Identifier of a storage pool.</info> + <return type='char *' info='the 16 bytes string or None in case of error'/> + <arg name='pool' type='virStoragePoolPtr' info='a storage pool object'/> + </function> + <function name='virStoragePoolGetUUIDString' file='python'> + <info>Fetch globally unique ID of the storage pool as a string.</info> + <return type='char *' info='the UUID string or None in case of error'/> + <arg name='pool' type='virStoragePoolPtr' info='a storage pool object'/> + </function> <function name='virNetworkGetAutostart' file='python'> <info>Extract the autostart flag for a network.</info> <return type='int' info='the autostart flag, or None in case of error'/>
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list