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 <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2023-05-29 18:01:22 +01:00
parent e0c7cef434
commit a3410cd4f7
3 changed files with 57 additions and 3 deletions

View File

@ -132,6 +132,8 @@ class TestTypeCreate(TestType):
'--multiattach', '--multiattach',
'--cacheable', '--cacheable',
'--replicated', '--replicated',
'--availability-zone',
'az1',
self.new_volume_type.name, self.new_volume_type.name,
] ]
verifylist = [ verifylist = [
@ -139,6 +141,7 @@ class TestTypeCreate(TestType):
('multiattach', True), ('multiattach', True),
('cacheable', True), ('cacheable', True),
('replicated', True), ('replicated', True),
('availability_zones', ['az1']),
('name', self.new_volume_type.name), ('name', self.new_volume_type.name),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -153,6 +156,7 @@ class TestTypeCreate(TestType):
'multiattach': '<is> True', 'multiattach': '<is> True',
'cacheable': '<is> True', 'cacheable': '<is> True',
'replication_enabled': '<is> True', 'replication_enabled': '<is> True',
'RESKEY:availability_zones': 'az1',
} }
) )
@ -442,6 +446,8 @@ class TestTypeList(TestType):
"--multiattach", "--multiattach",
"--cacheable", "--cacheable",
"--replicated", "--replicated",
"--availability-zone",
"az1",
] ]
verifylist = [ verifylist = [
("encryption_type", False), ("encryption_type", False),
@ -452,6 +458,7 @@ class TestTypeList(TestType):
("multiattach", True), ("multiattach", True),
("cacheable", True), ("cacheable", True),
("replicated", True), ("replicated", True),
("availability_zones", ["az1"]),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -463,6 +470,7 @@ class TestTypeList(TestType):
"multiattach": "<is> True", "multiattach": "<is> True",
"cacheable": "<is> True", "cacheable": "<is> True",
"replication_enabled": "<is> True", "replication_enabled": "<is> True",
"RESKEY:availability_zones": "az1",
} }
}, },
is_public=None, is_public=None,
@ -607,6 +615,8 @@ class TestTypeSet(TestType):
'--multiattach', '--multiattach',
'--cacheable', '--cacheable',
'--replicated', '--replicated',
'--availability-zone',
'az1',
self.volume_type.id, self.volume_type.id,
] ]
verifylist = [ verifylist = [
@ -616,6 +626,7 @@ class TestTypeSet(TestType):
('multiattach', True), ('multiattach', True),
('cacheable', True), ('cacheable', True),
('replicated', True), ('replicated', True),
('availability_zones', ['az1']),
('volume_type', self.volume_type.id), ('volume_type', self.volume_type.id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -629,6 +640,7 @@ class TestTypeSet(TestType):
'multiattach': '<is> True', 'multiattach': '<is> True',
'cacheable': '<is> True', 'cacheable': '<is> True',
'replication_enabled': '<is> True', 'replication_enabled': '<is> True',
'RESKEY:availability_zones': 'az1',
} }
) )
self.volume_type_access_mock.add_project_access.assert_not_called() self.volume_type_access_mock.add_project_access.assert_not_called()

View File

@ -176,6 +176,16 @@ class CreateVolumeType(command.ShowOne):
"(requires driver support)" "(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:<az>') " # noqa: E501
"(repeat option to set multiple availabilty zones)"
),
)
parser.add_argument( parser.add_argument(
'--project', '--project',
metavar='<project>', metavar='<project>',
@ -274,6 +284,10 @@ class CreateVolumeType(command.ShowOne):
properties['cacheable'] = '<is> True' properties['cacheable'] = '<is> True'
if parsed_args.replicated: if parsed_args.replicated:
properties['replication_enabled'] = '<is> True' properties['replication_enabled'] = '<is> True'
if parsed_args.availability_zones:
properties['RESKEY:availability_zones'] = ','.join(
parsed_args.availability_zones
)
if properties: if properties:
result = volume_type.set_keys(properties) result = volume_type.set_keys(properties)
volume_type._info.update( volume_type._info.update(
@ -435,6 +449,16 @@ class ListVolumeType(command.Lister):
"(supported by --os-volume-api-version 3.52 or above)" "(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:<az>') " # noqa: E501
"(repeat option to filter on multiple availabilty zones)"
),
)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -472,6 +496,10 @@ class ListVolumeType(command.Lister):
properties['cacheable'] = '<is> True' properties['cacheable'] = '<is> True'
if parsed_args.replicated: if parsed_args.replicated:
properties['replication_enabled'] = '<is> True' properties['replication_enabled'] = '<is> True'
if parsed_args.availability_zones:
properties['RESKEY:availability_zones'] = ','.join(
parsed_args.availability_zones
)
if properties: if properties:
if volume_client.api_version < api_versions.APIVersion('3.52'): if volume_client.api_version < api_versions.APIVersion('3.52'):
msg = _( msg = _(
@ -590,6 +618,16 @@ class SetVolumeType(command.Command):
"(requires driver support)" "(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:<az>') " # noqa: E501
"(repeat option to set multiple availabilty zones)"
),
)
parser.add_argument( parser.add_argument(
'--project', '--project',
metavar='<project>', metavar='<project>',
@ -706,6 +744,10 @@ class SetVolumeType(command.Command):
properties['cacheable'] = '<is> True' properties['cacheable'] = '<is> True'
if parsed_args.replicated: if parsed_args.replicated:
properties['replication_enabled'] = '<is> True' properties['replication_enabled'] = '<is> True'
if parsed_args.availability_zones:
properties['RESKEY:availability_zones'] = ','.join(
parsed_args.availability_zones
)
if properties: if properties:
try: try:
volume_type.set_keys(properties) volume_type.set_keys(properties)

View File

@ -2,6 +2,6 @@
features: features:
- | - |
The ``volume type create``, ``volume type set``, ``volume type list`` The ``volume type create``, ``volume type set``, ``volume type list``
commands now accept three new options - ``--multiattach``, ``--cacheable``, commands now accept four new options - ``--multiattach``, ``--cacheable``,
and ``--replicated`` - which are short cuts for setting or filtering on ``--replicated``, and ``--availability-zone`` - which are short cuts for
the relevant properties on the volume type. setting or filtering on the relevant properties on the volume type.