VM snapshot support in libvirt may not work correctly with some image
types, like 'raw'.
To make sure snapshots work correctly, only allow them to be taken on
VMs with 'qcow2' images, which is the most supported image type for that
operation.
Signed-off-by: Crístian Viana <vianac(a)linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 1 +
src/kimchi/model/vmsnapshots.py | 17 +++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 58d1f36..e43fe9c 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -319,6 +319,7 @@ messages = {
"KCHSNAP0006E": _("Unable to delete snapshot '%(name)s' on
virtual machine '%(vm)s'. Details: %(err)s"),
"KCHSNAP0008E": _("Unable to retrieve current snapshot on virtual
machine '%(vm)s'. Details: %(err)s"),
"KCHSNAP0009E": _("Unable to revert virtual machine '%(vm)s'
to snapshot '%(name)s'. Details: %(err)s"),
+ "KCHSNAP0010E": _("Unable to create snapshot on virtual machine
'%(vm)s' because it contains a disk with format '%(format)s'; only
'qcow2' is supported."),
"KCHCPUINF0001E": _("The number of vCPUs is too large for this
system."),
"KCHCPUINF0002E": _("Invalid vCPU/topology combination."),
diff --git a/src/kimchi/model/vmsnapshots.py b/src/kimchi/model/vmsnapshots.py
index 0da9dc3..bb9bfaa 100644
--- a/src/kimchi/model/vmsnapshots.py
+++ b/src/kimchi/model/vmsnapshots.py
@@ -27,6 +27,7 @@ from lxml.builder import E
from kimchi.exception import InvalidOperation, NotFoundError, OperationFailed
from kimchi.model.tasks import TaskModel
from kimchi.model.vms import DOM_STATE_MAP, VMModel
+from kimchi.model.vmstorages import VMStorageModel, VMStoragesModel
from kimchi.utils import add_task
@@ -35,12 +36,14 @@ class VMSnapshotsModel(object):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.task = TaskModel(**kargs)
+ self.vmstorages = VMStoragesModel(**kargs)
+ self.vmstorage = VMStorageModel(**kargs)
def create(self, vm_name, params={}):
"""Create a snapshot with the current domain state.
- The VM must be stopped before creating a snapshot on it; otherwise, an
- exception will be raised.
+ The VM must be stopped and contain only disks with format 'qcow2';
+ otherwise an exception will be raised.
Parameters:
vm_name -- the name of the VM where the snapshot will be created.
@@ -55,6 +58,16 @@ class VMSnapshotsModel(object):
if DOM_STATE_MAP[vir_dom.info()[0]] != u'shutoff':
raise InvalidOperation('KCHSNAP0001E', {'vm': vm_name})
+ # if the VM has a non-CDROM disk with type 'raw', abort.
+ for storage_name in self.vmstorages.get_list(vm_name):
+ storage = self.vmstorage.lookup(vm_name, storage_name)
+ type = storage['type']
+ format = storage['format']
+
+ if type != u'cdrom' and format != u'qcow2':
+ raise InvalidOperation('KCHSNAP0010E', {'vm': vm_name,
+ 'format': format})
+
name = params.get('name', unicode(int(time.time())))
task_params = {'vm_name': vm_name, 'name': name}
--
1.9.3