summaryrefslogtreecommitdiffstats
path: root/libvirt-override.c
diff options
context:
space:
mode:
authorAlex Jia <ajia@redhat.com>2012-02-14 10:46:23 +0800
committerAlex Jia <ajia@redhat.com>2012-02-16 10:15:16 +0800
commitf5c5e7e77bb962bcacd849c52891d694002d03c5 (patch)
tree765009d6e76b9ee7c3354e2e6509925ca33141f5 /libvirt-override.c
parente8fe5e59e246fb1ed396cc737657ee4e9d752ef3 (diff)
downloadlibvirt-python-split-f5c5e7e77bb962bcacd849c52891d694002d03c5.tar.gz
libvirt-python-split-f5c5e7e77bb962bcacd849c52891d694002d03c5.tar.xz
libvirt-python-split-f5c5e7e77bb962bcacd849c52891d694002d03c5.zip
python: Expose virDomain{G,S}etInterfaceParameters APIs in python binding
The v4 patch corrects indentation issues. The v3 patch follows latest python binding codes and change 'size' type from int to Py_ssize_t. An simple example to show how to use it: #!/usr/bin/env python import libvirt conn = libvirt.open(None) dom = conn.lookupByName('foo') print dom.interfaceParameters('vnet0', 0) params = {'outbound.peak': 10, 'inbound.peak': 10, 'inbound.burst': 20, 'inbound.average': 20, 'outbound.average': 30, 'outbound.burst': 30} print dom.setInterfaceParameters('vnet0', params, 0) print dom.interfaceParameters('vnet0', 0) Signed-off-by: Alex Jia <ajia@redhat.com>
Diffstat (limited to 'libvirt-override.c')
-rw-r--r--libvirt-override.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/libvirt-override.c b/libvirt-override.c
index 4e8a97e..792cfa3 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -1109,6 +1109,130 @@ cleanup:
}
static PyObject *
+libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *info;
+ PyObject *ret = NULL;
+ int i_retval;
+ int nparams = 0;
+ Py_ssize_t size = 0;
+ unsigned int flags;
+ const char *device = NULL;
+ virTypedParameterPtr params, new_params;
+
+ if (!PyArg_ParseTuple(args,
+ (char *)"OzOi:virDomainSetInterfaceParameters",
+ &pyobj_domain, &device, &info, &flags))
+ return NULL;
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ 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 = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0)
+ return VIR_PY_INT_FAIL;
+
+ if (nparams == 0) {
+ PyErr_Format(PyExc_LookupError,
+ "Domain has no settable attributes");
+ return NULL;
+ }
+
+ if (VIR_ALLOC_N(params, nparams) < 0)
+ return PyErr_NoMemory();
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0) {
+ ret = VIR_PY_INT_FAIL;
+ goto cleanup;
+ }
+
+ new_params = setPyVirTypedParameter(info, params, nparams);
+ if (!new_params)
+ goto cleanup;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virDomainSetInterfaceParameters(domain, device, 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:
+ virTypedParameterArrayClear(params, nparams);
+ VIR_FREE(params);
+ VIR_FREE(new_params);
+ return ret;
+}
+
+static PyObject *
+libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ virDomainPtr domain;
+ PyObject *pyobj_domain;
+ PyObject *ret = NULL;
+ int i_retval;
+ int nparams = 0;
+ unsigned int flags;
+ const char *device = NULL;
+ virTypedParameterPtr params;
+
+ if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainGetInterfaceParameters",
+ &pyobj_domain, &device, &flags))
+ return NULL;
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virDomainGetInterfaceParameters(domain, device, NULL, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0)
+ return VIR_PY_NONE;
+
+ if (!nparams)
+ return PyDict_New();
+
+ if (VIR_ALLOC_N(params, nparams) < 0)
+ return PyErr_NoMemory();
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virDomainGetInterfaceParameters(domain, device, params, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0) {
+ ret = VIR_PY_NONE;
+ goto cleanup;
+ }
+
+ ret = getPyVirTypedParameter(params, nparams);
+
+cleanup:
+ virTypedParameterArrayClear(params, nparams);
+ VIR_FREE(params);
+ return ret;
+}
+
+static PyObject *
libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
virDomainPtr domain;
@@ -5256,6 +5380,8 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
{(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
{(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, METH_VARARGS, NULL},
+ {(char *) "virDomainSetInterfaceParameters", libvirt_virDomainSetInterfaceParameters, METH_VARARGS, NULL},
+ {(char *) "virDomainGetInterfaceParameters", libvirt_virDomainGetInterfaceParameters, METH_VARARGS, NULL},
{(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
{(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
{(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},