summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
authorwhoami-rajat <rajatdhasmana@gmail.com>2023-01-10 13:37:41 +0530
committerwhoami-rajat <rajatdhasmana@gmail.com>2023-02-16 04:33:40 +0000
commite7ebf7544b7bd0b014e9dffa27d6c4c63f078f6e (patch)
treeee86dd9517b64975edabe170e8b3067d4ddc581b /openstackclient/volume
parent1e0880eda83ed7d338e5d09e98b9d1982068cd0b (diff)
downloadpython-openstackclient-e7ebf7544b7bd0b014e9dffa27d6c4c63f078f6e.tar.gz
Add volume revert command
This command allows users to revert a volume to a given snapshot. Change-Id: If35ee394d654f5264558a281c835affff524ca50
Diffstat (limited to 'openstackclient/volume')
-rw-r--r--openstackclient/volume/v3/volume.py33
1 files changed, 33 insertions, 0 deletions
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="<snapshot>",
+ 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)