? python/libvirt.pyc Index: python/generator.py =================================================================== RCS file: /data/cvs/libvirt/python/generator.py,v retrieving revision 1.15 diff -u -p -r1.15 generator.py --- python/generator.py 14 Feb 2007 17:20:27 -0000 1.15 +++ python/generator.py 9 Mar 2007 01:38:25 -0000 @@ -235,6 +235,10 @@ py_types = { 'const virDomainPtr': ('O', "virDomain", "virDomainPtr", "virDomainPtr"), 'virDomain *': ('O', "virDomain", "virDomainPtr", "virDomainPtr"), 'const virDomain *': ('O', "virDomain", "virDomainPtr", "virDomainPtr"), + 'virNetworkPtr': ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"), + 'const virNetworkPtr': ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"), + 'virNetwork *': ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"), + 'const virNetwork *': ('O', "virNetwork", "virNetworkPtr", "virNetworkPtr"), 'virConnectPtr': ('O', "virConnect", "virConnectPtr", "virConnectPtr"), 'const virConnectPtr': ('O', "virConnect", "virConnectPtr", "virConnectPtr"), 'virConnect *': ('O', "virConnect", "virConnectPtr", "virConnectPtr"), @@ -261,12 +265,16 @@ foreign_encoding_args = ( skip_impl = ( 'virConnectListDomainsID', 'virConnectListDefinedDomains', + 'virConnectListNetworks', + 'virConnectListDefinedNetworks', 'virConnGetLastError', 'virGetLastError', 'virDomainGetInfo', 'virNodeGetInfo', 'virDomainGetUUID', 'virDomainLookupByUUID', + 'virNetworkGetUUID', + 'virNetworkLookupByUUID', ) def skip_function(name): @@ -274,6 +282,8 @@ def skip_function(name): return 1 if name == "virDomainFree": return 1 + if name == "virNetworkFree": + return 1 if name == "vshRunConsole": return 1 return 0 @@ -526,6 +536,8 @@ def buildStubs(): classes_type = { "virDomainPtr": ("._o", "virDomain(_obj=%s)", "virDomain"), "virDomain *": ("._o", "virDomain(_obj=%s)", "virDomain"), + "virNetworkPtr": ("._o", "virNetwork(_obj=%s)", "virNetwork"), + "virNetwork *": ("._o", "virNetwork(_obj=%s)", "virNetwork"), "virConnectPtr": ("._o", "virConnect(_obj=%s)", "virConnect"), "virConnect *": ("._o", "virConnect(_obj=%s)", "virConnect"), } @@ -533,17 +545,19 @@ classes_type = { converter_type = { } -primary_classes = ["virDomain", "virConnect"] +primary_classes = ["virDomain", "virNetwork", "virConnect"] classes_ancestor = { } classes_destructors = { "virDomain": "virDomainFree", + "virNetwork": "virNetworkFree", "virConnect": "virConnectClose", } classes_references = { "virDomain": "virConnect", + "virNetwork": "virConnect", } functions_noexcept = { @@ -558,6 +572,7 @@ function_classes["None"] = [] function_post = { 'virDomainDestroy': "self._o = None", + 'virNetworkDestroy': "self._o = None", } def nameFixup(name, classe, type, file): @@ -573,6 +588,12 @@ def nameFixup(name, classe, type, file): elif name[0:9] == "virDomain": func = name[9:] func = string.lower(func[0:1]) + func[1:] + elif name[0:13] == "virNetworkGet": + func = name[13:] + func = string.lower(func[0:1]) + func[1:] + elif name[0:10] == "virNetwork": + func = name[10:] + func = string.lower(func[0:1]) + func[1:] elif name[0:7] == "virNode": func = name[7:] func = string.lower(func[0:1]) + func[1:] @@ -588,6 +609,8 @@ def nameFixup(name, classe, type, file): func = "ID" if func == "uUID": func = "UUID" + if func == "uUIDString": + func = "UUIDString" if func == "oSType": func = "OSType" if func == "xMLDesc": Index: python/libvir.c =================================================================== RCS file: /data/cvs/libvirt/python/libvir.c,v retrieving revision 1.19 diff -u -p -r1.19 libvir.c --- python/libvir.c 6 Mar 2007 21:55:44 -0000 1.19 +++ python/libvir.c 9 Mar 2007 01:38:25 -0000 @@ -18,6 +18,7 @@ extern void initlibvirtmod(void); PyObject *libvirt_virDomainGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args); +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); @@ -250,7 +251,7 @@ libvirt_virConnectListDefinedDomains(PyO PyObject *pyobj_conn; - if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDomains", &pyobj_conn)) + if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedDomains", &pyobj_conn)) return(NULL); conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); @@ -400,6 +401,176 @@ libvirt_virDomainLookupByUUID(PyObject * return(py_retval); } + +static PyObject * +libvirt_virNetworkFree(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + int c_retval; + virNetworkPtr domain; + PyObject *pyobj_domain; + + if (!PyArg_ParseTuple(args, (char *)"O:virNetworkFree", &pyobj_domain)) + return(NULL); + domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain); + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virNetworkFree(domain); + LIBVIRT_END_ALLOW_THREADS; + py_retval = libvirt_intWrap((int) c_retval); + return(py_retval); +} + + +static PyObject * +libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) { + PyObject *py_retval; + char **names = NULL; + int c_retval, i; + virConnectPtr conn; + PyObject *pyobj_conn; + + + if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNetworks", &pyobj_conn)) + return(NULL); + conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); + + c_retval = virConnectNumOfNetworks(conn); + if (c_retval < 0) { + Py_INCREF(Py_None); + return (Py_None); + } + + if (c_retval) { + names = malloc(sizeof(char *) * c_retval); + if (!names) { + Py_INCREF(Py_None); + return (Py_None); + } + c_retval = virConnectListNetworks(conn, names, c_retval); + if (c_retval < 0) { + free(names); + Py_INCREF(Py_None); + return(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_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) { + PyObject *py_retval; + char **names = NULL; + int c_retval, i; + virConnectPtr conn; + PyObject *pyobj_conn; + + + if (!PyArg_ParseTuple(args, (char *)"O:virConnectListDefinedNetworks", &pyobj_conn)) + return(NULL); + conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); + + c_retval = virConnectNumOfDefinedNetworks(conn); + if (c_retval < 0) { + Py_INCREF(Py_None); + return (Py_None); + } + + if (c_retval) { + names = malloc(sizeof(char *) * c_retval); + if (!names) { + Py_INCREF(Py_None); + return (Py_None); + } + c_retval = virConnectListDefinedNetworks(conn, names, c_retval); + if (c_retval < 0) { + free(names); + Py_INCREF(Py_None); + return(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); +} + + +PyObject * +libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + unsigned char uuid[VIR_UUID_BUFLEN]; + virNetworkPtr domain; + PyObject *pyobj_domain; + int c_retval; + + if (!PyArg_ParseTuple(args, (char *)"O:virNetworkGetUUID", &pyobj_domain)) + return(NULL); + domain = (virNetworkPtr) PyvirNetwork_Get(pyobj_domain); + + if (domain == NULL) { + Py_INCREF(Py_None); + return(Py_None); + } + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virNetworkGetUUID(domain, &uuid[0]); + LIBVIRT_END_ALLOW_THREADS; + + if (c_retval < 0) { + Py_INCREF(Py_None); + return(Py_None); + } + py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN); + + return(py_retval); +} + +static PyObject * +libvirt_virNetworkLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval; + virNetworkPtr c_retval; + virConnectPtr conn; + PyObject *pyobj_conn; + unsigned char * uuid; + int len; + + if (!PyArg_ParseTuple(args, (char *)"Oz#:virNetworkLookupByUUID", &pyobj_conn, &uuid, &len)) + return(NULL); + conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); + + if ((uuid == NULL) || (len != VIR_UUID_BUFLEN)) { + Py_INCREF(Py_None); + return(Py_None); + } + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virNetworkLookupByUUID(conn, uuid); + LIBVIRT_END_ALLOW_THREADS; + py_retval = libvirt_virNetworkPtrWrap((virNetworkPtr) c_retval); + return(py_retval); +} + + + /************************************************************************ * * * The registration stuff * @@ -418,6 +589,11 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virRegisterErrorHandler", libvirt_virRegisterErrorHandler, METH_VARARGS, NULL}, {(char *) "virGetLastError", libvirt_virGetLastError, METH_VARARGS, NULL}, {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL}, + {(char *) "virNetworkFree", libvirt_virNetworkFree, METH_VARARGS, NULL}, + {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL}, + {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL}, + {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL}, + {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; Index: python/libvirt-python-api.xml =================================================================== RCS file: /data/cvs/libvirt/python/libvirt-python-api.xml,v retrieving revision 1.5 diff -u -p -r1.5 libvirt-python-api.xml --- python/libvirt-python-api.xml 16 Nov 2006 00:17:10 -0000 1.5 +++ python/libvirt-python-api.xml 9 Mar 2007 01:38:25 -0000 @@ -11,12 +11,28 @@ + + list the networks, stores the pointers to the names in @names + + + + + list the defined networks, stores the pointers to the names in @names + + + Try to lookup a domain on the given hypervisor based on its UUID. + + Try to lookup a network on the given hypervisor based on its UUID. + + + + Extract informations about a domain. Note that if the connection used to get the domain is limited only a partial set of the informations can be extracted. @@ -32,5 +48,10 @@ + + Extract the UUID unique Identifier of a network. + + + Index: python/libvirt_wrap.h =================================================================== RCS file: /data/cvs/libvirt/python/libvirt_wrap.h,v retrieving revision 1.6 diff -u -p -r1.6 libvirt_wrap.h --- python/libvirt_wrap.h 6 Mar 2007 21:55:44 -0000 1.6 +++ python/libvirt_wrap.h 9 Mar 2007 01:38:25 -0000 @@ -39,6 +39,15 @@ typedef struct { } PyvirDomain_Object; +#define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \ + (((PyvirNetwork_Object *)(v))->obj)) + +typedef struct { + PyObject_HEAD + virNetworkPtr obj; +} PyvirNetwork_Object; + + PyObject * libvirt_intWrap(int val); PyObject * libvirt_longWrap(long val); PyObject * libvirt_ulongWrap(unsigned long val); @@ -48,6 +57,7 @@ PyObject * libvirt_constcharPtrWrap(cons PyObject * libvirt_charPtrConstWrap(const char *str); PyObject * libvirt_virConnectPtrWrap(virConnectPtr node); PyObject * libvirt_virDomainPtrWrap(virDomainPtr node); +PyObject * libvirt_virNetworkPtrWrap(virNetworkPtr node); /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl): Index: python/types.c =================================================================== RCS file: /data/cvs/libvirt/python/types.c,v retrieving revision 1.4 diff -u -p -r1.4 types.c --- python/types.c 15 Nov 2006 19:40:00 -0000 1.4 +++ python/types.c 9 Mar 2007 01:38:25 -0000 @@ -125,6 +125,24 @@ libvirt_virDomainPtrWrap(virDomainPtr no } PyObject * +libvirt_virNetworkPtrWrap(virNetworkPtr node) +{ + PyObject *ret; + +#ifdef DEBUG + printf("libvirt_virNetworkPtrWrap: node = %p\n", node); +#endif + if (node == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + ret = + PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNetworkPtr", + NULL); + return (ret); +} + +PyObject * libvirt_virConnectPtrWrap(virConnectPtr node) { PyObject *ret;