Allow "cinder backup-delete" to delete multiple backups in one request
While "cinder snapshot-delete" and "cinder delete" allow multiple resources to be deleted in a single command, "cinder backup-delete" request can only delete one backup at a time. Adding this capability to backups in cinderclient. Enables "cinder backup-delete" to delete multiple backups in a single command. With this change the command can be run as below: cinder backup-delete <backup> [<backup>...] DocImpact Closes-Bug: #1543056 Implements: blueprint cli-backup-multiple-deletes Change-Id: I767710bda3b7c358c6525c9a9f074010084e411d
This commit is contained in:
parent
64138007bd
commit
a3dca1599f
|
@ -806,6 +806,12 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||
def delete_backups_76a17945_3c6f_435c_975b_b5685db10b62(self, **kw):
|
||||
return (202, {}, None)
|
||||
|
||||
def delete_backups_1234(self, **kw):
|
||||
return (202, {}, None)
|
||||
|
||||
def delete_backups_5678(self, **kw):
|
||||
return (202, {}, None)
|
||||
|
||||
def post_backups(self, **kw):
|
||||
base_uri = 'http://localhost:8776'
|
||||
tenant_id = '0fa851f6668144cf9cd8c8419c1646c1'
|
||||
|
|
|
@ -415,6 +415,11 @@ class ShellTest(utils.TestCase):
|
|||
self.run_command('backup-create 1234 --snapshot-id 4321')
|
||||
self.assert_called('POST', '/backups')
|
||||
|
||||
def test_multiple_backup_delete(self):
|
||||
self.run_command('backup-delete 1234 5678')
|
||||
self.assert_called_anytime('DELETE', '/backups/1234')
|
||||
self.assert_called('DELETE', '/backups/5678')
|
||||
|
||||
def test_restore(self):
|
||||
self.run_command('backup-restore 1234')
|
||||
self.assert_called('POST', '/backups/1234/restore')
|
||||
|
|
|
@ -1472,13 +1472,22 @@ def do_backup_list(cs, args):
|
|||
utils.print_list(backups, columns)
|
||||
|
||||
|
||||
@utils.arg('backup', metavar='<backup>',
|
||||
help='Name or ID of backup to delete.')
|
||||
@utils.arg('backup', metavar='<backup>', nargs='+',
|
||||
help='Name or ID of backup(s) to delete.')
|
||||
@utils.service_type('volumev2')
|
||||
def do_backup_delete(cs, args):
|
||||
"""Removes a backup."""
|
||||
backup = _find_backup(cs, args.backup)
|
||||
backup.delete()
|
||||
"""Removes one or more backups."""
|
||||
failure_count = 0
|
||||
for backup in args.backup:
|
||||
try:
|
||||
_find_backup(cs, backup).delete()
|
||||
print("Request to delete backup %s has been accepted." % (backup))
|
||||
except Exception as e:
|
||||
failure_count += 1
|
||||
print("Delete for backup %s failed: %s" % (backup, e))
|
||||
if failure_count == len(args.backup):
|
||||
raise exceptions.CommandError("Unable to delete any of the specified "
|
||||
"backups.")
|
||||
|
||||
|
||||
@utils.arg('backup', metavar='<backup>',
|
||||
|
|
Loading…
Reference in New Issue