A new command is added to list all existing snapshots on a virtual
machine:
GET /vms/<vm-name>/snapshots
It returns a list of snapshot structures (as returned by 'GET
/vms/<vm-name>/snapshots/<snapshot-name>') which exist on a virtual
machine.
Signed-off-by: Crístian Viana <vianac(a)linux.vnet.ibm.com>
---
docs/API.md | 1 +
src/kimchi/i18n.py | 1 +
src/kimchi/mockmodel.py | 4 ++++
src/kimchi/model/vmsnapshots.py | 11 +++++++++++
tests/test_rest.py | 18 ++++++++++++++++++
5 files changed, 35 insertions(+)
diff --git a/docs/API.md b/docs/API.md
index 44cc825..590cb6c 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -193,6 +193,7 @@ Represents a snapshot of the Virtual Machine's primary monitor.
* **POST**: Create a new snapshot on a VM.
* name: The snapshot name (optional, defaults to a value based on the
current time).
+* **GET**: Retrieve a list of snapshots on a VM.
### Sub-resource: Snapshot
**URI:** /vms/*:name*/snapshots/*:snapshot*
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 159a2d2..0a6fee3 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -315,4 +315,5 @@ messages = {
"KCHSNAP0002E": _("Unable to create snapshot '%(name)s' on
virtual machine '%(vm)s'. Details: %(err)s"),
"KCHSNAP0003E": _("Snapshot '%(name)s' does not exist on
virtual machine '%(vm)s'."),
"KCHSNAP0004E": _("Unable to retrieve snapshot '%(name)s' on
virtual machine '%(vm)s'. Details: %(err)s"),
+ "KCHSNAP0005E": _("Unable to list snapshots on virtual machine
'%(vm)s'. Details: %(err)s"),
}
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index b6fb531..11b4394 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -996,6 +996,10 @@ class MockModel(object):
cb('OK', True)
+ def vmsnapshots_get_list(self, vm_name):
+ vm = self._get_vm(vm_name)
+ return sorted(vm.snapshots.keys(), key=unicode.lower)
+
def vmsnapshot_lookup(self, vm_name, name):
vm = self._get_vm(vm_name)
diff --git a/src/kimchi/model/vmsnapshots.py b/src/kimchi/model/vmsnapshots.py
index 1ce6e9f..b3fb6d5 100644
--- a/src/kimchi/model/vmsnapshots.py
+++ b/src/kimchi/model/vmsnapshots.py
@@ -91,6 +91,17 @@ class VMSnapshotsModel(object):
cb('OK', True)
+ def get_list(self, vm_name):
+ vir_dom = VMModel.get_vm(vm_name, self.conn)
+
+ try:
+ vir_snaps = vir_dom.listAllSnapshots(0)
+ return sorted([s.getName().decode('utf-8') for s in vir_snaps],
+ key=unicode.lower)
+ except libvirt.libvirtError, e:
+ raise OperationFailed('KCHSNAP0005E',
+ {'vm': vm_name, 'err': e.message})
+
class VMSnapshotModel(object):
def __init__(self, **kargs):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index e6ce715..6af0d72 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -408,6 +408,24 @@ class RestTests(unittest.TestCase):
self.assertEquals(u'', snap['parent'])
self.assertEquals(u'shutoff', snap['state'])
+ resp = self.request('/vms/test-vm/snapshots', '{}',
'GET')
+ self.assertEquals(200, resp.status)
+ snaps = json.loads(resp.read())
+ self.assertEquals(1, len(snaps))
+
+ resp = self.request('/vms/test-vm/snapshots', '{}',
'POST')
+ self.assertEquals(202, resp.status)
+ task = json.loads(resp.read())
+ wait_task(self._task_lookup, task['id'])
+ resp = self.request('/tasks/%s' % task['id'], '{}',
'GET')
+ task = json.loads(resp.read())
+ self.assertEquals('finished', task['status'])
+
+ resp = self.request('/vms/test-vm/snapshots', '{}',
'GET')
+ self.assertEquals(200, resp.status)
+ snaps = json.loads(resp.read())
+ self.assertEquals(2, len(snaps))
+
# Delete the VM
resp = self.request('/vms/test-vm', '{}', 'DELETE')
self.assertEquals(204, resp.status)
--
1.9.3