summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHu Tao <hutao@cn.fujitsu.com>2011-07-27 10:13:10 +0800
committerMichal Privoznik <mprivozn@redhat.com>2011-07-28 10:15:34 +0200
commit915bcb169d98c75dfa0f648daf650c7c9a1c1719 (patch)
tree042c236f0f879fffb7ecb11d8edcfb726a5f6478
parent0f47be1708e3e52924ccff4da3ff92737c4343b8 (diff)
downloadlibvirt-python-split-915bcb169d98c75dfa0f648daf650c7c9a1c1719.tar.gz
libvirt-python-split-915bcb169d98c75dfa0f648daf650c7c9a1c1719.tar.xz
libvirt-python-split-915bcb169d98c75dfa0f648daf650c7c9a1c1719.zip
python: add python binding for virDomainGetMemoryParameters
-rw-r--r--libvirt-override-api.xml6
-rw-r--r--libvirt-override.c79
2 files changed, 79 insertions, 6 deletions
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 928bfb7..0a67f9d 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -221,10 +221,10 @@
<arg name='params' type='virMemoryParameterPtr' info='pointer to memory tunable objects'/>
</function>
<function name='virDomainGetMemoryParameters' file='python'>
- <info>Get the memory parameters, the @params array will be filled with the values.</info>
- <return type='int' info='-1 in case of error, 0 in case of success.'/>
+ <info>Get the memory parameters</info>
+ <return type='virSchedParameterPtr' info='None in case of error, returns a dictionary of params'/>
<arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
- <arg name='params' type='virMemoryParameterPtr' info='pointer to memory tunable objects'/>
+ <arg name='flags' type='int' info='an OR&apos;ed set of virDomainModificationImpact'/>
</function>
<function name='virConnectListStoragePools' file='python'>
<info>list the storage pools, stores the pointers to the names in @names</info>
diff --git a/libvirt-override.c b/libvirt-override.c
index a580309..c0ac491 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -747,11 +747,84 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
return VIR_PY_INT_FAIL;
}
-/* FIXME: This is a place holder for the implementation. */
static PyObject *
libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED,
- PyObject *args ATTRIBUTE_UNUSED) {
- return VIR_PY_INT_FAIL;
+ PyObject *args) {
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *info;
+ int i_retval;
+ int nparams = 0, i;
+ unsigned int flags;
+ virTypedParameterPtr params;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetMemoryParameters",
+ &pyobj_domain, &flags))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virDomainGetMemoryParameters(domain, NULL, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0)
+ return VIR_PY_NONE;
+
+ if ((params = malloc(sizeof(*params)*nparams)) == NULL)
+ return VIR_PY_NONE;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virDomainGetMemoryParameters(domain, params, &nparams, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0) {
+ free(params);
+ return VIR_PY_NONE;
+ }
+
+ /* convert to a Python tuple of long objects */
+ if ((info = PyDict_New()) == NULL) {
+ free(params);
+ return VIR_PY_NONE;
+ }
+ for (i = 0 ; i < nparams ; i++) {
+ PyObject *key, *val;
+
+ switch (params[i].type) {
+ case VIR_TYPED_PARAM_INT:
+ val = PyInt_FromLong((long)params[i].value.i);
+ break;
+
+ case VIR_TYPED_PARAM_UINT:
+ val = PyInt_FromLong((long)params[i].value.ui);
+ break;
+
+ case VIR_TYPED_PARAM_LLONG:
+ val = PyLong_FromLongLong((long long)params[i].value.l);
+ break;
+
+ case VIR_TYPED_PARAM_ULLONG:
+ val = PyLong_FromLongLong((long long)params[i].value.ul);
+ break;
+
+ case VIR_TYPED_PARAM_DOUBLE:
+ val = PyFloat_FromDouble((double)params[i].value.d);
+ break;
+
+ case VIR_TYPED_PARAM_BOOLEAN:
+ val = PyBool_FromLong((long)params[i].value.b);
+ break;
+
+ default:
+ free(params);
+ Py_DECREF(info);
+ return VIR_PY_NONE;
+ }
+
+ key = libvirt_constcharPtrWrap(params[i].field);
+ PyDict_SetItem(info, key, val);
+ }
+ free(params);
+ return(info);
}
static PyObject *