Adds command `image metadef object list
`
Depends-on: https://review.opendev.org/c/openstack/openstacksdk/+/858350 Change-Id: I0691f7519e8fb9f01836e6232e0bcebd2c428ac3
This commit is contained in:
parent
78ef009a3a
commit
4bb6efa8f8
@ -34,7 +34,7 @@ md-namespace-tags-delete,,Delete all metadata definitions tags inside a specific
|
||||
md-namespace-update,,Update an existing metadata definitions namespace.
|
||||
md-object-create,image metadef object create,Create a new metadata definitions object inside a namespace.
|
||||
md-object-delete,,Delete a specific metadata definitions object inside a namespace.
|
||||
md-object-list,,List metadata definitions objects inside a specific namespace.
|
||||
md-object-list,image metadef object list,List metadata definitions objects inside a specific namespace.
|
||||
md-object-property-show,,Describe a specific metadata definitions property inside an object.
|
||||
md-object-show,image metadef object show,Describe a specific metadata definitions object inside a namespace.
|
||||
md-object-update,,Update metadata definitions object inside a namespace.
|
||||
|
|
@ -105,3 +105,35 @@ class ShowMetadefObjects(command.ShowOne):
|
||||
fields, value = _format_object(data)
|
||||
|
||||
return fields, value
|
||||
|
||||
|
||||
class ListMetadefObjects(command.Lister):
|
||||
_description = _("List metadef objects inside a specific namespace.")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"namespace",
|
||||
metavar="<namespace>",
|
||||
help=_("Namespace (name) for the namespace"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
image_client = self.app.client_manager.image
|
||||
|
||||
namespace_name = parsed_args.namespace
|
||||
columns = ['name', 'description']
|
||||
|
||||
md_objects = list(image_client.metadef_objects(namespace_name))
|
||||
column_headers = columns
|
||||
return (
|
||||
column_headers,
|
||||
(
|
||||
utils.get_item_properties(
|
||||
md_object,
|
||||
columns,
|
||||
)
|
||||
for md_object in md_objects
|
||||
),
|
||||
)
|
||||
|
@ -102,3 +102,38 @@ class TestMetadefObjectsShow(fakes.TestImagev2):
|
||||
|
||||
self.assertEqual(self.expected_columns, columns)
|
||||
self.assertEqual(self.expected_data, data)
|
||||
|
||||
|
||||
class TestMetadefObjectList(fakes.TestImagev2):
|
||||
_metadef_namespace = fakes.create_one_metadef_namespace()
|
||||
_metadef_objects = [fakes.create_one_metadef_object()]
|
||||
columns = ['name', 'description']
|
||||
|
||||
datalist = []
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.image_client.metadef_objects.side_effect = [
|
||||
self._metadef_objects,
|
||||
[],
|
||||
]
|
||||
|
||||
# Get the command object to test
|
||||
self.image_client.metadef_objects.return_value = iter(
|
||||
self._metadef_objects
|
||||
)
|
||||
self.cmd = metadef_objects.ListMetadefObjects(self.app, None)
|
||||
self.datalist = self._metadef_objects
|
||||
|
||||
def test_metadef_objects_list(self):
|
||||
arglist = [self._metadef_namespace.namespace]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
|
||||
# In base command class Lister in cliff, abstract method take_action()
|
||||
# returns a tuple containing the column names and an iterable
|
||||
# containing the data to be listed.
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(getattr(self.datalist[0], 'name'), next(data)[0])
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``image metadef object list`` command to list the
|
||||
metadata definitions objects inside a specific namespace
|
@ -397,8 +397,11 @@ openstack.image.v2 =
|
||||
image_metadef_namespace_set = openstackclient.image.v2.metadef_namespaces:SetMetadefNameSpace
|
||||
image_metadef_namespace_show = openstackclient.image.v2.metadef_namespaces:ShowMetadefNameSpace
|
||||
|
||||
|
||||
image_metadef_object_create = openstackclient.image.v2.metadef_objects:CreateMetadefObjects
|
||||
image_metadef_object_show = openstackclient.image.v2.metadef_objects:ShowMetadefObjects
|
||||
image_metadef_object_list = openstackclient.image.v2.metadef_objects:ListMetadefObjects
|
||||
|
||||
|
||||
image_metadef_property_create = openstackclient.image.v2.metadef_properties:CreateMetadefProperty
|
||||
image_metadef_property_list = openstackclient.image.v2.metadef_properties:ListMetadefProperties
|
||||
|
Loading…
Reference in New Issue
Block a user