diff options
author | Alan Bishop <abishop@redhat.com> | 2021-01-11 13:05:11 -0800 |
---|---|---|
committer | Alan Bishop <abishop@redhat.com> | 2021-01-11 13:05:11 -0800 |
commit | 7e3566ed04c8f664f6e1df0614499989f6b3560a (patch) | |
tree | e6c22ef2c34214074b4c5193ca89c539995fc5cd /cinderclient/v3 | |
parent | 1abc1b5d404c523a696f7186bc4c4b6fc7407cad (diff) | |
download | python-cinderclient-7e3566ed04c8f664f6e1df0614499989f6b3560a.tar.gz |
Support backup-restore to a specific volume type or AZ
Enhance the 'backup-restore' shell command to support restoring a
backup to a newly created volume of a specific volume type and/or in a
different AZ. New '--volume-type' and '--availability-zone' arguments
leverage the existing cinder API's ability to create a volume from a
backup, which was added in microversion v3.47.
The shell code is a new v3 implementation, and it drops support for the
v2 command's deprecated '--volume-id' argument.
Change-Id: Ic6645d3b973f8487903c5f57e936ba3b4b3bf005
Diffstat (limited to 'cinderclient/v3')
-rw-r--r-- | cinderclient/v3/shell.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index eaded7e..3065352 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -218,6 +218,74 @@ def do_backup_list(cs, args): AppendFilters.filters = [] +@utils.arg('backup', metavar='<backup>', + help='Name or ID of backup to restore.') +@utils.arg('--volume', metavar='<volume>', + default=None, + help='Name or ID of existing volume to which to restore. ' + 'This is mutually exclusive with --name and takes priority. ' + 'Default=None.') +@utils.arg('--name', metavar='<name>', + default=None, + help='Use the name for new volume creation to restore. ' + 'This is mutually exclusive with --volume and --volume ' + 'takes priority. ' + 'Default=None.') +@utils.arg('--volume-type', + metavar='<volume-type>', + default=None, + start_version='3.47', + help='Volume type for the new volume creation to restore. This ' + 'option is not valid when used with the "volume" option. ' + 'Default=None.') +@utils.arg('--availability-zone', metavar='<AZ>', + default=None, + start_version='3.47', + help='AZ for the new volume creation to restore. By default it ' + 'will be the same as backup AZ. This option is not valid when ' + 'used with the "volume" option. Default=None.') +def do_backup_restore(cs, args): + """Restores a backup.""" + if args.volume: + volume_id = utils.find_volume(cs, args.volume).id + if args.name: + args.name = None + print('Mutually exclusive options are specified simultaneously: ' + '"volume" and "name". The volume option takes priority.') + else: + volume_id = None + + volume_type = getattr(args, 'volume_type', None) + az = getattr(args, 'availability_zone', None) + if (volume_type or az) and args.volume: + msg = ('The "volume-type" and "availability-zone" options are not ' + 'valid when used with the "volume" option.') + raise exceptions.ClientException(code=1, message=msg) + + backup = shell_utils.find_backup(cs, args.backup) + info = {"backup_id": backup.id} + + if volume_type or (az and az != backup.availability_zone): + # Implement restoring a backup to a newly created volume of a + # specific volume type or in a different AZ by using the + # volume-create API. The default volume name matches the pattern + # cinder uses (see I23730834058d88e30be62624ada3b24cdaeaa6f3). + volume_name = args.name or 'restore_backup_%s' % backup.id + volume = cs.volumes.create(size=backup.size, + name=volume_name, + volume_type=volume_type, + availability_zone=az, + backup_id=backup.id) + info['volume_id'] = volume._info['id'] + info['volume_name'] = volume_name + else: + restore = cs.restores.restore(backup.id, volume_id, args.name) + info.update(restore._info) + info.pop('links', None) + + utils.print_dict(info) + + @utils.arg('--detail', action='store_true', help='Show detailed information about pools.') |