Skip to content

Commit a3410cd

Browse files
committed
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>
1 parent e0c7cef commit a3410cd

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

openstackclient/tests/unit/volume/v2/test_volume_type.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,16 @@ def test_type_create_with_properties(self):
132132
'--multiattach',
133133
'--cacheable',
134134
'--replicated',
135+
'--availability-zone',
136+
'az1',
135137
self.new_volume_type.name,
136138
]
137139
verifylist = [
138140
('properties', {'myprop': 'myvalue'}),
139141
('multiattach', True),
140142
('cacheable', True),
141143
('replicated', True),
144+
('availability_zones', ['az1']),
142145
('name', self.new_volume_type.name),
143146
]
144147
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -153,6 +156,7 @@ def test_type_create_with_properties(self):
153156
'multiattach': '<is> True',
154157
'cacheable': '<is> True',
155158
'replication_enabled': '<is> True',
159+
'RESKEY:availability_zones': 'az1',
156160
}
157161
)
158162

@@ -442,6 +446,8 @@ def test_type_list_with_properties(self):
442446
"--multiattach",
443447
"--cacheable",
444448
"--replicated",
449+
"--availability-zone",
450+
"az1",
445451
]
446452
verifylist = [
447453
("encryption_type", False),
@@ -452,6 +458,7 @@ def test_type_list_with_properties(self):
452458
("multiattach", True),
453459
("cacheable", True),
454460
("replicated", True),
461+
("availability_zones", ["az1"]),
455462
]
456463
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
457464

@@ -463,6 +470,7 @@ def test_type_list_with_properties(self):
463470
"multiattach": "<is> True",
464471
"cacheable": "<is> True",
465472
"replication_enabled": "<is> True",
473+
"RESKEY:availability_zones": "az1",
466474
}
467475
},
468476
is_public=None,
@@ -607,6 +615,8 @@ def test_type_set_property(self):
607615
'--multiattach',
608616
'--cacheable',
609617
'--replicated',
618+
'--availability-zone',
619+
'az1',
610620
self.volume_type.id,
611621
]
612622
verifylist = [
@@ -616,6 +626,7 @@ def test_type_set_property(self):
616626
('multiattach', True),
617627
('cacheable', True),
618628
('replicated', True),
629+
('availability_zones', ['az1']),
619630
('volume_type', self.volume_type.id),
620631
]
621632
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -629,6 +640,7 @@ def test_type_set_property(self):
629640
'multiattach': '<is> True',
630641
'cacheable': '<is> True',
631642
'replication_enabled': '<is> True',
643+
'RESKEY:availability_zones': 'az1',
632644
}
633645
)
634646
self.volume_type_access_mock.add_project_access.assert_not_called()

openstackclient/volume/v2/volume_type.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ def get_parser(self, prog_name):
176176
"(requires driver support)"
177177
),
178178
)
179+
parser.add_argument(
180+
'--availability-zone',
181+
action='append',
182+
dest='availability_zones',
183+
help=_(
184+
"Set an availability zone for this volume type "
185+
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
186+
"(repeat option to set multiple availabilty zones)"
187+
),
188+
)
179189
parser.add_argument(
180190
'--project',
181191
metavar='<project>',
@@ -274,6 +284,10 @@ def take_action(self, parsed_args):
274284
properties['cacheable'] = '<is> True'
275285
if parsed_args.replicated:
276286
properties['replication_enabled'] = '<is> True'
287+
if parsed_args.availability_zones:
288+
properties['RESKEY:availability_zones'] = ','.join(
289+
parsed_args.availability_zones
290+
)
277291
if properties:
278292
result = volume_type.set_keys(properties)
279293
volume_type._info.update(
@@ -435,6 +449,16 @@ def get_parser(self, prog_name):
435449
"(supported by --os-volume-api-version 3.52 or above)"
436450
),
437451
)
452+
parser.add_argument(
453+
'--availability-zone',
454+
action='append',
455+
dest='availability_zones',
456+
help=_(
457+
"List only volume types with this availability configured "
458+
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
459+
"(repeat option to filter on multiple availabilty zones)"
460+
),
461+
)
438462
return parser
439463

440464
def take_action(self, parsed_args):
@@ -472,6 +496,10 @@ def take_action(self, parsed_args):
472496
properties['cacheable'] = '<is> True'
473497
if parsed_args.replicated:
474498
properties['replication_enabled'] = '<is> True'
499+
if parsed_args.availability_zones:
500+
properties['RESKEY:availability_zones'] = ','.join(
501+
parsed_args.availability_zones
502+
)
475503
if properties:
476504
if volume_client.api_version < api_versions.APIVersion('3.52'):
477505
msg = _(
@@ -590,6 +618,16 @@ def get_parser(self, prog_name):
590618
"(requires driver support)"
591619
),
592620
)
621+
parser.add_argument(
622+
'--availability-zone',
623+
action='append',
624+
dest='availability_zones',
625+
help=_(
626+
"Set an availability zone for this volume type "
627+
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
628+
"(repeat option to set multiple availabilty zones)"
629+
),
630+
)
593631
parser.add_argument(
594632
'--project',
595633
metavar='<project>',
@@ -706,6 +744,10 @@ def take_action(self, parsed_args):
706744
properties['cacheable'] = '<is> True'
707745
if parsed_args.replicated:
708746
properties['replication_enabled'] = '<is> True'
747+
if parsed_args.availability_zones:
748+
properties['RESKEY:availability_zones'] = ','.join(
749+
parsed_args.availability_zones
750+
)
709751
if properties:
710752
try:
711753
volume_type.set_keys(properties)

releasenotes/notes/volume-type-extra-specs-22a22fcb6e269832.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
features:
33
- |
44
The ``volume type create``, ``volume type set``, ``volume type list``
5-
commands now accept three new options - ``--multiattach``, ``--cacheable``,
6-
and ``--replicated`` - which are short cuts for setting or filtering on
7-
the relevant properties on the volume type.
5+
commands now accept four new options - ``--multiattach``, ``--cacheable``,
6+
``--replicated``, and ``--availability-zone`` - which are short cuts for
7+
setting or filtering on the relevant properties on the volume type.

0 commit comments

Comments
 (0)