Enable "cinder delete" can delete multiple volumes in one request

"nova delete" can delete multiple servers in one request but
"cinder delete" can only delete one volume in one request, it is
better to enhance cinder client to support remove multiple volumes
in one request.

Change-Id: I6a63aa3d7e4c152ae5e45bf2b36d862bdcd6df33
Closes-Bug: #1241941
This commit is contained in:
Jay Lau 2013-10-25 22:57:03 -04:00
parent 7fa5bc3005
commit 4ce8e800c4
6 changed files with 78 additions and 24 deletions

View File

@ -297,13 +297,17 @@ class FakeHTTPClient(base_client.HTTPClient):
# at the very least it's not complete
def get_volumes_detail(self, **kw):
return (200, {}, {"volumes": [
{'id': 1234,
{'id': kw.get('id', 1234),
'name': 'sample-volume',
'attachments': [{'server_id': 1234}]},
]})
def get_volumes_1234(self, **kw):
r = {'volume': self.get_volumes_detail()[2]['volumes'][0]}
r = {'volume': self.get_volumes_detail(id=1234)[2]['volumes'][0]}
return (200, {}, r)
def get_volumes_5678(self, **kw):
r = {'volume': self.get_volumes_detail(id=5678)[2]['volumes'][0]}
return (200, {}, r)
def get_volumes_1234_encryption(self, **kw):
@ -350,6 +354,9 @@ class FakeHTTPClient(base_client.HTTPClient):
def delete_volumes_1234(self, **kw):
return (202, {}, None)
def delete_volumes_5678(self, **kw):
return (202, {}, None)
#
# Quotas
#

View File

@ -117,6 +117,10 @@ class ShellTest(utils.TestCase):
self.run_command('delete 1234')
self.assert_called('DELETE', '/volumes/1234')
def test_delete_multiple(self):
self.run_command('delete 1234 5678')
self.assert_called('DELETE', '/volumes/5678')
def test_backup(self):
self.run_command('backup-create 1234')
self.assert_called('POST', '/backups')

View File

@ -304,13 +304,17 @@ class FakeHTTPClient(base_client.HTTPClient):
# at the very least it's not complete
def get_volumes_detail(self, **kw):
return (200, {}, {"volumes": [
{'id': 1234,
{'id': kw.get('id', 1234),
'name': 'sample-volume',
'attachments': [{'server_id': 1234}]},
]})
def get_volumes_1234(self, **kw):
r = {'volume': self.get_volumes_detail()[2]['volumes'][0]}
r = {'volume': self.get_volumes_detail(id=1234)[2]['volumes'][0]}
return (200, {}, r)
def get_volumes_5678(self, **kw):
r = {'volume': self.get_volumes_detail(id=5678)[2]['volumes'][0]}
return (200, {}, r)
def get_volumes_1234_encryption(self, **kw):
@ -357,6 +361,9 @@ class FakeHTTPClient(base_client.HTTPClient):
def delete_volumes_1234(self, **kw):
return (202, {}, None)
def delete_volumes_5678(self, **kw):
return (202, {}, None)
#
# Quotas
#

View File

@ -95,6 +95,10 @@ class ShellTest(utils.TestCase):
self.run_command('delete 1234')
self.assert_called('DELETE', '/volumes/1234')
def test_delete_multiple(self):
self.run_command('delete 1234 5678')
self.assert_called('DELETE', '/volumes/5678')
def test_backup(self):
self.run_command('backup-create 1234')
self.assert_called('POST', '/backups')

View File

@ -277,22 +277,38 @@ def do_create(cs, args):
_print_volume(volume)
@utils.arg('volume', metavar='<volume>',
help='Name or ID of the volume to delete.')
@utils.arg('volume', metavar='<volume>', nargs='+',
help='Name or ID of the volume(s) to delete.')
@utils.service_type('volume')
def do_delete(cs, args):
"""Remove a volume."""
volume = utils.find_volume(cs, args.volume)
volume.delete()
"""Remove volume(s)."""
failure_count = 0
for volume in args.volume:
try:
utils.find_volume(cs, volume).delete()
except Exception as e:
failure_count += 1
print("Delete for volume %s failed: %s" % (volume, e))
if failure_count == len(args.volume):
raise exceptions.CommandError("Unable to delete any of the specified "
"volumes.")
@utils.arg('volume', metavar='<volume>',
help='Name or ID of the volume to delete.')
@utils.arg('volume', metavar='<volume>', nargs='+',
help='Name or ID of the volume(s) to delete.')
@utils.service_type('volume')
def do_force_delete(cs, args):
"""Attempt forced removal of a volume, regardless of its state."""
volume = utils.find_volume(cs, args.volume)
volume.force_delete()
"""Attempt forced removal of volume(s), regardless of the state(s)."""
failure_count = 0
for volume in args.volume:
try:
utils.find_volume(cs, volume).force_delete()
except Exception as e:
failure_count += 1
print("Delete for volume %s failed: %s" % (volume, e))
if failure_count == len(args.volume):
raise exceptions.CommandError("Unable to force delete any of the "
"specified volumes.")
@utils.arg('volume', metavar='<volume>',

View File

@ -304,23 +304,39 @@ def do_create(cs, args):
@utils.arg('volume',
metavar='<volume>',
help='Name or ID of the volume to delete.')
metavar='<volume>', nargs='+',
help='Name or ID of the volume(s) to delete.')
@utils.service_type('volumev2')
def do_delete(cs, args):
"""Remove a volume."""
volume = utils.find_volume(cs, args.volume)
volume.delete()
"""Remove a volume(s)."""
failure_count = 0
for volume in args.volume:
try:
utils.find_volume(cs, volume).delete()
except Exception as e:
failure_count += 1
print("Delete for volume %s failed: %s" % (volume, e))
if failure_count == len(args.volume):
raise exceptions.CommandError("Unable to delete any of the specified "
"volumes.")
@utils.arg('volume',
metavar='<volume>',
help='Name or ID of the volume to delete.')
metavar='<volume>', nargs='+',
help='Name or ID of the volume(s) to delete.')
@utils.service_type('volumev2')
def do_force_delete(cs, args):
"""Attempt forced removal of a volume, regardless of its state."""
volume = utils.find_volume(cs, args.volume)
volume.force_delete()
"""Attempt forced removal of volume(s), regardless of the state(s)."""
failure_count = 0
for volume in args.volume:
try:
utils.find_volume(cs, volume).force_delete()
except Exception as e:
failure_count += 1
print("Delete for volume %s failed: %s" % (volume, e))
if failure_count == len(args.volume):
raise exceptions.CommandError("Unable to force delete any of the "
"specified volumes.")
@utils.arg('volume', metavar='<volume>',