[Kimchi-devel] [PATCH 05/10] snapshot: Delete a domain snapshot

Aline Manera alinefm at linux.vnet.ibm.com
Wed Nov 12 15:50:56 UTC 2014


On 11/12/2014 11:08 AM, Crístian Viana wrote:
> A new command is added to delete an existing snapshot:
>
> DELETE /vms/<vm-name>/snapshots/<snapshot-name>
>
> It deletes the specified snapshot from the virtual machine.
>
> Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
> ---
>   docs/API.md                     |  5 +++++
>   src/kimchi/i18n.py              |  1 +
>   src/kimchi/mockmodel.py         |  8 ++++++++
>   src/kimchi/model/vmsnapshots.py |  9 +++++++++
>   tests/test_rest.py              | 10 ++++++++++
>   5 files changed, 33 insertions(+)
>
> diff --git a/docs/API.md b/docs/API.md
> index 38c8a59..a6ca0c2 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -204,6 +204,11 @@ Represents a snapshot of the Virtual Machine's primary monitor.
>                  (in seconds, since the epoch).
>       * parent: The name of the parent snapshot, or an empty string if there is
>                 no parent.

> +* **DELETE**: Delete snapshot.
> +    * children: A boolean flag indicating whether the snapshot's children
> +                should also be deleted: if true, the snapshot and its children
> +                will be deleted; if false, only the snapshot will be deleted
> +                (optional, defaults to false).
>   

As it is not implemented yet, I'd say to you remove this description to 
avoid confusion.

>   ### Collection: Templates
>   
> diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
> index 0a6fee3..6a1e193 100644
> --- a/src/kimchi/i18n.py
> +++ b/src/kimchi/i18n.py
> @@ -316,4 +316,5 @@ messages = {
>       "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"),
> +    "KCHSNAP0006E": _("Unable to delete snapshot '%(name)s' on virtual machine '%(vm)s'. Details: %(err)s"),
>   }
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index d4d53fc..50c6e0c 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -1012,6 +1012,14 @@ class MockModel(object):
>           except KeyError:
>               raise NotFoundError('KCHSNAP0003E', {'vm': vm_name, 'name': name})
>   
> +    def vmsnapshot_delete(self, vm_name, name):
> +        vm = self._get_vm(vm_name)
> +
> +        try:
> +            del vm.snapshots[name]
> +        except KeyError:
> +            raise NotFoundError('KCHSNAP0003E', {'vm': vm_name, 'name': name})
> +
>       def tasks_get_list(self):
>           with self.objstore as session:
>               return session.get_list('task')
> diff --git a/src/kimchi/model/vmsnapshots.py b/src/kimchi/model/vmsnapshots.py
> index adc785f..e02108d 100644
> --- a/src/kimchi/model/vmsnapshots.py
> +++ b/src/kimchi/model/vmsnapshots.py
> @@ -133,6 +133,15 @@ class VMSnapshotModel(object):
>                   'created': unicode(snap_xml.creationTime),
>                   'parent': parent}
>   
> +    def delete(self, vm_name, name):
> +        try:
> +            vir_snap = self.get_vmsnapshot(vm_name, name)
> +            vir_snap.delete(0)
> +        except libvirt.libvirtError, e:
> +            raise OperationFailed('KCHSNAP0006E', {'name': name,
> +                                                   'vm': vm_name,
> +                                                   'err': e.message})
> +
>       def get_vmsnapshot(self, vm_name, name):
>           vir_dom = VMModel.get_vm(vm_name, self.conn)
>   
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index 6af0d72..ef0fbf3 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -426,6 +426,16 @@ class RestTests(unittest.TestCase):
>           snaps = json.loads(resp.read())
>           self.assertEquals(2, len(snaps))
>   
> +        # Delete a snapshot
> +        resp = self.request('/vms/test-vm/snapshots/foobar', '{}', 'DELETE')
> +        self.assertEquals(404, resp.status)
> +        resp = self.request('/vms/test-vm/snapshots/%s' % params['name'],
> +                            '{}', 'DELETE')
> +        self.assertEquals(204, resp.status)
> +        resp = self.request('/vms/test-vm/snapshots/%s' % params['name'],
> +                            '{}', 'GET')
> +        self.assertEquals(404, resp.status)
> +
>           # Delete the VM
>           resp = self.request('/vms/test-vm', '{}', 'DELETE')
>           self.assertEquals(204, resp.status)




More information about the Kimchi-devel mailing list