Skip to content

Commit 190f06a

Browse files
Add "image metadef property show" command
Change-Id: I326735014dfcb4477b109a99aa31f71b07b91c7b
1 parent 5fb922e commit 190f06a

5 files changed

Lines changed: 92 additions & 1 deletion

File tree

doc/source/cli/data/glance.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ md-object-update,,Update metadata definitions object inside a namespace.
4141
md-property-create,,Create a new metadata definitions property inside a namespace.
4242
md-property-delete,,Delete a specific metadata definitions property inside a namespace.
4343
md-property-list,image metadef property list,List metadata definitions properties inside a specific namespace.
44-
md-property-show,,Describe a specific metadata definitions property inside a namespace.
44+
md-property-show,image metadef property show,Describe a specific metadata definitions property inside a namespace.
4545
md-property-update,,Update metadata definitions property inside a namespace.
4646
md-resource-type-associate,,Associate resource type with a metadata definitions namespace.
4747
md-resource-type-deassociate,,Deassociate resource type with a metadata definitions namespace.

openstackclient/image/v2/metadef_properties.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,55 @@ def take_action(self, parsed_args):
4444
for prop in props
4545
),
4646
)
47+
48+
49+
class ShowMetadefProperty(command.ShowOne):
50+
_description = _("Describe a specific property from a namespace")
51+
52+
def get_parser(self, prog_name):
53+
parser = super().get_parser(prog_name)
54+
parser.add_argument(
55+
"namespace_name",
56+
metavar="<namespace_name>",
57+
help=_("Namespace (name) for the namespace"),
58+
)
59+
parser.add_argument(
60+
"property_name",
61+
metavar="<property_name>",
62+
help=_("Property to show"),
63+
)
64+
return parser
65+
66+
def take_action(self, parsed_args):
67+
image_client = self.app.client_manager.image
68+
data = image_client.get_metadef_property(
69+
parsed_args.property_name, parsed_args.namespace_name
70+
)
71+
data = data.to_dict(ignore_none=True, original_names=True)
72+
info = {
73+
key: data[key]
74+
for key in [
75+
'namespace_name',
76+
'name',
77+
'type',
78+
'title',
79+
'description',
80+
'operators',
81+
'default',
82+
'is_readonly',
83+
'minimum',
84+
'maximum',
85+
'enum',
86+
'pattern',
87+
'min_length',
88+
'max_length',
89+
'items',
90+
'require_unique_items',
91+
'min_items',
92+
'max_items',
93+
'allow_additional_items',
94+
]
95+
if key in data
96+
}
97+
98+
return zip(*sorted(info.items()))

openstackclient/tests/unit/image/v2/test_metadef_properties.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,36 @@ def test_metadef_property_list(self):
4040

4141
self.assertEqual(self.columns, columns)
4242
self.assertEqual(getattr(self.datalist[0], 'name'), next(data)[0])
43+
44+
45+
class TestMetadefPropertyShow(image_fakes.TestImagev2):
46+
_metadef_property = image_fakes.create_one_metadef_property()
47+
48+
expected_columns = (
49+
'name',
50+
'title',
51+
'type',
52+
)
53+
expected_data = (
54+
_metadef_property.name,
55+
_metadef_property.title,
56+
_metadef_property.type,
57+
)
58+
59+
def setUp(self):
60+
super().setUp()
61+
62+
self.image_client.get_metadef_property.return_value = (
63+
self._metadef_property
64+
)
65+
66+
self.cmd = metadef_properties.ShowMetadefProperty(self.app, None)
67+
68+
def test_metadef_property_show(self):
69+
arglist = ['my-namespace', 'my-property']
70+
verifylist = []
71+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
72+
73+
columns, data = self.cmd.take_action(parsed_args)
74+
self.assertEqual(self.expected_columns, columns)
75+
self.assertEqual(self.expected_data, data)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``image metadef property show`` command to show details
5+
about a metadef property inside a specific namespace.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ openstack.image.v2 =
398398
image_metadef_namespace_show = openstackclient.image.v2.metadef_namespaces:ShowMetadefNameSpace
399399

400400
image_metadef_property_list = openstackclient.image.v2.metadef_properties:ListMetadefProperties
401+
image_metadef_property_show = openstackclient.image.v2.metadef_properties:ShowMetadefProperty
401402

402403
image_metadef_resource_type_list = openstackclient.image.v2.metadef_resource_types:ListMetadefResourceTypes
403404

0 commit comments

Comments
 (0)