summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2014-05-19 15:04:44 +0200
committerMichal Privoznik <mprivozn@redhat.com>2014-05-20 17:26:17 +0200
commitbcacc418a3b21f5fe34bbe6579275453f5b849d7 (patch)
treec40b1507a6c7efff342c44badaac712d31f2f189
parentc5bbd5bd9de86d88f7b2152522690dd2bc1fcbcd (diff)
downloadlibvirt-python-bcacc418a3b21f5fe34bbe6579275453f5b849d7.tar.gz
Implement virDomain{Get,Set}Time APIs
While the setter can be generated automatically, the getter is not. However, it would be a lot easier if they both share the same logic: a python dictionary to represent the time: dict['seconds'] to represent seconds, and dict['nseconds'] to represent nanoseconds. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
-rwxr-xr-xgenerator.py2
-rw-r--r--libvirt-override-virDomain.py13
-rw-r--r--libvirt-override.c95
-rw-r--r--sanitytest.py2
4 files changed, 111 insertions, 1 deletions
diff --git a/generator.py b/generator.py
index e7b4643..bdac877 100755
--- a/generator.py
+++ b/generator.py
@@ -519,6 +519,8 @@ skip_function = (
'virDomainFSFreeze', # overridden in virDomain.py
'virDomainFSThaw', # overridden in virDomain.py
+ 'virDomainGetTime', # overridden in virDomain.py
+ 'virDomainSetTime', # overridden in virDomain.py
# 'Ref' functions have no use for bindings users.
"virConnectRef",
diff --git a/libvirt-override-virDomain.py b/libvirt-override-virDomain.py
index e61ad00..a50ec0d 100644
--- a/libvirt-override-virDomain.py
+++ b/libvirt-override-virDomain.py
@@ -59,3 +59,16 @@
ret = libvirtmod.virDomainFSThaw(self._o, mountpoints, flags)
if ret == -1: raise libvirtError ('virDomainFSThaw() failed', dom=self)
return ret
+
+ def getTime(self, flags=0):
+ """Extract information about guest time """
+ ret = libvirtmod.virDomainGetTime(self._o, flags)
+ if ret == -1: raise libvirtError ('virDomainGetTime() failed', dom=self)
+ return ret
+
+ def setTime(self, time=None, flags=0):
+ """Set guest time to the given value. @time is a dict conatining
+ 'seconds' field for seconds and 'nseconds' field for nanosecons """
+ ret = libvirtmod.virDomainSetTime(self._o, time, flags)
+ if ret == -1: raise libvirtError ('virDomainSetTime() failed', dom=self)
+ return ret
diff --git a/libvirt-override.c b/libvirt-override.c
index c4ac223..a7a6213 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -7645,6 +7645,99 @@ libvirt_virDomainFSThaw(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
VIR_FREE(mountpoints);
return py_retval;
}
+
+static PyObject *
+libvirt_virDomainGetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval = NULL;
+ PyObject *dict = NULL;
+ PyObject *pyobj_domain, *pyobj_seconds, *pyobj_nseconds;
+ virDomainPtr domain;
+ long long seconds;
+ unsigned int nseconds;
+ unsigned int flags;
+ int c_retval;
+
+ if (!PyArg_ParseTuple(args, (char*)"Oi:virDomainGetTime",
+ &pyobj_domain, &flags))
+ return NULL;
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ if (!(dict = PyDict_New()))
+ goto cleanup;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virDomainGetTime(domain, &seconds, &nseconds, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (c_retval < 0)
+ goto cleanup;
+
+ if (!(pyobj_seconds = libvirt_longlongWrap(seconds)) ||
+ PyDict_SetItemString(dict, "seconds", pyobj_seconds) < 0)
+ goto cleanup;
+ Py_DECREF(pyobj_seconds);
+
+ if (!(pyobj_nseconds = libvirt_uintWrap(nseconds)) ||
+ PyDict_SetItemString(dict, "nseconds", pyobj_nseconds) < 0)
+ goto cleanup;
+ Py_DECREF(pyobj_nseconds);
+
+ py_retval = dict;
+ dict = NULL;
+ cleanup:
+ Py_XDECREF(dict);
+ return py_retval;
+}
+
+
+static PyObject *
+libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+ PyObject *py_retval = NULL;
+ PyObject *pyobj_domain;
+ PyObject *py_dict;
+ virDomainPtr domain;
+ long long seconds = 0;
+ unsigned int nseconds = 0;
+ unsigned int flags;
+ ssize_t py_dict_size;
+ int c_retval;
+
+ if (!PyArg_ParseTuple(args, (char*)"OOi:virDomainSetTime",
+ &pyobj_domain, &py_dict, &flags))
+ return NULL;
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ py_dict_size = PyDict_Size(py_dict);
+
+ if (py_dict_size == 2) {
+ PyObject *pyobj_seconds, *pyobj_nseconds;
+
+ if (!(pyobj_seconds = PyDict_GetItemString(py_dict, "seconds")) ||
+ (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0)) {
+ PyErr_Format(PyExc_LookupError, "malformed or missing 'seconds'");
+ goto cleanup;
+ }
+
+ if (!(pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds")) ||
+ (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0)) {
+ PyErr_Format(PyExc_LookupError, "malformed or missing 'nseconds'");
+ goto cleanup;
+ }
+ } else if (py_dict_size > 0) {
+ PyErr_Format(PyExc_LookupError, "Dictionary must contain "
+ "'seconds' and 'nseconds'");
+ goto cleanup;
+ }
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virDomainSetTime(domain, seconds, nseconds, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ py_retval = libvirt_intWrap(c_retval);
+
+ cleanup:
+ return py_retval;
+}
#endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
/************************************************************************
@@ -7825,6 +7918,8 @@ static PyMethodDef libvirtMethods[] = {
#if LIBVIR_CHECK_VERSION(1, 2, 5)
{(char *) "virDomainFSFreeze", libvirt_virDomainFSFreeze, METH_VARARGS, NULL},
{(char *) "virDomainFSThaw", libvirt_virDomainFSThaw, METH_VARARGS, NULL},
+ {(char *) "virDomainGetTime", libvirt_virDomainGetTime, METH_VARARGS, NULL},
+ {(char *) "virDomainSetTime", libvirt_virDomainSetTime, METH_VARARGS, NULL},
#endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
{NULL, NULL, 0, NULL}
};
diff --git a/sanitytest.py b/sanitytest.py
index 62fe42b..6067a3f 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -152,7 +152,7 @@ for name in sorted(basicklassmap):
# and virDomainSnapshot namespaces which stupidly used a different
# convention which we now can't fix without breaking API
if func[0:3] == "Get" and klass not in ["virConnect", "virDomainSnapshot", "libvirt"]:
- if func not in ["GetCPUStats"]:
+ if func not in ["GetCPUStats", "GetTime"]:
func = func[3:]
# The object creation and lookup APIs all have to get re-mapped