mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-10 23:45:53 -06:00
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>
This commit is contained in:
parent
4c1c361127
commit
8b29c45986
@ -261,6 +261,22 @@
|
|||||||
<arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
|
<arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
|
||||||
<arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/>
|
<arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/>
|
||||||
</function>
|
</function>
|
||||||
|
<function name='virDomainSetInterfaceParameters' file='python'>
|
||||||
|
<info>Change the bandwidth tunables for a interface device</info>
|
||||||
|
<arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
|
||||||
|
<arg name='device' type='const char *' info='interface name'/>
|
||||||
|
<arg name='params' type='virTypedParameterPtr' info='Pointer to bandwidth tuning params object'/>
|
||||||
|
<arg name='flags' type='unsigned int' info='an OR'ed set of virDomainModificationImpact'/>
|
||||||
|
<return type='int' info='0 in case of success, -1 in case of failure'/>
|
||||||
|
</function>
|
||||||
|
<function name='virDomainGetInterfaceParameters' file='python'>
|
||||||
|
<info>Get the bandwidth tunables for a interface device</info>
|
||||||
|
<arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
|
||||||
|
<arg name='device' type='const char *' info='interface name'/>
|
||||||
|
<arg name='flags' type='unsigned int' info='an OR'ed set of virDomainModificationImpact'/>
|
||||||
|
<return type='str *' info='the bandwidth tunables value or None in case of error'/>
|
||||||
|
</function>
|
||||||
|
|
||||||
<function name='virConnectListStoragePools' file='python'>
|
<function name='virConnectListStoragePools' file='python'>
|
||||||
<info>list the storage pools, stores the pointers to the names in @names</info>
|
<info>list the storage pools, stores the pointers to the names in @names</info>
|
||||||
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
|
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
|
||||||
|
@ -1108,6 +1108,130 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 *
|
static PyObject *
|
||||||
libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
|
libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
|
||||||
PyObject *args) {
|
PyObject *args) {
|
||||||
@ -5256,6 +5380,8 @@ static PyMethodDef libvirtMethods[] = {
|
|||||||
{(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
|
{(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
|
||||||
{(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
|
{(char *) "virDomainSetNumaParameters", libvirt_virDomainSetNumaParameters, METH_VARARGS, NULL},
|
||||||
{(char *) "virDomainGetNumaParameters", libvirt_virDomainGetNumaParameters, 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 *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
|
||||||
{(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
|
{(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
|
||||||
{(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
|
{(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
|
||||||
|
Loading…
Reference in New Issue
Block a user