On Tue, Jun 18, 2019 at 12:09:21PM +0100, Daniel P. Berrangé wrote:
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@xxxxxxxxxx> --- 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/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)
Indentation
+{ + 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)
Indentation
+{ + 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;
There's no need for the if or the cleanup label here
+ + 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)
5, 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} };
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> Jano
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list