Accept deleting multiple snapshots in one shot

In bug 1241941 the delete and force-delete commands were updated to
accept multiple volumes for deleting in the same call. This patch adds
the same behaviour to the snapshot-delete command.

Closes-Bug: #1284540
Change-Id: I5e4bf8641d7fd261fa24b03832bad08007e43c12
This commit is contained in:
Xavier Queralt 2014-02-25 10:25:24 +01:00
parent 5278bdb0c5
commit 5a080b4d47
7 changed files with 41 additions and 10 deletions

@ -285,6 +285,9 @@ class FakeHTTPClient(base_client.HTTPClient):
def delete_snapshots_1234(self, **kw):
return (202, {}, {})
def delete_snapshots_5678(self, **kw):
return (202, {}, {})
#
# Volumes
#

@ -359,3 +359,7 @@ class ShellTest(utils.TestCase):
def test_quota_delete(self):
self.run_command('quota-delete 1234')
self.assert_called('DELETE', '/os-quota-sets/1234')
def test_snapshot_delete_multiple(self):
self.run_command('snapshot-delete 1234 5678')
self.assert_called('DELETE', '/snapshots/5678')

@ -294,6 +294,9 @@ class FakeHTTPClient(base_client.HTTPClient):
def delete_snapshots_1234(self, **kw):
return (202, {}, {})
def delete_snapshots_5678(self, **kw):
return (202, {}, {})
#
# Volumes
#

@ -359,3 +359,7 @@ class ShellTest(utils.TestCase):
def test_quota_delete(self):
self.run_command('quota-delete 1234')
self.assert_called('DELETE', '/os-quota-sets/1234')
def test_snapshot_delete_multiple(self):
self.run_command('snapshot-delete 5678')
self.assert_called('DELETE', '/snapshots/5678')

@ -481,13 +481,21 @@ def do_snapshot_create(cs, args):
@utils.arg('snapshot',
metavar='<snapshot>',
help='Name or ID of the snapshot to delete.')
metavar='<snapshot>', nargs='+',
help='Name or ID of the snapshot(s) to delete.')
@utils.service_type('volume')
def do_snapshot_delete(cs, args):
"""Remove a snapshot."""
snapshot = _find_volume_snapshot(cs, args.snapshot)
snapshot.delete()
"""Remove one or more snapshots."""
failure_count = 0
for snapshot in args.snapshot:
try:
_find_volume_snapshot(cs, snapshot).delete()
except Exception as e:
failure_count += 1
print("Delete for snapshot %s failed: %s" % (snapshot, e))
if failure_count == len(args.snapshot):
raise exceptions.CommandError("Unable to delete any of the specified "
"snapshots.")
@utils.arg('snapshot', metavar='<snapshot>',

@ -531,13 +531,21 @@ def do_snapshot_create(cs, args):
@utils.arg('snapshot',
metavar='<snapshot>',
help='Name or ID of the snapshot to delete.')
metavar='<snapshot>', nargs='+',
help='Name or ID of the snapshot(s) to delete.')
@utils.service_type('volumev2')
def do_snapshot_delete(cs, args):
"""Remove a snapshot."""
snapshot = _find_volume_snapshot(cs, args.snapshot)
snapshot.delete()
"""Remove one or more snapshots."""
failure_count = 0
for snapshot in args.snapshot:
try:
_find_volume_snapshot(cs, snapshot).delete()
except Exception as e:
failure_count += 1
print("Delete for snapshot %s failed: %s" % (snapshot, e))
if failure_count == len(args.snapshot):
raise exceptions.CommandError("Unable to delete any of the specified "
"snapshots.")
@utils.arg('snapshot', metavar='<snapshot>',

@ -34,6 +34,7 @@ MASTER
------
.. _1255905: http://bugs.launchpad.net/python-cinderclient/+bug/1255905
.. _1267168: http://bugs.launchpad.net/python-cinderclient/+bug/1267168
.. _1284540: http://bugs.launchpad.net/python-cinderclient/+bug/1284540
1.0.8
-----