Adds CLI support for `glance md-object-property-show
`
This patch adds a command "image metadef object property show" which describe a specific metadata definitions property inside an object. Change-Id: I738e2e3c27c9819290d5a2a8781878b81f03b5f9
This commit is contained in:
parent
2eea916b35
commit
2a90a6f07b
@ -37,6 +37,9 @@ Image v2
|
||||
.. autoprogram-cliff:: openstack.image.v2
|
||||
:command: image metadef object update
|
||||
|
||||
.. autoprogram-cliff:: openstack.image.v2
|
||||
:command: image metadef object property show
|
||||
|
||||
.. autoprogram-cliff:: openstack.image.v2
|
||||
:command: image metadef property create
|
||||
|
||||
|
@ -36,7 +36,7 @@ md-object-create,image metadef object create,Create a new metadata definitions o
|
||||
md-object-show,image metadef object show,Describe a specific metadata definitions object inside a namespace.
|
||||
md-object-list,image metadef object list,List metadata definitions objects inside a specific namespace.
|
||||
md-object-delete,image metadef object delete,Delete a specific metadata definitions object inside a namespace.
|
||||
md-object-property-show,,Describe a specific metadata definitions property inside an object.
|
||||
md-object-property-show,image metadef object property show,Describe a specific metadata definitions property inside an object.
|
||||
md-object-update,image metadef object update,Update metadata definitions object inside a namespace.
|
||||
md-property-create,image metadef property create,Create a new metadata definitions property inside a namespace.
|
||||
md-property-delete,image metadef property delete,Delete a specific metadata definitions property inside a namespace.
|
||||
|
|
@ -223,3 +223,47 @@ class SetMetadefObject(command.Command):
|
||||
image_client.update_metadef_object(
|
||||
object, parsed_args.namespace, **kwargs
|
||||
)
|
||||
|
||||
|
||||
class ShowMetadefObjectProperty(command.ShowOne):
|
||||
_description = _(
|
||||
"Describe a specific metadata definitions property inside an object."
|
||||
)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"namespace",
|
||||
metavar="<namespace_name>",
|
||||
help=_("Namespace (name) for the namespace"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"object",
|
||||
metavar="<object_name>",
|
||||
help=_("Name of an object."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"property",
|
||||
help=_("Name of the property."),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
image_client = self.app.client_manager.image
|
||||
|
||||
namespace_name = parsed_args.namespace
|
||||
object_name = parsed_args.object
|
||||
|
||||
obj = image_client.get_metadef_object(object_name, namespace_name)
|
||||
try:
|
||||
prop = obj['properties'][parsed_args.property]
|
||||
prop['name'] = parsed_args.property
|
||||
|
||||
except KeyError:
|
||||
msg = _('Property %s not found in object %s.') % (
|
||||
parsed_args.property,
|
||||
parsed_args.object,
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
return zip(*sorted(prop.items()))
|
||||
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from osc_lib import exceptions
|
||||
|
||||
from openstackclient.image.v2 import metadef_objects
|
||||
from openstackclient.tests.unit.image.v2 import fakes
|
||||
|
||||
@ -198,3 +200,63 @@ class TestMetadefObjectSet(fakes.TestImagev2):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestMetadefObjectPropertyShow(fakes.TestImagev2):
|
||||
_metadef_namespace = fakes.create_one_metadef_namespace()
|
||||
_metadef_objects = fakes.create_one_metadef_object()
|
||||
md_property = _metadef_objects['properties']['quota:cpu_quota']
|
||||
md_property['name'] = 'quota:cpu_quota'
|
||||
|
||||
expected_columns = (
|
||||
'description',
|
||||
'name',
|
||||
'title',
|
||||
'type',
|
||||
)
|
||||
expected_data = (
|
||||
md_property['description'],
|
||||
md_property['name'],
|
||||
md_property['title'],
|
||||
md_property['type'],
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.image_client.get_metadef_object.return_value = (
|
||||
self._metadef_objects
|
||||
)
|
||||
self.cmd = metadef_objects.ShowMetadefObjectProperty(self.app, None)
|
||||
|
||||
def test_object_property_show(self):
|
||||
arglist = [
|
||||
self._metadef_namespace.namespace,
|
||||
self._metadef_objects.name,
|
||||
'quota:cpu_quota',
|
||||
]
|
||||
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)
|
||||
|
||||
def test_neg_object_property_show(self):
|
||||
arglist = [
|
||||
self._metadef_namespace.namespace,
|
||||
self._metadef_objects.name,
|
||||
'prop1',
|
||||
]
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
exc = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args,
|
||||
)
|
||||
self.assertIn(
|
||||
'Property %s not found in object %s.'
|
||||
% (parsed_args.property, parsed_args.object),
|
||||
str(exc),
|
||||
)
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``image metadef object property show`` command which
|
||||
shows a particular property inside metadef object.
|
@ -404,7 +404,7 @@ openstack.image.v2 =
|
||||
image_metadef_object_list = openstackclient.image.v2.metadef_objects:ListMetadefObjects
|
||||
image_metadef_object_delete = openstackclient.image.v2.metadef_objects:DeleteMetadefObject
|
||||
image_metadef_object_update = openstackclient.image.v2.metadef_objects:SetMetadefObject
|
||||
|
||||
image_metadef_object_property_show = openstackclient.image.v2.metadef_objects:ShowMetadefObjectProperty
|
||||
|
||||
image_metadef_property_create = openstackclient.image.v2.metadef_properties:CreateMetadefProperty
|
||||
image_metadef_property_delete = openstackclient.image.v2.metadef_properties:DeleteMetadefProperty
|
||||
|
Loading…
Reference in New Issue
Block a user