summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgenerator.py25
-rw-r--r--libvir.c178
-rw-r--r--libvirt-python-api.xml21
-rw-r--r--libvirt_wrap.h10
-rw-r--r--types.c18
5 files changed, 250 insertions, 2 deletions
diff --git a/generator.py b/generator.py
index c54d25e..50a3bee 100755
--- a/generator.py
+++ b/generator.py
@@ -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":
diff --git a/libvir.c b/libvir.c
index d0e6ee7..0a6faf5 100644
--- a/libvir.c
+++ b/libvir.c
@@ -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(PyObject *self ATTRIBUTE_UNUSED,
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 *self ATTRIBUTE_UNUSED, PyObject *args) {
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}
};
diff --git a/libvirt-python-api.xml b/libvirt-python-api.xml
index 1a658a3..28f0185 100644
--- a/libvirt-python-api.xml
+++ b/libvirt-python-api.xml
@@ -11,12 +11,28 @@
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
<return type='str *' info='the list of Names of None in case of error'/>
</function>
+ <function name='virConnectListNetworks' file='python'>
+ <info>list the networks, stores the pointers to the names in @names</info>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <return type='str *' info='the list of Names of None in case of error'/>
+ </function>
+ <function name='virConnectListDefinedNetworks' file='python'>
+ <info>list the defined networks, stores the pointers to the names in @names</info>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <return type='str *' info='the list of Names of None in case of error'/>
+ </function>
<function name='virDomainLookupByUUID' file='python'>
<info>Try to lookup a domain on the given hypervisor based on its UUID.</info>
<return type='virDomainPtr' info='a new domain object or NULL in case of failure'/>
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
<arg name='uuid' type='const unsigned char *' info='the UUID string for the domain, must be 16 bytes'/>
</function>
+ <function name='virNetworkLookupByUUID' file='python'>
+ <info>Try to lookup a network on the given hypervisor based on its UUID.</info>
+ <return type='virNetworkPtr' info='a new network object or NULL in case of failure'/>
+ <arg name='conn' type='virNetworkPtr' info='pointer to the hypervisor connection'/>
+ <arg name='uuid' type='const unsigned char *' info='the UUID string for the network, must be 16 bytes'/>
+ </function>
<function name='virDomainGetInfo' file='python'>
<info>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.</info>
<return type='int *' info='the list of informations or None in case of error'/>
@@ -32,5 +48,10 @@
<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='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>
</symbols>
</api>
diff --git a/libvirt_wrap.h b/libvirt_wrap.h
index 547dc6d..d7f43c2 100644
--- a/libvirt_wrap.h
+++ b/libvirt_wrap.h
@@ -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(const char *str);
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):
diff --git a/types.c b/types.c
index 4ad4fa5..4672e1c 100644
--- a/types.c
+++ b/types.c
@@ -125,6 +125,24 @@ libvirt_virDomainPtrWrap(virDomainPtr node)
}
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;