summaryrefslogtreecommitdiff
path: root/cinderclient/v3/volume_snapshots.py
diff options
context:
space:
mode:
authorBrian Rosmaita <rosmaita.fossdev@gmail.com>2021-08-31 19:10:00 -0400
committerBrian Rosmaita <rosmaita.fossdev@gmail.com>2021-09-02 18:48:28 -0400
commitc3c15f6cb2f50ec5bb2ae561d8fc61f27fae80d2 (patch)
tree0c4b45b90812c8300d061bb2cd0be8d92668b58c /cinderclient/v3/volume_snapshots.py
parent45cebe406fdabd5f3636cb78d85ac934ca735a08 (diff)
downloadpython-cinderclient-c3c15f6cb2f50ec5bb2ae561d8fc61f27fae80d2.tar.gz
Support Block Storage API mv 3.66
Block Storage API mv 3.66 enables snapshots of in-use volumes without requiring a 'force' flag. For backward compatibility, the API silently accepts force=true, even though the 'force' flag is considered invalid for that call. That behavior is replicated in the client, where --force with a true value is silently accepted. The --force option is not advertised in the shell and an option value that doesn't evaluate to true raises an UnsupportedAttribute error. Similar behavior from the v3 Snapshot class, except it raises a ValueError under similar circumstances. Change-Id: I7408d0e3a5ed7f4cbcaf65cf3434ad60aaed511d
Diffstat (limited to 'cinderclient/v3/volume_snapshots.py')
-rw-r--r--cinderclient/v3/volume_snapshots.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/cinderclient/v3/volume_snapshots.py b/cinderclient/v3/volume_snapshots.py
index ce7f4e0..9a94422 100644
--- a/cinderclient/v3/volume_snapshots.py
+++ b/cinderclient/v3/volume_snapshots.py
@@ -15,10 +15,18 @@
"""Volume snapshot interface (v3 extension)."""
+from oslo_utils import strutils
+
from cinderclient import api_versions
from cinderclient.apiclient import base as common_base
from cinderclient import base
+MV_3_66_FORCE_FLAG_ERROR = (
+ "Since microversion 3.66 of the Block Storage API, the 'force' option is "
+ "invalid for this request. For backward compatibility, however, when the "
+ "'force' flag is passed with a value evaluating to True, it is silently "
+ "ignored.")
+
class Snapshot(base.Resource):
"""A Snapshot is a point-in-time snapshot of an openstack volume."""
@@ -80,6 +88,7 @@ class SnapshotManager(base.ManagerWithFind):
"""Manage :class:`Snapshot` resources."""
resource_class = Snapshot
+ @api_versions.wraps("3.0", "3.65")
def create(self, volume_id, force=False,
name=None, description=None, metadata=None):
@@ -106,6 +115,42 @@ class SnapshotManager(base.ManagerWithFind):
'metadata': snapshot_metadata}}
return self._create('/snapshots', body, 'snapshot')
+ @api_versions.wraps("3.66")
+ def create(self, volume_id, force=None, # noqa: F811
+ name=None, description=None, metadata=None):
+
+ """Creates a snapshot of the given volume.
+
+ :param volume_id: The ID of the volume to snapshot.
+ :param force: This is technically not valid after mv 3.66, but the
+ API silently accepts force=True for backward compatibility, so this
+ function will, too
+ :param name: Name of the snapshot
+ :param description: Description of the snapshot
+ :param metadata: Metadata of the snapshot
+ :raises: ValueError if 'force' is not passed with a value that
+ evaluates to true
+ :rtype: :class:`Snapshot`
+ """
+
+ if metadata is None:
+ snapshot_metadata = {}
+ else:
+ snapshot_metadata = metadata
+
+ body = {'snapshot': {'volume_id': volume_id,
+ 'name': name,
+ 'description': description,
+ 'metadata': snapshot_metadata}}
+ if force is not None:
+ try:
+ force = strutils.bool_from_string(force, strict=True)
+ if not force:
+ raise ValueError()
+ except ValueError:
+ raise ValueError(MV_3_66_FORCE_FLAG_ERROR)
+ return self._create('/snapshots', body, 'snapshot')
+
def get(self, snapshot_id):
"""Shows snapshot details.