summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2021-06-09 11:57:32 +0100
committerStephen Finucane <sfinucan@redhat.com>2021-06-10 11:21:25 +0100
commit7f66dfe0e3e8720e847211494c185d7d4983ba5b (patch)
tree805730953147f979d752398b57f0dfb48003b85b /openstackclient/volume
parent34de2d3352aaef5c1bb86a5441cc8781e03b5587 (diff)
downloadpython-openstackclient-7f66dfe0e3e8720e847211494c185d7d4983ba5b.tar.gz
volume: Add more missing 'volume backup *' options
Add an additional '--no-property' option to the 'volume backup set' command, along with a brand spanking new 'volume backup unset' command. Change-Id: Id7ca925e0ada03e259f0ecaf3e02af11c900641e Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/volume')
-rw-r--r--openstackclient/volume/v2/volume_backup.py87
1 files changed, 85 insertions, 2 deletions
diff --git a/openstackclient/volume/v2/volume_backup.py b/openstackclient/volume/v2/volume_backup.py
index a171164e..96b22a68 100644
--- a/openstackclient/volume/v2/volume_backup.py
+++ b/openstackclient/volume/v2/volume_backup.py
@@ -14,6 +14,7 @@
"""Volume v2 Backup action implementations"""
+import copy
import functools
import logging
@@ -406,10 +407,20 @@ class SetVolumeBackup(command.Command):
),
)
parser.add_argument(
+ '--no-property',
+ action='store_true',
+ help=_(
+ 'Remove all properties from this backup '
+ '(specify both --no-property and --property to remove the '
+ 'current properties before setting new properties)'
+ ),
+ )
+ parser.add_argument(
'--property',
metavar='<key=value>',
action=parseractions.KeyValueAction,
dest='properties',
+ default={},
help=_(
'Set a property on this backup '
'(repeat option to set multiple values) '
@@ -454,6 +465,14 @@ class SetVolumeBackup(command.Command):
kwargs['description'] = parsed_args.description
+ if parsed_args.no_property:
+ if volume_client.api_version < api_versions.APIVersion('3.43'):
+ msg = _(
+ '--os-volume-api-version 3.43 or greater is required to '
+ 'support the --no-property option'
+ )
+ raise exceptions.CommandError(msg)
+
if parsed_args.properties:
if volume_client.api_version < api_versions.APIVersion('3.43'):
msg = _(
@@ -462,13 +481,20 @@ class SetVolumeBackup(command.Command):
)
raise exceptions.CommandError(msg)
- kwargs['metadata'] = parsed_args.properties
+ if volume_client.api_version >= api_versions.APIVersion('3.43'):
+ metadata = copy.deepcopy(backup.metadata)
+
+ if parsed_args.no_property:
+ metadata = {}
+
+ metadata.update(parsed_args.properties)
+ kwargs['metadata'] = metadata
if kwargs:
try:
volume_client.backups.update(backup.id, **kwargs)
except Exception as e:
- LOG.error("Failed to update backup name or description: %s", e)
+ LOG.error("Failed to update backup: %s", e)
result += 1
if result > 0:
@@ -476,6 +502,63 @@ class SetVolumeBackup(command.Command):
raise exceptions.CommandError(msg)
+class UnsetVolumeBackup(command.Command):
+ """Unset volume backup properties.
+
+ This command requires ``--os-volume-api-version`` 3.43 or greater.
+ """
+
+ def get_parser(self, prog_name):
+ parser = super().get_parser(prog_name)
+ parser.add_argument(
+ 'backup',
+ metavar='<backup>',
+ help=_('Backup to modify (name or ID)')
+ )
+ parser.add_argument(
+ '--property',
+ metavar='<key>',
+ action='append',
+ dest='properties',
+ help=_(
+ 'Property to remove from this backup '
+ '(repeat option to unset multiple values) '
+ ),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ volume_client = self.app.client_manager.volume
+
+ if volume_client.api_version < api_versions.APIVersion('3.43'):
+ msg = _(
+ '--os-volume-api-version 3.43 or greater is required to '
+ 'support the --property option'
+ )
+ raise exceptions.CommandError(msg)
+
+ backup = utils.find_resource(
+ volume_client.backups, parsed_args.backup)
+ metadata = copy.deepcopy(backup.metadata)
+
+ for key in parsed_args.properties:
+ if key not in metadata:
+ # ignore invalid properties but continue
+ LOG.warning(
+ "'%s' is not a valid property for backup '%s'",
+ key, parsed_args.backup,
+ )
+ continue
+
+ del metadata[key]
+
+ kwargs = {
+ 'metadata': metadata,
+ }
+
+ volume_client.backups.update(backup.id, **kwargs)
+
+
class ShowVolumeBackup(command.ShowOne):
_description = _("Display volume backup details")