Merge "Adding command for copying backups"
This commit is contained in:
@@ -74,6 +74,14 @@ class BackupManagerTest(testtools.TestCase):
|
||||
self.backups.create(**args)
|
||||
create_mock.assert_called_with('/backups', body, 'backup')
|
||||
|
||||
def test_copy(self):
|
||||
create_mock = mock.Mock()
|
||||
self.backups._create = create_mock
|
||||
args = {'name': 'test_backup', 'backup': '1'}
|
||||
body = {'backup': args}
|
||||
self.backups.create(**args)
|
||||
create_mock.assert_called_with('/backups', body, 'backup')
|
||||
|
||||
def test_list(self):
|
||||
page_mock = mock.Mock()
|
||||
self.backups._paginated = page_mock
|
||||
|
@@ -50,14 +50,19 @@ class Backups(base.ManagerWithFind):
|
||||
return self._paginated("/backups", "backups", limit, marker,
|
||||
query_strings)
|
||||
|
||||
def create(self, name, instance, description=None, parent_id=None):
|
||||
def create(self, name, instance=None, description=None, parent_id=None,
|
||||
backup=None,):
|
||||
"""Create a new backup from the given instance."""
|
||||
body = {
|
||||
"backup": {
|
||||
"name": name,
|
||||
"instance": instance
|
||||
"name": name
|
||||
}
|
||||
}
|
||||
|
||||
if instance:
|
||||
body['backup']['instance'] = instance
|
||||
if backup:
|
||||
body["backup"]['backup'] = backup
|
||||
if description:
|
||||
body['backup']['description'] = description
|
||||
if parent_id:
|
||||
|
@@ -396,6 +396,30 @@ def do_backup_create(cs, args):
|
||||
_print_instance(backup)
|
||||
|
||||
|
||||
@utils.arg('name', metavar='<name>', help='Name of the backup.')
|
||||
@utils.arg('backup', metavar='<backup>',
|
||||
help='Backup ID of the source backup.',
|
||||
default=None)
|
||||
@utils.arg('--region', metavar='<region>', help='Region where the source '
|
||||
'backup resides.',
|
||||
default=None)
|
||||
@utils.arg('--description', metavar='<description>',
|
||||
default=None,
|
||||
help='An optional description for the backup.')
|
||||
@utils.service_type('database')
|
||||
def do_backup_copy(cs, args):
|
||||
"""Creates a backup from another backup."""
|
||||
if args.backup:
|
||||
backup_ref = {"id": args.backup,
|
||||
"region": args.region}
|
||||
else:
|
||||
backup_ref = None
|
||||
backup = cs.backups.create(args.name, instance=None,
|
||||
description=args.description,
|
||||
parent_id=None, backup=backup_ref,)
|
||||
_print_instance(backup)
|
||||
|
||||
|
||||
# Database related actions
|
||||
|
||||
@utils.arg('instance', metavar='<instance>', help='ID of the instance.')
|
||||
|
Reference in New Issue
Block a user