From e7ebf7544b7bd0b014e9dffa27d6c4c63f078f6e Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Tue, 10 Jan 2023 13:37:41 +0530 Subject: Add volume revert command This command allows users to revert a volume to a given snapshot. Change-Id: If35ee394d654f5264558a281c835affff524ca50 --- openstackclient/volume/v3/volume.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'openstackclient/volume') diff --git a/openstackclient/volume/v3/volume.py b/openstackclient/volume/v3/volume.py index 07bd434f..4b159688 100644 --- a/openstackclient/volume/v3/volume.py +++ b/openstackclient/volume/v3/volume.py @@ -79,3 +79,36 @@ class VolumeSummary(command.ShowOne): formatters={'metadata': format_columns.DictColumn}, ), ) + + +class VolumeRevertToSnapshot(command.Command): + _description = _("Revert a volume to a snapshot.") + + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + parser.add_argument( + 'snapshot', + metavar="", + help=_('Name or ID of the snapshot to restore. The snapshot must ' + 'be the most recent one known to cinder.'), + ) + return parser + + def take_action(self, parsed_args): + + volume_client = self.app.client_manager.volume + + if volume_client.api_version < api_versions.APIVersion('3.40'): + msg = _( + "--os-volume-api-version 3.40 or greater is required to " + "support the 'volume revert snapshot' command" + ) + raise exceptions.CommandError(msg) + + snapshot = utils.find_resource( + volume_client.volume_snapshots, parsed_args.snapshot) + volume = utils.find_resource( + volume_client.volumes, snapshot.volume_id) + + volume_client.volumes.revert_to_snapshot( + volume=volume, snapshot=snapshot) -- cgit v1.2.1