Define the various rules in the generator to wire up methods into the
virNetwork class and create the new virNetworkPort class.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
generator.py | 25 +++++++++-
libvirt-override-api.xml | 13 ++++++
libvirt-override.c | 99 ++++++++++++++++++++++++++++++++++++++++
typewrappers.c | 13 ++++++
typewrappers.h | 10 ++++
5 files changed, 158 insertions(+), 2 deletions(-)
diff --git a/generator.py b/generator.py
index ffa3ce5..ab5144d 100755
--- a/generator.py
+++ b/generator.py
@@ -328,6 +328,10 @@ py_types = {
'virNetwork *': ('O', "virNetwork",
"virNetworkPtr", "virNetworkPtr"),
'const virNetwork *': ('O', "virNetwork",
"virNetworkPtr", "virNetworkPtr"),
+ 'virNetworkPortPtr': ('O', "virNetworkPort",
"virNetworkPortPtr", "virNetworkPortPtr"),
+ 'virNetworkPort *': ('O', "virNetworkPort",
"virNetworkPortPtr", "virNetworkPortPtr"),
+ 'const virNetworkPort *': ('O', "virNetworkPort",
"virNetworkPortPtr", "virNetworkPortPtr"),
+
'virInterfacePtr': ('O', "virInterface",
"virInterfacePtr", "virInterfacePtr"),
'virInterface *': ('O', "virInterface",
"virInterfacePtr", "virInterfacePtr"),
'const virInterface *': ('O', "virInterface",
"virInterfacePtr", "virInterfacePtr"),
@@ -496,6 +500,8 @@ skip_impl = (
'virConnectBaselineHypervisorCPU',
'virDomainGetLaunchSecurityInfo',
'virNodeGetSEVInfo',
+ 'virNetworkPortGetParameters',
+ 'virNetworkPortSetParameters',
)
lxc_skip_impl = (
@@ -541,6 +547,7 @@ skip_function = (
'virConnectListAllStoragePools', # overridden in virConnect.py
'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
'virConnectListAllNetworks', # overridden in virConnect.py
+ 'virNetworkListAllPorts', # overridden in virConnect.py
'virConnectListAllInterfaces', # overridden in virConnect.py
'virConnectListAllNodeDevices', # overridden in virConnect.py
'virConnectListAllNWFilters', # overridden in virConnect.py
@@ -575,6 +582,7 @@ skip_function = (
"virDomainRef",
"virInterfaceRef",
"virNetworkRef",
+ "virNetworkPortRef",
"virNodeDeviceRef",
"virSecretRef",
"virNWFilterRef",
@@ -590,6 +598,7 @@ skip_function = (
"virDomainGetConnect",
"virInterfaceGetConnect",
"virNetworkGetConnect",
+ "virNetworkPortGetNetwork",
"virSecretGetConnect",
"virNWFilterGetConnect",
"virStoragePoolGetConnect",
@@ -1005,6 +1014,8 @@ classes_type = {
"virDomain *": ("._o", "virDomain(self, _obj=%s)",
"virDomain"),
"virNetworkPtr": ("._o", "virNetwork(self, _obj=%s)",
"virNetwork"),
"virNetwork *": ("._o", "virNetwork(self, _obj=%s)",
"virNetwork"),
+ "virNetworkPortPtr": ("._o", "virNetworkPort(self,
_obj=%s)", "virNetworkPort"),
+ "virNetworkPort *": ("._o", "virNetworkPort(self,
_obj=%s)", "virNetworkPort"),
"virInterfacePtr": ("._o", "virInterface(self,
_obj=%s)", "virInterface"),
"virInterface *": ("._o", "virInterface(self,
_obj=%s)", "virInterface"),
"virStoragePoolPtr": ("._o", "virStoragePool(self,
_obj=%s)", "virStoragePool"),
@@ -1027,8 +1038,8 @@ classes_type = {
"virDomainSnapshot *": ("._o", "virDomainSnapshot(self,
_obj=%s)", "virDomainSnapshot"),
}
-primary_classes = ["virDomain", "virNetwork",
"virInterface",
- "virStoragePool", "virStorageVol",
+primary_classes = ["virDomain", "virNetwork",
"virNetworkPort",
+ "virInterface", "virStoragePool",
"virStorageVol",
"virConnect", "virNodeDevice",
"virSecret",
"virNWFilter", "virNWFilterBinding",
"virStream", "virDomainSnapshot"]
@@ -1036,6 +1047,7 @@ primary_classes = ["virDomain", "virNetwork",
"virInterface",
classes_destructors = {
"virDomain": "virDomainFree",
"virNetwork": "virNetworkFree",
+ "virNetworkPort": "virNetworkPortFree",
"virInterface": "virInterfaceFree",
"virStoragePool": "virStoragePoolFree",
"virStorageVol": "virStorageVolFree",
@@ -1111,6 +1123,12 @@ def nameFixup(name, classe, type, file):
elif name[0:16] == "virNetworkLookup":
func = name[3:]
func = func[0:1].lower() + func[1:]
+ elif name[0:23] == "virNetworkPortCreateXML":
+ func = name[10:]
+ func = func[0:1].lower() + func[1:]
+ elif name[0:20] == "virNetworkPortLookup":
+ func = name[10:]
+ func = func[0:1].lower() + func[1:]
elif name[0:18] == "virInterfaceDefine":
func = name[3:]
func = func[0:1].lower() + func[1:]
@@ -1199,6 +1217,9 @@ def nameFixup(name, classe, type, file):
func = name[13:]
func = func[0:1].lower() + func[1:]
func = func.replace("dHCP", "DHCP")
+ elif name[0:14] == "virNetworkPort":
+ func = name[14:]
+ func = func[0:1].lower() + func[1:]
elif name[0:10] == "virNetwork":
func = name[10:]
func = func[0:1].lower() + func[1:]
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 53b15c5..6e29c1e 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -764,5 +764,18 @@
<arg name='virttype' type='const char *' info='optional
virtualization type'/>
<arg name='flags' type='int' info='unused, always pass
0'/>
</function>
+ <function name='virNetworkPortSetParameters' file='python'>
+ <info>Change the port tunables</info>
+ <return type='int' info='-1 in case of error, 0 in case of
success.'/>
+ <arg name='port' type='virNetworkPortPtr' info='pointer to
network port object'/>
+ <arg name='params' type='virTypedParameterPtr' info='pointer
to tunable objects'/>
+ <arg name='flags' type='int' info='unused, always pass
0'/>
+ </function>
+ <function name='virNetworkPortGetParameters' file='python'>
+ <info>Get the port parameters</info>
+ <return type='char *' info='None in case of error, returns a
dictionary of params'/>
+ <arg name='port' type='virNetworkPortPtr' info='pointer to
network port object'/>
+ <arg name='flags' type='int' info='unused, always pass
0'/>
+ </function>
</symbols>
</api>
diff --git a/libvirt-override.c b/libvirt-override.c
index c5e2908..a940730 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -9945,6 +9945,101 @@ libvirt_virNodeGetSEVInfo(PyObject *self ATTRIBUTE_UNUSED,
}
#endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
+#if LIBVIR_CHECK_VERSION(5, 5, 0)
+static PyObject *
+libvirt_virNetworkPortSetParameters(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ virNetworkPortPtr port;
+ PyObject *pyobj_port, *info;
+ PyObject *ret = NULL;
+ int i_retval;
+ int nparams = 0;
+ Py_ssize_t size = 0;
+ unsigned int flags;
+ virTypedParameterPtr params = NULL, new_params = NULL;
+
+ if (!PyArg_ParseTuple(args,
+ (char *)"OOI:virNetworkPortSetParameters",
+ &pyobj_port, &info, &flags))
+ return NULL;
+ port = (virNetworkPortPtr) PyvirNetworkPort_Get(pyobj_port);
+
+ if ((size = PyDict_Size(info)) < 0)
+ return NULL;
+
+ if (size == 0) {
+ PyErr_Format(PyExc_LookupError,
+ "Need non-empty dictionary to set attributes");
+ return NULL;
+ }
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virNetworkPortGetParameters(port, ¶ms, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0)
+ return VIR_PY_INT_FAIL;
+
+ if (nparams == 0) {
+ PyErr_Format(PyExc_LookupError,
+ "Port has no settable attributes");
+ return NULL;
+ }
+
+ new_params = setPyVirTypedParameter(info, params, nparams);
+ if (!new_params)
+ goto cleanup;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virNetworkPortSetParameters(port, new_params, size, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0) {
+ ret = VIR_PY_INT_FAIL;
+ goto cleanup;
+ }
+
+ ret = VIR_PY_INT_SUCCESS;
+
+ cleanup:
+ virTypedParamsFree(params, nparams);
+ virTypedParamsFree(new_params, size);
+ return ret;
+}
+
+static PyObject *
+libvirt_virNetworkPortGetParameters(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *pyobj_port;
+ virNetworkPortPtr port;
+ virTypedParameterPtr params = NULL;
+ int nparams = 0;
+ PyObject *dict = NULL;
+ unsigned int flags;
+ int rc;
+
+ if (!PyArg_ParseTuple(args, (char *) "OI:virNetworkPortGetParameters",
+ &pyobj_port, &flags))
+ return NULL;
+ port = (virNetworkPortPtr) PyvirNetworkPort_Get(pyobj_port);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ rc = virNetworkPortGetParameters(port, ¶ms, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (rc < 0)
+ return VIR_PY_NONE;
+
+ if (!(dict = getPyVirTypedParameter(params, nparams)))
+ goto cleanup;
+
+ cleanup:
+ virTypedParamsFree(params, nparams);
+ return dict;
+}
+#endif /* LIBVIR_CHECK_VERSION(5, 5, 0) */
/************************************************************************
* *
@@ -10192,6 +10287,10 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainGetLaunchSecurityInfo",
libvirt_virDomainGetLaunchSecurityInfo, METH_VARARGS, NULL},
{(char *) "virNodeGetSEVInfo", libvirt_virNodeGetSEVInfo, METH_VARARGS,
NULL},
#endif /* LIBVIR_CHECK_VERSION(4, 5, 0) */
+#if LIBVIR_CHECK_VERSION(4, 5, 0)
+ {(char *) "virNetworkPortSetParameters",
libvirt_virNetworkPortSetParameters, METH_VARARGS, NULL},
+ {(char *) "virNetworkPortGetParameters",
libvirt_virNetworkPortGetParameters, METH_VARARGS, NULL},
+#endif /* LIBVIR_CHECK_VERSION(5, 5, 0) */
{NULL, NULL, 0, NULL}
};
diff --git a/typewrappers.c b/typewrappers.c
index 9ba14b4..5710744 100644
--- a/typewrappers.c
+++ b/typewrappers.c
@@ -451,6 +451,19 @@ libvirt_virNetworkPtrWrap(virNetworkPtr node)
return ret;
}
+PyObject *
+libvirt_virNetworkPortPtrWrap(virNetworkPortPtr node)
+{
+ PyObject *ret;
+
+ if (node == NULL) {
+ return VIR_PY_NONE;
+ }
+
+ ret = libvirt_buildPyObject(node, "virNetworkPortPtr", NULL);
+ return ret;
+}
+
PyObject *
libvirt_virInterfacePtrWrap(virInterfacePtr node)
{
diff --git a/typewrappers.h b/typewrappers.h
index 4423774..e4983b2 100644
--- a/typewrappers.h
+++ b/typewrappers.h
@@ -58,6 +58,15 @@ typedef struct {
} PyvirNetwork_Object;
+#define PyvirNetworkPort_Get(v) (((v) == Py_None) ? NULL : \
+ (((PyvirNetworkPort_Object *)(v))->obj))
+
+typedef struct {
+ PyObject_HEAD
+ virNetworkPortPtr obj;
+} PyvirNetworkPort_Object;
+
+
#define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
(((PyvirInterface_Object *)(v))->obj))
@@ -192,6 +201,7 @@ int libvirt_charPtrSizeUnwrap(PyObject *obj, char **str, Py_ssize_t
*size);
PyObject * libvirt_virConnectPtrWrap(virConnectPtr node);
PyObject * libvirt_virDomainPtrWrap(virDomainPtr node);
PyObject * libvirt_virNetworkPtrWrap(virNetworkPtr node);
+PyObject * libvirt_virNetworkPortPtrWrap(virNetworkPortPtr node);
PyObject * libvirt_virInterfacePtrWrap(virInterfacePtr node);
PyObject * libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node);
PyObject * libvirt_virStorageVolPtrWrap(virStorageVolPtr node);
--
2.21.0