diff options
| author | whoami-rajat <rajatdhasmana@gmail.com> | 2022-11-17 18:35:01 +0530 |
|---|---|---|
| committer | whoami-rajat <rajatdhasmana@gmail.com> | 2022-11-21 20:30:09 +0530 |
| commit | bd0727c4f897289722ba639930c9e979cfee534a (patch) | |
| tree | 6a07561a2dba008cf573c2b6473b70161e4d7fbb /openstackclient/volume | |
| parent | 56b0f6de0e950cf23aeb25ff234b307e3857dcfa (diff) | |
| download | python-openstackclient-bd0727c4f897289722ba639930c9e979cfee534a.tar.gz | |
Add option to create volume from backup
Support for creating a volume from backup was added in
microversio 3.47. This patch adds a --backup option
to the volume create command to add that support.
Change-Id: Ib26d2d335475d9aacbf77c0fd7b7cda2ba743943
Diffstat (limited to 'openstackclient/volume')
| -rw-r--r-- | openstackclient/volume/v2/volume.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 1e1fde92..53f6e643 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -71,10 +71,10 @@ def _check_size_arg(args): volume is not specified. """ - if ((args.snapshot or args.source) + if ((args.snapshot or args.source or args.backup) is None and args.size is None): - msg = _("--size is a required option if snapshot " - "or source volume is not specified.") + msg = _("--size is a required option if snapshot, backup " + "or source volume are not specified.") raise exceptions.CommandError(msg) @@ -118,6 +118,12 @@ class CreateVolume(command.ShowOne): help=_("Volume to clone (name or ID)"), ) source_group.add_argument( + "--backup", + metavar="<backup>", + help=_("Restore backup to a volume (name or ID) " + "(supported by --os-volume-api-version 3.47 or later)"), + ) + source_group.add_argument( "--source-replicated", metavar="<replicated-volume>", help=argparse.SUPPRESS, @@ -177,9 +183,16 @@ class CreateVolume(command.ShowOne): def take_action(self, parsed_args): _check_size_arg(parsed_args) + volume_client = self.app.client_manager.volume image_client = self.app.client_manager.image + if parsed_args.backup and not ( + volume_client.api_version.matches('3.47')): + msg = _("--os-volume-api-version 3.47 or greater is required " + "to create a volume from backup.") + raise exceptions.CommandError(msg) + source_volume = None if parsed_args.source: source_volume = utils.find_resource( @@ -213,6 +226,15 @@ class CreateVolume(command.ShowOne): # snapshot size. size = max(size or 0, snapshot_obj.size) + backup = None + if parsed_args.backup: + backup_obj = utils.find_resource( + volume_client.backups, + parsed_args.backup) + backup = backup_obj.id + # As above + size = max(size or 0, backup_obj.size) + volume = volume_client.volumes.create( size=size, snapshot_id=snapshot, @@ -225,6 +247,7 @@ class CreateVolume(command.ShowOne): source_volid=source_volume, consistencygroup_id=consistency_group, scheduler_hints=parsed_args.hint, + backup_id=backup, ) if parsed_args.bootable or parsed_args.non_bootable: |
