diff options
author | TommyLike <tommylikehu@gmail.com> | 2017-10-30 10:42:16 +0800 |
---|---|---|
committer | TommyLike <tommylikehu@gmail.com> | 2017-12-07 11:31:39 +0800 |
commit | 7aedf4c898dff8e69d73da45668ec3d909f63a44 (patch) | |
tree | b3e403839d77e02fbe2627d0d96f52ea47653a2b | |
parent | 91fb5b07d109c7d16dde64dffe99a63084b76dce (diff) | |
download | python-cinderclient-7aedf4c898dff8e69d73da45668ec3d909f63a44.tar.gz |
Support create volume from backup in client
This patch adds create volume from backup support
in cinderclient.
Change-Id: I01dbcf6b113d88732c174b848be2127ee7242b3c
Implements: blueprint support-create-volume-from-backup
Depends-On: 58d0fb327f9fc980e0c8b84dcd9f64c093285d13
-rw-r--r-- | cinderclient/api_versions.py | 2 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 32 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_volumes.py | 3 | ||||
-rw-r--r-- | cinderclient/v2/shell.py | 5 | ||||
-rw-r--r-- | cinderclient/v3/shell.py | 10 | ||||
-rw-r--r-- | cinderclient/v3/volumes.py | 4 | ||||
-rw-r--r-- | releasenotes/notes/support-create-volume-from-backup-c4e8aac89uy18uy2.yaml | 4 |
7 files changed, 53 insertions, 7 deletions
diff --git a/cinderclient/api_versions.py b/cinderclient/api_versions.py index 26904d1..141ce60 100644 --- a/cinderclient/api_versions.py +++ b/cinderclient/api_versions.py @@ -29,7 +29,7 @@ LOG = logging.getLogger(__name__) # key is a deprecated version and value is an alternative version. DEPRECATED_VERSIONS = {"1": "2"} DEPRECATED_VERSION = "2.0" -MAX_VERSION = "3.46" +MAX_VERSION = "3.47" MIN_VERSION = "3.0" _SUBSTITUTIONS = {} diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index 0161987..6f713ca 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -530,9 +530,39 @@ class ShellTest(utils.TestCase): 'metadata': {}, 'volume_type': '4321', 'description': None, - 'multiattach': False}} + 'multiattach': False, + 'backup_id': None}} self.assert_called_anytime('POST', '/volumes', expected) + @ddt.data({'cmd': '--os-volume-api-version 3.47 create --backup-id 1234', + 'update': {'backup_id': '1234'}}, + {'cmd': '--os-volume-api-version 3.47 create 2', + 'update': {'size': 2}} + ) + @ddt.unpack + def test_create_volume_with_backup(self, cmd, update): + self.run_command(cmd) + self.assert_called('GET', '/volumes/1234') + expected = {'volume': {'imageRef': None, + 'project_id': None, + 'status': 'creating', + 'user_id': None, + 'size': None, + 'availability_zone': None, + 'source_replica': None, + 'attach_status': 'detached', + 'source_volid': None, + 'consistencygroup_id': None, + 'name': None, + 'snapshot_id': None, + 'metadata': {}, + 'volume_type': None, + 'description': None, + 'multiattach': False, + 'backup_id': None}} + expected['volume'].update(update) + self.assert_called_anytime('POST', '/volumes', body=expected) + def test_group_list(self): self.run_command('--os-volume-api-version 3.13 group-list') self.assert_called_anytime('GET', '/groups/detail') diff --git a/cinderclient/tests/unit/v3/test_volumes.py b/cinderclient/tests/unit/v3/test_volumes.py index 75eb30f..e4b7e4a 100644 --- a/cinderclient/tests/unit/v3/test_volumes.py +++ b/cinderclient/tests/unit/v3/test_volumes.py @@ -91,7 +91,8 @@ class VolumesTest(utils.TestCase): 'source_replica': None, 'consistencygroup_id': None, 'multiattach': False, - 'group_id': '1234'}} + 'group_id': '1234', + 'backup_id': None}} cs.assert_called('POST', '/volumes', body=expected) self._assert_request_id(vol) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 6301b7a..dc2c14e 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -210,8 +210,9 @@ class CheckSizeArgForCreate(argparse.Action): def __call__(self, parser, args, values, option_string=None): if ((args.snapshot_id or args.source_volid or args.source_replica) is None and values is None): - parser.error('Size is a required parameter if snapshot ' - 'or source volume is not specified.') + if not hasattr(args, 'backup_id') or args.backup_id is None: + parser.error('Size is a required parameter if snapshot ' + 'or source volume or backup is not specified.') setattr(args, self.dest, values) diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index b5c0ed6..edead62 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -498,6 +498,11 @@ def do_reset_state(cs, args): metavar='<image>', default=None, help='Creates a volume from image (ID or name). Default=None.') +@utils.arg('--backup-id', + metavar='<backup-id>', + default=None, + start_version='3.47', + help='Creates a volume from backup ID. Default=None.') @utils.arg('--image_ref', help=argparse.SUPPRESS) @utils.arg('--name', @@ -585,6 +590,8 @@ def do_create(cs, args): except AttributeError: group_id = None + backup_id = args.backup_id if hasattr(args, 'backup_id') else None + volume = cs.volumes.create(args.size, args.consisgroup_id, group_id, @@ -598,7 +605,8 @@ def do_create(cs, args): metadata=volume_metadata, scheduler_hints=hints, source_replica=args.source_replica, - multiattach=args.multiattach) + multiattach=args.multiattach, + backup_id=backup_id) info = dict() volume = cs.volumes.get(volume.id) diff --git a/cinderclient/v3/volumes.py b/cinderclient/v3/volumes.py index bba714b..99006b4 100644 --- a/cinderclient/v3/volumes.py +++ b/cinderclient/v3/volumes.py @@ -75,7 +75,7 @@ class VolumeManager(volumes.VolumeManager): volume_type=None, user_id=None, project_id=None, availability_zone=None, metadata=None, imageRef=None, scheduler_hints=None, - source_replica=None, multiattach=False): + source_replica=None, multiattach=False, backup_id=None): """Create a volume. :param size: Size of volume in GB @@ -96,6 +96,7 @@ class VolumeManager(volumes.VolumeManager): specified by the client to help boot an instance :param multiattach: Allow the volume to be attached to more than one instance + :param backup_id: ID of the backup :rtype: :class:`Volume` """ if metadata is None: @@ -119,6 +120,7 @@ class VolumeManager(volumes.VolumeManager): 'source_volid': source_volid, 'source_replica': source_replica, 'multiattach': multiattach, + 'backup_id': backup_id }} if group_id: diff --git a/releasenotes/notes/support-create-volume-from-backup-c4e8aac89uy18uy2.yaml b/releasenotes/notes/support-create-volume-from-backup-c4e8aac89uy18uy2.yaml new file mode 100644 index 0000000..af09015 --- /dev/null +++ b/releasenotes/notes/support-create-volume-from-backup-c4e8aac89uy18uy2.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Support create volume from backup in microversion v3.47. |