diff options
author | TommyLike <tommylikehu@gmail.com> | 2017-12-13 10:52:36 +0800 |
---|---|---|
committer | TommyLike <tommylikehu@gmail.com> | 2017-12-14 11:17:29 +0800 |
commit | 9bfd6da08d615e56385df990b72cd0b891ed8868 (patch) | |
tree | 92598f75bbcab502f83777145c420da5436d682c | |
parent | 440f8d82aa8a263c95a3ec6823f4d67ca10a8d4a (diff) | |
download | python-cinderclient-9bfd6da08d615e56385df990b72cd0b891ed8868.tar.gz |
Backup create is not available from 3.0 to 3.42
Backup create command is shielded by patch [1].
[1]: 2255fc99da9752737dcaa96ae4507b646074afb2
Change-Id: I100b8734ee2df4d81e16e2bfdafd81227c20d25e
-rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 30 | ||||
-rw-r--r-- | cinderclient/v3/shell.py | 28 | ||||
-rw-r--r-- | cinderclient/v3/volume_backups.py | 27 |
3 files changed, 69 insertions, 16 deletions
diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index 6f713ca..37dbc49 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -1041,13 +1041,31 @@ class ShellTest(utils.TestCase): mock_time.sleep.call_args_list) self.assertEqual([mock.call(some_id)] * 2, poll_fn.call_args_list) + def test_backup(self): + self.run_command('--os-volume-api-version 3.42 backup-create ' + '--name 1234 1234') + expected = {'backup': {'volume_id': 1234, + 'container': None, + 'name': '1234', + 'description': None, + 'incremental': False, + 'force': False, + 'snapshot_id': None, + }} + self.assert_called('POST', '/backups', body=expected) + def test_backup_with_metadata(self): - cmd = '--os-volume-api-version 3.43 ' - cmd += 'backup-create ' - cmd += '--metadata foo=bar ' - cmd += '1234' - self.run_command(cmd) - self.assert_called('POST', '/backups') + self.run_command('--os-volume-api-version 3.43 backup-create ' + '--metadata foo=bar --name 1234 1234') + expected = {'backup': {'volume_id': 1234, + 'container': None, + 'name': '1234', + 'description': None, + 'incremental': False, + 'force': False, + 'snapshot_id': None, + 'metadata': {'foo': 'bar'}, }} + self.assert_called('POST', '/backups', body=expected) @mock.patch("cinderclient.utils.print_list") def test_snapshot_list_with_userid(self, mock_print_list): diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 922c3a1..3f94b9d 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -2220,7 +2220,7 @@ def do_service_get_log(cs, args): columns = ('Binary', 'Host', 'Prefix', 'Level') utils.print_list(log_levels, columns) -@api_versions.wraps('3.43') + @utils.arg('volume', metavar='<volume>', help='Name or ID of volume to backup.') @utils.arg('--container', metavar='<container>', @@ -2258,6 +2258,7 @@ def do_service_get_log(cs, args): nargs='*', metavar='<key=value>', default=None, + start_version='3.43', help='Metadata key and value pairs. Default=None.') def do_backup_create(cs, args): """Creates a volume backup.""" @@ -2268,14 +2269,23 @@ def do_backup_create(cs, args): args.description = args.display_description volume = utils.find_volume(cs, args.volume) - backup = cs.backups.create(volume.id, - args.container, - args.name, - args.description, - args.incremental, - args.force, - args.snapshot_id, - args.metadata) + if hasattr(args, 'metadata') and args.metadata: + backup = cs.backups.create(volume.id, + args.container, + args.name, + args.description, + args.incremental, + args.force, + args.snapshot_id, + shell_utils.extract_metadata(args)) + else: + backup = cs.backups.create(volume.id, + args.container, + args.name, + args.description, + args.incremental, + args.force, + args.snapshot_id) info = {"volume_id": volume.id} info.update(backup._info) diff --git a/cinderclient/v3/volume_backups.py b/cinderclient/v3/volume_backups.py index 555ace8..323daff 100644 --- a/cinderclient/v3/volume_backups.py +++ b/cinderclient/v3/volume_backups.py @@ -39,7 +39,31 @@ class VolumeBackupManager(volume_backups.VolumeBackupManager): return self._update("/backups/%s" % base.getid(backup), body) - @api_versions.wraps("3.43") + @api_versions.wraps("3.0") + def create(self, volume_id, container=None, + name=None, description=None, + incremental=False, force=False, + snapshot_id=None): + """Creates a volume backup. + + :param volume_id: The ID of the volume to backup. + :param container: The name of the backup service container. + :param name: The name of the backup. + :param description: The description of the backup. + :param incremental: Incremental backup. + :param force: If True, allows an in-use volume to be backed up. + :rtype: :class:`VolumeBackup` + """ + body = {'backup': {'volume_id': volume_id, + 'container': container, + 'name': name, + 'description': description, + 'incremental': incremental, + 'force': force, + 'snapshot_id': snapshot_id, }} + return self._create('/backups', body, 'backup') + + @api_versions.wraps("3.43") # noqa: F811 def create(self, volume_id, container=None, name=None, description=None, incremental=False, force=False, @@ -56,6 +80,7 @@ class VolumeBackupManager(volume_backups.VolumeBackupManager): :param metadata: Key Value pairs :rtype: :class:`VolumeBackup` """ + # pylint: disable=function-redefined body = {'backup': {'volume_id': volume_id, 'container': container, 'name': name, |