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
This commit is contained in:
parent
91fb5b07d1
commit
7aedf4c898
cinderclient
releasenotes/notes
@ -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 = {}
|
||||
|
@ -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')
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Support create volume from backup in microversion v3.47.
|
Loading…
x
Reference in New Issue
Block a user