From 5a080b4d474a9e8ada54f4fa8c7b4a088d13f965 Mon Sep 17 00:00:00 2001 From: Xavier Queralt Date: Tue, 25 Feb 2014 10:25:24 +0100 Subject: [PATCH] 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 --- cinderclient/tests/v1/fakes.py | 3 +++ cinderclient/tests/v1/test_shell.py | 4 ++++ cinderclient/tests/v2/fakes.py | 3 +++ cinderclient/tests/v2/test_shell.py | 4 ++++ cinderclient/v1/shell.py | 18 +++++++++++++----- cinderclient/v2/shell.py | 18 +++++++++++++----- doc/source/index.rst | 1 + 7 files changed, 41 insertions(+), 10 deletions(-) diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index d24cf053f..cf89b8e81 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -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 # diff --git a/cinderclient/tests/v1/test_shell.py b/cinderclient/tests/v1/test_shell.py index 586caa240..dac9bc550 100644 --- a/cinderclient/tests/v1/test_shell.py +++ b/cinderclient/tests/v1/test_shell.py @@ -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') diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index eebc58610..8eb97f0fd 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -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 # diff --git a/cinderclient/tests/v2/test_shell.py b/cinderclient/tests/v2/test_shell.py index c9a92aa2e..f18db4a18 100644 --- a/cinderclient/tests/v2/test_shell.py +++ b/cinderclient/tests/v2/test_shell.py @@ -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') diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index 6a11c2a9f..66155007e 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -481,13 +481,21 @@ def do_snapshot_create(cs, args): @utils.arg('snapshot', - metavar='', - help='Name or ID of the snapshot to delete.') + metavar='', 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='', diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index e4c3da322..cbb97eba6 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -531,13 +531,21 @@ def do_snapshot_create(cs, args): @utils.arg('snapshot', - metavar='', - help='Name or ID of the snapshot to delete.') + metavar='', 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='', diff --git a/doc/source/index.rst b/doc/source/index.rst index 04e70fd04..9aa6acafc 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -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 -----