From a3410cd4f785ec188973d85509448a320e882514 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 29 May 2023 18:01:22 +0100 Subject: [PATCH] volume: Add alias for volume type AZs Another quality of life improvements. The key for this one is weird and the whole thing is a little more involved, hence why it's kept separate. Change-Id: I75aa85f27905104dc84fffe823c01b4c90a6a822 Signed-off-by: Stephen Finucane --- .../tests/unit/volume/v2/test_volume_type.py | 12 ++++++ openstackclient/volume/v2/volume_type.py | 42 +++++++++++++++++++ ...ume-type-extra-specs-22a22fcb6e269832.yaml | 6 +-- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/openstackclient/tests/unit/volume/v2/test_volume_type.py b/openstackclient/tests/unit/volume/v2/test_volume_type.py index e2b503b9b9..2157eabccd 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume_type.py +++ b/openstackclient/tests/unit/volume/v2/test_volume_type.py @@ -132,6 +132,8 @@ class TestTypeCreate(TestType): '--multiattach', '--cacheable', '--replicated', + '--availability-zone', + 'az1', self.new_volume_type.name, ] verifylist = [ @@ -139,6 +141,7 @@ class TestTypeCreate(TestType): ('multiattach', True), ('cacheable', True), ('replicated', True), + ('availability_zones', ['az1']), ('name', self.new_volume_type.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -153,6 +156,7 @@ class TestTypeCreate(TestType): 'multiattach': ' True', 'cacheable': ' True', 'replication_enabled': ' True', + 'RESKEY:availability_zones': 'az1', } ) @@ -442,6 +446,8 @@ class TestTypeList(TestType): "--multiattach", "--cacheable", "--replicated", + "--availability-zone", + "az1", ] verifylist = [ ("encryption_type", False), @@ -452,6 +458,7 @@ class TestTypeList(TestType): ("multiattach", True), ("cacheable", True), ("replicated", True), + ("availability_zones", ["az1"]), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -463,6 +470,7 @@ class TestTypeList(TestType): "multiattach": " True", "cacheable": " True", "replication_enabled": " True", + "RESKEY:availability_zones": "az1", } }, is_public=None, @@ -607,6 +615,8 @@ class TestTypeSet(TestType): '--multiattach', '--cacheable', '--replicated', + '--availability-zone', + 'az1', self.volume_type.id, ] verifylist = [ @@ -616,6 +626,7 @@ class TestTypeSet(TestType): ('multiattach', True), ('cacheable', True), ('replicated', True), + ('availability_zones', ['az1']), ('volume_type', self.volume_type.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -629,6 +640,7 @@ class TestTypeSet(TestType): 'multiattach': ' True', 'cacheable': ' True', 'replication_enabled': ' True', + 'RESKEY:availability_zones': 'az1', } ) self.volume_type_access_mock.add_project_access.assert_not_called() diff --git a/openstackclient/volume/v2/volume_type.py b/openstackclient/volume/v2/volume_type.py index c8e5627431..ebb364b5d8 100644 --- a/openstackclient/volume/v2/volume_type.py +++ b/openstackclient/volume/v2/volume_type.py @@ -176,6 +176,16 @@ class CreateVolumeType(command.ShowOne): "(requires driver support)" ), ) + parser.add_argument( + '--availability-zone', + action='append', + dest='availability_zones', + help=_( + "Set an availability zone for this volume type " + "(this is an alias for '--property RESKEY:availability_zones:') " # noqa: E501 + "(repeat option to set multiple availabilty zones)" + ), + ) parser.add_argument( '--project', metavar='', @@ -274,6 +284,10 @@ class CreateVolumeType(command.ShowOne): properties['cacheable'] = ' True' if parsed_args.replicated: properties['replication_enabled'] = ' True' + if parsed_args.availability_zones: + properties['RESKEY:availability_zones'] = ','.join( + parsed_args.availability_zones + ) if properties: result = volume_type.set_keys(properties) volume_type._info.update( @@ -435,6 +449,16 @@ class ListVolumeType(command.Lister): "(supported by --os-volume-api-version 3.52 or above)" ), ) + parser.add_argument( + '--availability-zone', + action='append', + dest='availability_zones', + help=_( + "List only volume types with this availability configured " + "(this is an alias for '--property RESKEY:availability_zones:') " # noqa: E501 + "(repeat option to filter on multiple availabilty zones)" + ), + ) return parser def take_action(self, parsed_args): @@ -472,6 +496,10 @@ class ListVolumeType(command.Lister): properties['cacheable'] = ' True' if parsed_args.replicated: properties['replication_enabled'] = ' True' + if parsed_args.availability_zones: + properties['RESKEY:availability_zones'] = ','.join( + parsed_args.availability_zones + ) if properties: if volume_client.api_version < api_versions.APIVersion('3.52'): msg = _( @@ -590,6 +618,16 @@ class SetVolumeType(command.Command): "(requires driver support)" ), ) + parser.add_argument( + '--availability-zone', + action='append', + dest='availability_zones', + help=_( + "Set an availability zone for this volume type " + "(this is an alias for '--property RESKEY:availability_zones:') " # noqa: E501 + "(repeat option to set multiple availabilty zones)" + ), + ) parser.add_argument( '--project', metavar='', @@ -706,6 +744,10 @@ class SetVolumeType(command.Command): properties['cacheable'] = ' True' if parsed_args.replicated: properties['replication_enabled'] = ' True' + if parsed_args.availability_zones: + properties['RESKEY:availability_zones'] = ','.join( + parsed_args.availability_zones + ) if properties: try: volume_type.set_keys(properties) diff --git a/releasenotes/notes/volume-type-extra-specs-22a22fcb6e269832.yaml b/releasenotes/notes/volume-type-extra-specs-22a22fcb6e269832.yaml index fb30f98cf6..aab21d00a3 100644 --- a/releasenotes/notes/volume-type-extra-specs-22a22fcb6e269832.yaml +++ b/releasenotes/notes/volume-type-extra-specs-22a22fcb6e269832.yaml @@ -2,6 +2,6 @@ features: - | The ``volume type create``, ``volume type set``, ``volume type list`` - commands now accept three new options - ``--multiattach``, ``--cacheable``, - and ``--replicated`` - which are short cuts for setting or filtering on - the relevant properties on the volume type. + commands now accept four new options - ``--multiattach``, ``--cacheable``, + ``--replicated``, and ``--availability-zone`` - which are short cuts for + setting or filtering on the relevant properties on the volume type.