I have primarily followed the pattern of the 'secret' driver to provide
support for the missing python bindings for the network filter API.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
python/generator.py | 35 ++++++++++-
python/libvirt-override-api.xml | 21 ++++++
python/libvirt-override.c | 124 ++++++++++++++++++++++++++++++++++++++++
python/typewrappers.c | 13 ++++
python/typewrappers.h | 9 ++
5 files changed, 198 insertions(+), 4 deletions(-)
Index: libvirt-acl/python/generator.py
===================================================================
--- libvirt-acl.orig/python/generator.py
+++ libvirt-acl/python/generator.py
@@ -175,7 +175,6 @@ skipped_types = {
'virConnectDomainEventIOErrorCallback': "No function types in
python",
'virConnectDomainEventGraphicsCallback': "No function types in
python",
'virEventAddHandleFunc': "No function types in python",
- 'virNWFilterPtr': "No function types in python",
}
#######################################################################
@@ -237,6 +236,11 @@ py_types = {
'virSecret *': ('O', "virSecret",
"virSecretPtr", "virSecretPtr"),
'const virSecret *': ('O', "virSecret",
"virSecretPtr", "virSecretPtr"),
+ 'virNWFilterPtr': ('O', "virNWFilter",
"virNWFilterPtr", "virNWFilterPtr"),
+ 'const virNWFilterPtr': ('O', "virNWFilter",
"virNWFilterPtr", "virNWFilterPtr"),
+ 'virNWFilter *': ('O', "virNWFilter",
"virNWFilterPtr", "virNWFilterPtr"),
+ 'const virNWFilter *': ('O', "virNWFilter",
"virNWFilterPtr", "virNWFilterPtr"),
+
'virStreamPtr': ('O', "virStream",
"virStreamPtr", "virStreamPtr"),
'const virStreamPtr': ('O', "virStream",
"virStreamPtr", "virStreamPtr"),
'virStream *': ('O', "virStream",
"virStreamPtr", "virStreamPtr"),
@@ -308,6 +312,9 @@ skip_impl = (
'virSecretGetUUID',
'virSecretGetUUIDString',
'virSecretLookupByUUID',
+ 'virNWFilterGetUUID',
+ 'virNWFilterGetUUIDString',
+ 'virNWFilterLookupByUUID',
'virStreamRecv',
'virStreamSend',
'virStoragePoolGetUUID',
@@ -361,6 +368,7 @@ skip_function = (
"virNetworkRef",
"virNodeDeviceRef",
"virSecretRef",
+ "virNWFilterRef",
"virStoragePoolRef",
"virStorageVolRef",
@@ -371,6 +379,7 @@ skip_function = (
"virInterfaceGetConnect",
"virNetworkGetConnect",
"virSecretGetConnect",
+ "virNWFilterGetConnect",
"virStoragePoolGetConnect",
"virStorageVolGetConnect",
)
@@ -643,6 +652,8 @@ classes_type = {
"virNodeDevice *": ("._o", "virNodeDevice(self,
_obj=%s)", "virNodeDevice"),
"virSecretPtr": ("._o", "virSecret(self, _obj=%s)",
"virSecret"),
"virSecret *": ("._o", "virSecret(self, _obj=%s)",
"virSecret"),
+ "virNWFilterPtr": ("._o", "virNWFilter(self, _obj=%s)",
"virNWFilter"),
+ "virNWFilter *": ("._o", "virNWFilter(self, _obj=%s)",
"virNWFilter"),
"virStreamPtr": ("._o", "virStream(self, _obj=%s)",
"virStream"),
"virStream *": ("._o", "virStream(self, _obj=%s)",
"virStream"),
"virConnectPtr": ("._o", "virConnect(_obj=%s)",
"virConnect"),
@@ -657,7 +668,7 @@ converter_type = {
primary_classes = ["virDomain", "virNetwork",
"virInterface",
"virStoragePool", "virStorageVol",
"virConnect", "virNodeDevice",
"virSecret",
- "virStream", "virDomainSnapshot"]
+ "virNWFilter", "virStream",
"virDomainSnapshot"]
classes_ancestor = {
}
@@ -669,6 +680,7 @@ classes_destructors = {
"virStorageVol": "virStorageVolFree",
"virNodeDevice" : "virNodeDeviceFree",
"virSecret": "virSecretFree",
+ "virNWFilter": "virNWFilterFree",
"virDomainSnapshot": "virDomainSnapshotFree",
# We hand-craft __del__ for this one
#"virStream": "virStreamFree",
@@ -691,6 +703,7 @@ functions_noexcept = {
'virNodeDeviceGetParent': True,
'virSecretGetUsageType': True,
'virSecretGetUsageID': True,
+ 'virNWFilterGetName': True,
}
reference_keepers = {
@@ -756,6 +769,12 @@ def nameFixup(name, classe, type, file):
elif name[0:15] == "virSecretLookup":
func = name[3:]
func = string.lower(func[0:1]) + func[1:]
+ elif name[0:17] == "virNWFilterDefine":
+ func = name[3:]
+ func = string.lower(func[0:3]) + func[3:]
+ elif name[0:17] == "virNWFilterLookup":
+ func = name[3:]
+ func = string.lower(func[0:3]) + func[3:]
elif name[0:20] == "virStoragePoolDefine":
func = name[3:]
func = string.lower(func[0:1]) + func[1:]
@@ -813,6 +832,12 @@ def nameFixup(name, classe, type, file):
elif name[0:9] == 'virSecret':
func = name[9:]
func = string.lower(func[0:1]) + func[1:]
+ elif name[0:14] == 'virNWFilterGet':
+ func = name[14:]
+ func = string.lower(func[0:1]) + func[1:]
+ elif name[0:11] == 'virNWFilter':
+ func = name[11:]
+ func = string.lower(func[0:1]) + func[1:]
elif name[0:12] == 'virStreamNew':
func = "newStream"
elif name[0:9] == 'virStream':
@@ -1099,7 +1124,8 @@ def buildWrappers():
else:
classes.write("class %s:\n" % (classname))
if classname in [ "virDomain", "virNetwork",
"virInterface", "virStoragePool",
- "virStorageVol", "virNodeDevice",
"virSecret","virStream" ]:
+ "virStorageVol", "virNodeDevice",
"virSecret","virStream",
+ "virNWFilter" ]:
classes.write(" def __init__(self, conn,
_obj=None):\n")
else:
classes.write(" def __init__(self, _obj=None):\n")
@@ -1108,7 +1134,8 @@ def buildWrappers():
for ref in list:
classes.write(" self.%s = None\n" % ref[1])
if classname in [ "virDomain", "virNetwork",
"virInterface",
- "virNodeDevice", "virSecret",
"virStream" ]:
+ "virNodeDevice", "virSecret",
"virStream",
+ "virNWFilter" ]:
classes.write(" self._conn = conn\n")
elif classname in [ "virStorageVol", "virStoragePool"
]:
classes.write(" self._conn = conn\n" + \
Index: libvirt-acl/python/typewrappers.c
===================================================================
--- libvirt-acl.orig/python/typewrappers.c
+++ libvirt-acl/python/typewrappers.c
@@ -215,6 +215,19 @@ libvirt_virSecretPtrWrap(virSecretPtr no
}
PyObject *
+libvirt_virNWFilterPtrWrap(virNWFilterPtr node)
+{
+ PyObject *ret;
+
+ if (node == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virNWFilterPtr", NULL);
+ return (ret);
+}
+
+PyObject *
libvirt_virStreamPtrWrap(virStreamPtr node)
{
PyObject *ret;
Index: libvirt-acl/python/typewrappers.h
===================================================================
--- libvirt-acl.orig/python/typewrappers.h
+++ libvirt-acl/python/typewrappers.h
@@ -91,6 +91,14 @@ typedef struct {
virSecretPtr obj;
} PyvirSecret_Object;
+#define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
+ (((PyvirNWFilter_Object *)(v))->obj))
+
+typedef struct {
+ PyObject_HEAD
+ virNWFilterPtr obj;
+} PyvirNWFilter_Object;
+
#define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
(((PyvirStream_Object *)(v))->obj))
@@ -163,6 +171,7 @@ PyObject * libvirt_virFreeCallbackWrap(v
PyObject * libvirt_virVoidPtrWrap(void* node);
PyObject * libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node);
PyObject * libvirt_virSecretPtrWrap(virSecretPtr node);
+PyObject * libvirt_virNWFilterPtrWrap(virNWFilterPtr node);
PyObject * libvirt_virStreamPtrWrap(virStreamPtr node);
PyObject * libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node);
Index: libvirt-acl/python/libvirt-override.c
===================================================================
--- libvirt-acl.orig/python/libvirt-override.c
+++ libvirt-acl/python/libvirt-override.c
@@ -1957,6 +1957,126 @@ libvirt_virSecretSetValue(PyObject *self
}
static PyObject *
+libvirt_virNWFilterGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval;
+ unsigned char uuid[VIR_UUID_BUFLEN];
+ virNWFilterPtr nwfilter;
+ PyObject *pyobj_nwfilter;
+ int c_retval;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUID",
&pyobj_nwfilter))
+ return(NULL);
+ nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
+
+ if (nwfilter == NULL)
+ return VIR_PY_NONE;
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virNWFilterGetUUID(nwfilter, &uuid[0]);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (c_retval < 0)
+ return VIR_PY_NONE;
+ py_retval = PyString_FromStringAndSize((char *) &uuid[0], VIR_UUID_BUFLEN);
+
+ return(py_retval);
+}
+
+static PyObject *
+libvirt_virNWFilterGetUUIDString(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ PyObject *py_retval;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+ virNWFilterPtr nwfilter;
+ PyObject *pyobj_nwfilter;
+ int c_retval;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virNWFilterGetUUIDString",
+ &pyobj_nwfilter))
+ return(NULL);
+ nwfilter = (virNWFilterPtr) PyvirNWFilter_Get(pyobj_nwfilter);
+
+ if (nwfilter == NULL)
+ return VIR_PY_NONE;
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virNWFilterGetUUIDString(nwfilter, &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_virNWFilterLookupByUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval;
+ virNWFilterPtr c_retval;
+ virConnectPtr conn;
+ PyObject *pyobj_conn;
+ unsigned char * uuid;
+ int len;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oz#:virNWFilterLookupByUUID",
&pyobj_conn, &uuid, &len))
+ return(NULL);
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ if ((uuid == NULL) || (len != VIR_UUID_BUFLEN))
+ return VIR_PY_NONE;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virNWFilterLookupByUUID(conn, uuid);
+ LIBVIRT_END_ALLOW_THREADS;
+ py_retval = libvirt_virNWFilterPtrWrap((virNWFilterPtr) c_retval);
+ return(py_retval);
+}
+
+
+static PyObject *
+libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args) {
+ PyObject *py_retval;
+ char **uuids = NULL;
+ virConnectPtr conn;
+ int c_retval, i;
+ PyObject *pyobj_conn;
+
+ if (!PyArg_ParseTuple(args, (char *)"O:virConnectListNWFilters",
&pyobj_conn))
+ return NULL;
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectNumOfNWFilters(conn);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0)
+ return VIR_PY_NONE;
+
+ if (c_retval) {
+ uuids = malloc(sizeof(*uuids) * c_retval);
+ if (!uuids)
+ return VIR_PY_NONE;
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectListNWFilters(conn, uuids, c_retval);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0) {
+ free(uuids);
+ return VIR_PY_NONE;
+ }
+ }
+ py_retval = PyList_New(c_retval);
+
+ if (uuids) {
+ for (i = 0;i < c_retval;i++) {
+ PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
+ free(uuids[i]);
+ }
+ free(uuids);
+ }
+
+ return py_retval;
+}
+
+static PyObject *
libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
PyObject *py_retval;
@@ -3316,6 +3436,10 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virConnectListSecrets", libvirt_virConnectListSecrets,
METH_VARARGS, NULL},
{(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS,
NULL},
{(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS,
NULL},
+ {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS,
NULL},
+ {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString,
METH_VARARGS, NULL},
+ {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID,
METH_VARARGS, NULL},
+ {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters,
METH_VARARGS, NULL},
{(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces,
METH_VARARGS, NULL},
{(char *) "virConnectListDefinedInterfaces",
libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
{(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU,
METH_VARARGS, NULL},
Index: libvirt-acl/python/libvirt-override-api.xml
===================================================================
--- libvirt-acl.orig/python/libvirt-override-api.xml
+++ libvirt-acl/python/libvirt-override-api.xml
@@ -226,6 +226,27 @@
<return type='char *' info='the UUID string or None in case of
error'/>
<arg name='secret' type='virSecretPtr' info='a secret
object'/>
</function>
+ <function name='virConnectListNWFilters' file='libvirt'
module='libvirt'>
+ <info>List the defined network filters</info>
+ <arg name='conn' type='virConnectPtr' info='virConnect
connection'/>
+ <return type='str *' info='the list of network filter IDs or None in
case of error'/>
+ </function>
+ <function name='virNWFilterLookupByUUID' file='python'>
+ <info>Try to lookup a network filter on the given hypervisor based on its
UUID.</info>
+ <return type='virNWFilterPtr' info='a new network filter 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 secret, must be 16 bytes'/>
+ </function>
+ <function name='virNWFilterGetUUID' file='python'>
+ <info>Extract the UUID unique Identifier of a network filter.</info>
+ <return type='char *' info='the 16 bytes string or None in case of
error'/>
+ <arg name='nwfilter' type='virNWFilterPtr' info='a network
filter object'/>
+ </function>
+ <function name='virNWFilterGetUUIDString' file='python'>
+ <info>Fetch globally unique ID of the network filter as a
string.</info>
+ <return type='char *' info='the UUID string or None in case of
error'/>
+ <arg name='nwfilter' type='virNWFilterPtr' info='a network
filter object'/>
+ </function>
<function name='virConnectListInterfaces' file='python'>
<info>list the running interfaces, stores the pointers to the names in
@names</info>
<arg name='conn' type='virConnectPtr' info='pointer to the
hypervisor connection'/>