1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2024-10-26 07:55:06 +03:00

Add virDomainCheckpoint APIs

Copies heavily from existing virDomainSnapshot handling, regarding
what special cases the generator has to be taught and what overrides
need to be written.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Eric Blake 2019-02-07 16:36:16 -06:00
parent 5e9d1aa7fa
commit 358a8640fa
10 changed files with 196 additions and 7 deletions

View File

@ -28,6 +28,8 @@ hand written source files
the virConnect class
- libvirt-override-virDomain.py - high level overrides in
the virDomain class
- libvirt-override-virDomainCheckpoint.py - high level overrides in
the virDomainCheckpoint class
- libvirt-override-virDomainSnapshot.py - high level overrides in
the virDomainSnapshot class
- libvirt-override-virStoragePool.py - high level overrides in

View File

@ -23,6 +23,7 @@ include libvirt-override.c
include libvirt-override.py
include libvirt-override-virConnect.py
include libvirt-override-virDomain.py
include libvirt-override-virDomainCheckpoint.py
include libvirt-override-virDomainSnapshot.py
include libvirt-override-virNetwork.py
include libvirt-override-virStoragePool.py

View File

@ -35,6 +35,7 @@ libvirt_headers = [
"libvirt",
"libvirt-common",
"libvirt-domain",
"libvirt-domain-checkpoint",
"libvirt-domain-snapshot",
"libvirt-event",
"libvirt-host",
@ -368,6 +369,10 @@ py_types = {
'virStream *': ('O', "virStream", "virStreamPtr", "virStreamPtr"),
'const virStream *': ('O', "virStream", "virStreamPtr", "virStreamPtr"),
'virDomainCheckpointPtr': ('O', "virDomainCheckpoint", "virDomainCheckpointPtr", "virDomainCheckpointPtr"),
'virDomainCheckpoint *': ('O', "virDomainCheckpoint", "virDomainCheckpointPtr", "virDomainCheckpointPtr"),
'const virDomainCheckpoint *': ('O', "virDomainCheckpoint", "virDomainCheckpointPtr", "virDomainCheckpointPtr"),
'virDomainSnapshotPtr': ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
'virDomainSnapshot *': ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
'const virDomainSnapshot *': ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"),
@ -542,6 +547,8 @@ skip_function = (
'virSaveLastError', # We have our own python error wrapper
'virFreeError', # Only needed if we use virSaveLastError
'virConnectListAllDomains', # overridden in virConnect.py
'virDomainListAllCheckpoints', # overridden in virDomain.py
'virDomainCheckpointListAllChildren', # overridden in virDomainCheckpoint.py
'virDomainListAllSnapshots', # overridden in virDomain.py
'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
'virConnectListAllStoragePools', # overridden in virConnect.py
@ -590,6 +597,7 @@ skip_function = (
"virStoragePoolRef",
"virStorageVolRef",
"virStreamRef",
"virDomainCheckpointRef",
"virDomainSnapshotRef",
# This functions shouldn't be called via the bindings (and even the docs
@ -603,6 +611,8 @@ skip_function = (
"virNWFilterGetConnect",
"virStoragePoolGetConnect",
"virStorageVolGetConnect",
"virDomainCheckpointGetConnect",
"virDomainCheckpointGetDomain",
"virDomainSnapshotGetConnect",
"virDomainSnapshotGetDomain",
@ -1034,6 +1044,8 @@ classes_type = {
"virStream *": ("._o", "virStream(self, _obj=%s)", "virStream"),
"virConnectPtr": ("._o", "virConnect(_obj=%s)", "virConnect"),
"virConnect *": ("._o", "virConnect(_obj=%s)", "virConnect"),
"virDomainCheckpointPtr": ("._o", "virDomainCheckpoint(self,_obj=%s)", "virDomainCheckpoint"),
"virDomainCheckpoint *": ("._o", "virDomainCheckpoint(self, _obj=%s)", "virDomainCheckpoint"),
"virDomainSnapshotPtr": ("._o", "virDomainSnapshot(self,_obj=%s)", "virDomainSnapshot"),
"virDomainSnapshot *": ("._o", "virDomainSnapshot(self, _obj=%s)", "virDomainSnapshot"),
}
@ -1042,7 +1054,7 @@ primary_classes = ["virDomain", "virNetwork", "virNetworkPort",
"virInterface", "virStoragePool", "virStorageVol",
"virConnect", "virNodeDevice", "virSecret",
"virNWFilter", "virNWFilterBinding",
"virStream", "virDomainSnapshot"]
"virStream", "virDomainCheckpoint", "virDomainSnapshot"]
classes_destructors = {
"virDomain": "virDomainFree",
@ -1055,6 +1067,7 @@ classes_destructors = {
"virSecret": "virSecretFree",
"virNWFilter": "virNWFilterFree",
"virNWFilterBinding": "virNWFilterBindingFree",
"virDomainCheckpoint": "virDomainCheckpointFree",
"virDomainSnapshot": "virDomainSnapshotFree",
# We hand-craft __del__ for this one
#"virStream": "virStreamFree",
@ -1065,6 +1078,7 @@ class_skip_connect_impl = {
}
class_domain_impl = {
"virDomainCheckpoint": True,
"virDomainSnapshot": True,
}
@ -1189,6 +1203,15 @@ def nameFixup(name, classe, type, file):
elif name[0:12] == "virDomainGet":
func = name[12:]
func = func[0:1].lower() + func[1:]
elif name[0:31] == "virDomainCheckpointLookupByName":
func = name[9:]
func = func[0:1].lower() + func[1:]
elif name[0:28] == "virDomainCheckpointCreateXML":
func = name[9:]
func = func[0:1].lower() + func[1:]
elif name[0:19] == "virDomainCheckpoint":
func = name[19:]
func = func[0:1].lower() + func[1:]
elif name[0:29] == "virDomainSnapshotLookupByName":
func = name[9:]
func = func[0:1].lower() + func[1:]
@ -1525,7 +1548,7 @@ def buildWrappers(module):
"virStorageVol", "virNodeDevice", "virSecret","virStream",
"virNWFilter", "virNWFilterBinding" ]:
classes.write(" def __init__(self, conn, _obj=None):\n")
elif classname in [ 'virDomainSnapshot' ]:
elif classname in [ "virDomainCheckpoint", "virDomainSnapshot" ]:
classes.write(" def __init__(self, dom, _obj=None):\n")
else:
classes.write(" def __init__(self, _obj=None):\n")
@ -1537,7 +1560,7 @@ def buildWrappers(module):
classes.write(" self._conn = conn\n" + \
" if not isinstance(conn, virConnect):\n" + \
" self._conn = conn._conn\n")
elif classname in [ "virDomainSnapshot" ]:
elif classname in [ "virDomainCheckpoint", "virDomainSnapshot" ]:
classes.write(" self._dom = dom\n")
classes.write(" self._conn = dom.connect()\n")
classes.write(" if type(_obj).__name__ not in [\"PyCapsule\", \"PyCObject\"]:\n")
@ -1665,7 +1688,7 @@ def buildWrappers(module):
classes.write(
" if ret is None:raise libvirtError('%s() failed', vol=self)\n" %
(name))
elif classname == "virDomainSnapshot":
elif classname in [ "virDomainCheckpoint", "virDomainSnapshot"]:
classes.write(
" if ret is None:raise libvirtError('%s() failed', dom=self._dom)\n" %
(name))

View File

@ -576,6 +576,18 @@
<arg name='flags' type='unsigned int' info='flags'/>
<return type='int' info="0 on success, -1 on error"/>
</function>
<function name='virDomainListAllCheckpoints' file='python'>
<info>returns the list of checkpoints for the given domain</info>
<arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
<arg name='flags' type='unsigned int' info='flags'/>
<return type='char *' info='the list of checkpoints or None in case of error'/>
</function>
<function name='virDomainCheckpointListAllChildren' file='python'>
<info>collect the list of child checkpoint names for the given checkpoint</info>
<arg name='checkpoint' type='virDomainCheckpointPtr' info='pointer to the checkpoint'/>
<arg name='flags' type='unsigned int' info='flags'/>
<return type='char *' info='the list of checkpoints or None in case of error'/>
</function>
<function name='virDomainGetBlockJobInfo' file='python'>
<info>Get progress information for a block job</info>
<arg name='dom' type='virDomainPtr' info='pointer to the domain'/>

View File

@ -11,6 +11,19 @@
return retlist
def listAllCheckpoints(self, flags=0):
"""List all checkpoints and returns a list of checkpoint objects"""
ret = libvirtmod.virDomainListAllCheckpoints(self._o, flags)
if ret is None:
raise libvirtError("virDomainListAllCheckpoints() failed", conn=self)
retlist = list()
for chkptr in ret:
retlist.append(virDomainCheckpoint(self, _obj=chkptr))
return retlist
def createWithFiles(self, files, flags=0):
"""Launch a defined domain. If the call succeeds the domain moves from the
defined to the running domains pools.

View File

@ -0,0 +1,19 @@
def getConnect(self):
"""Get the connection that owns the domain that a checkpoint was created for"""
return self.connect()
def getDomain(self):
"""Get the domain that a checkpoint was created for"""
return self.domain()
def listAllChildren(self, flags=0):
"""List all child checkpoints and returns a list of checkpoint objects"""
ret = libvirtmod.virDomainCheckpointListAllChildren(self._o, flags)
if ret is None:
raise libvirtError("virDomainCheckpointListAllChildren() failed", conn=self)
retlist = list()
for chkptr in ret:
retlist.append(virDomainCheckpoint(self, _obj=chkptr))
return retlist

View File

@ -2325,6 +2325,98 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
}
#if LIBVIR_CHECK_VERSION(5, 6, 0)
static PyObject *
libvirt_virDomainListAllCheckpoints(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args)
{
PyObject *py_retval = NULL;
virDomainCheckpointPtr *chks = NULL;
int c_retval;
ssize_t i;
virDomainPtr dom;
PyObject *pyobj_dom;
unsigned int flags;
if (!PyArg_ParseTuple(args, (char *)"OI:virDomainListAllCheckpoints",
&pyobj_dom, &flags))
return NULL;
dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainListAllCheckpoints(dom, &chks, flags);
LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0)
return VIR_PY_NONE;
if (!(py_retval = PyList_New(c_retval)))
goto cleanup;
for (i = 0; i < c_retval; i++) {
VIR_PY_LIST_SET_GOTO(py_retval, i,
libvirt_virDomainCheckpointPtrWrap(chks[i]), error);
chks[i] = NULL;
}
cleanup:
for (i = 0; i < c_retval; i++)
if (chks[i])
virDomainCheckpointFree(chks[i]);
VIR_FREE(chks);
return py_retval;
error:
Py_CLEAR(py_retval);
goto cleanup;
}
static PyObject *
libvirt_virDomainCheckpointListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args)
{
PyObject *py_retval = NULL;
virDomainCheckpointPtr *chks = NULL;
int c_retval;
ssize_t i;
virDomainCheckpointPtr parent;
PyObject *pyobj_parent;
unsigned int flags;
if (!PyArg_ParseTuple(args, (char *)"OI:virDomainCheckpointListAllChildren",
&pyobj_parent, &flags))
return NULL;
parent = (virDomainCheckpointPtr) PyvirDomainCheckpoint_Get(pyobj_parent);
LIBVIRT_BEGIN_ALLOW_THREADS;
c_retval = virDomainCheckpointListAllChildren(parent, &chks, flags);
LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0)
return VIR_PY_NONE;
if (!(py_retval = PyList_New(c_retval)))
goto cleanup;
for (i = 0; i < c_retval; i++) {
VIR_PY_LIST_SET_GOTO(py_retval, i,
libvirt_virDomainCheckpointPtrWrap(chks[i]), error);
chks[i] = NULL;
}
cleanup:
for (i = 0; i < c_retval; i++)
if (chks[i])
virDomainCheckpointFree(chks[i]);
VIR_FREE(chks);
return py_retval;
error:
Py_CLEAR(py_retval);
goto cleanup;
}
#endif /* LIBVIR_CHECK_VERSION(5, 6, 0) */
static PyObject *
libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args)
@ -10238,6 +10330,10 @@ static PyMethodDef libvirtMethods[] = {
#if LIBVIR_CHECK_VERSION(1, 0, 3)
{(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL},
#endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */
#if LIBVIR_CHECK_VERSION(5, 6, 0)
{(char *) "virDomainListAllCheckpoints", libvirt_virDomainListAllCheckpoints, METH_VARARGS, NULL},
{(char *) "virDomainCheckpointListAllChildren", libvirt_virDomainCheckpointListAllChildren, METH_VARARGS, NULL},
#endif /* LIBVIR_CHECK_VERSION(5, 6, 0) */
{(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
#if LIBVIR_CHECK_VERSION(0, 9, 13)
{(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL},

View File

@ -249,7 +249,7 @@ for name in sorted(basicklassmap):
# Remove 'Get' prefix from most APIs, except those in virConnect
# 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[0:3] == "Get" and klass not in ["virConnect", "virDomainCheckpoint", "virDomainSnapshot", "libvirt"]:
if func not in ["GetCPUStats", "GetTime"]:
func = func[3:]
@ -266,7 +266,7 @@ for name in sorted(basicklassmap):
if klass != "virDomain":
func = klass[3:] + func
if klass == "virDomainSnapshot":
if klass in ["virDomainCheckpoint", "virDomainSnapshot"]:
klass = "virDomain"
func = func[6:]
elif klass == "virStorageVol" and func in ["StorageVolCreateXMLFrom", "StorageVolCreateXML"]:
@ -300,7 +300,7 @@ for name in sorted(basicklassmap):
if func[0:6] == "Change":
klass = "virConnect"
# Need to special case the snapshot APIs
# Need to special case the checkpoint and snapshot APIs
if klass == "virDomainSnapshot" and func in ["Current", "ListNames", "Num"]:
klass = "virDomain"
func = "snapshot" + func

View File

@ -581,6 +581,19 @@ libvirt_virStreamPtrWrap(virStreamPtr node)
return ret;
}
PyObject *
libvirt_virDomainCheckpointPtrWrap(virDomainCheckpointPtr node)
{
PyObject *ret;
if (node == NULL) {
return VIR_PY_NONE;
}
ret = libvirt_buildPyObject(node, "virDomainCheckpointPtr", NULL);
return ret;
}
PyObject *
libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node)
{

View File

@ -140,6 +140,15 @@ typedef struct {
} PyvirStream_Object;
#define PyvirDomainCheckpoint_Get(v) (((v) == Py_None) ? NULL : \
(((PyvirDomainCheckpoint_Object *)(v))->obj))
typedef struct {
PyObject_HEAD
virDomainCheckpointPtr obj;
} PyvirDomainCheckpoint_Object;
#define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
(((PyvirDomainSnapshot_Object *)(v))->obj))
@ -217,6 +226,7 @@ PyObject * libvirt_virSecretPtrWrap(virSecretPtr node);
PyObject * libvirt_virNWFilterPtrWrap(virNWFilterPtr node);
PyObject * libvirt_virNWFilterBindingPtrWrap(virNWFilterBindingPtr node);
PyObject * libvirt_virStreamPtrWrap(virStreamPtr node);
PyObject * libvirt_virDomainCheckpointPtrWrap(virDomainCheckpointPtr node);
PyObject * libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node);