Add "image metadef property show" command

Change-Id: I326735014dfcb4477b109a99aa31f71b07b91c7b
This commit is contained in:
Cyril Roelandt 2023-10-12 02:51:17 +00:00
parent 5fb922e469
commit 190f06a963
5 changed files with 92 additions and 1 deletions

View File

@ -41,7 +41,7 @@ md-object-update,,Update metadata definitions object inside a namespace.
md-property-create,,Create a new metadata definitions property inside a namespace.
md-property-delete,,Delete a specific metadata definitions property inside a namespace.
md-property-list,image metadef property list,List metadata definitions properties inside a specific namespace.
md-property-show,,Describe a specific metadata definitions property inside a namespace.
md-property-show,image metadef property show,Describe a specific metadata definitions property inside a namespace.
md-property-update,,Update metadata definitions property inside a namespace.
md-resource-type-associate,,Associate resource type with a metadata definitions namespace.
md-resource-type-deassociate,,Deassociate resource type with a metadata definitions namespace.

1 cache-clear Clear all images from cache, queue or both.
41 md-property-create Create a new metadata definitions property inside a namespace.
42 md-property-delete Delete a specific metadata definitions property inside a namespace.
43 md-property-list image metadef property list List metadata definitions properties inside a specific namespace.
44 md-property-show image metadef property show Describe a specific metadata definitions property inside a namespace.
45 md-property-update Update metadata definitions property inside a namespace.
46 md-resource-type-associate Associate resource type with a metadata definitions namespace.
47 md-resource-type-deassociate Deassociate resource type with a metadata definitions namespace.

View File

@ -44,3 +44,55 @@ class ListMetadefProperties(command.Lister):
for prop in props
),
)
class ShowMetadefProperty(command.ShowOne):
_description = _("Describe a specific property from a namespace")
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument(
"namespace_name",
metavar="<namespace_name>",
help=_("Namespace (name) for the namespace"),
)
parser.add_argument(
"property_name",
metavar="<property_name>",
help=_("Property to show"),
)
return parser
def take_action(self, parsed_args):
image_client = self.app.client_manager.image
data = image_client.get_metadef_property(
parsed_args.property_name, parsed_args.namespace_name
)
data = data.to_dict(ignore_none=True, original_names=True)
info = {
key: data[key]
for key in [
'namespace_name',
'name',
'type',
'title',
'description',
'operators',
'default',
'is_readonly',
'minimum',
'maximum',
'enum',
'pattern',
'min_length',
'max_length',
'items',
'require_unique_items',
'min_items',
'max_items',
'allow_additional_items',
]
if key in data
}
return zip(*sorted(info.items()))

View File

@ -40,3 +40,36 @@ class TestMetadefPropertyList(image_fakes.TestImagev2):
self.assertEqual(self.columns, columns)
self.assertEqual(getattr(self.datalist[0], 'name'), next(data)[0])
class TestMetadefPropertyShow(image_fakes.TestImagev2):
_metadef_property = image_fakes.create_one_metadef_property()
expected_columns = (
'name',
'title',
'type',
)
expected_data = (
_metadef_property.name,
_metadef_property.title,
_metadef_property.type,
)
def setUp(self):
super().setUp()
self.image_client.get_metadef_property.return_value = (
self._metadef_property
)
self.cmd = metadef_properties.ShowMetadefProperty(self.app, None)
def test_metadef_property_show(self):
arglist = ['my-namespace', 'my-property']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.expected_columns, columns)
self.assertEqual(self.expected_data, data)

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``image metadef property show`` command to show details
about a metadef property inside a specific namespace.

View File

@ -398,6 +398,7 @@ openstack.image.v2 =
image_metadef_namespace_show = openstackclient.image.v2.metadef_namespaces:ShowMetadefNameSpace
image_metadef_property_list = openstackclient.image.v2.metadef_properties:ListMetadefProperties
image_metadef_property_show = openstackclient.image.v2.metadef_properties:ShowMetadefProperty
image_metadef_resource_type_list = openstackclient.image.v2.metadef_resource_types:ListMetadefResourceTypes