Add "image metadef property list" command.
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/857727 Change-Id: I8f6692e779c4721225052d348b4b947a545bd6c0
This commit is contained in:
parent
53e7d713f0
commit
5fb922e469
@ -40,7 +40,7 @@ md-object-show,,Describe a specific metadata definitions object inside a namespa
|
||||
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,,List metadata definitions properties inside a specific 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-update,,Update metadata definitions property inside a namespace.
|
||||
md-resource-type-associate,,Associate resource type with a metadata definitions namespace.
|
||||
|
|
46
openstackclient/image/v2/metadef_properties.py
Normal file
46
openstackclient/image/v2/metadef_properties.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Copyright 2023 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
class ListMetadefProperties(command.Lister):
|
||||
_description = _("List metadef properties")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"namespace_name",
|
||||
metavar="<namespace_name>",
|
||||
help=_("An identifier (a name) for the namespace"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
image_client = self.app.client_manager.image
|
||||
props = image_client.metadef_properties(parsed_args.namespace_name)
|
||||
columns = ['name', 'title', 'type']
|
||||
return (
|
||||
columns,
|
||||
(
|
||||
utils.get_item_properties(
|
||||
prop,
|
||||
columns,
|
||||
)
|
||||
for prop in props
|
||||
),
|
||||
)
|
@ -20,6 +20,7 @@ from openstack.image.v2 import _proxy
|
||||
from openstack.image.v2 import image
|
||||
from openstack.image.v2 import member
|
||||
from openstack.image.v2 import metadef_namespace
|
||||
from openstack.image.v2 import metadef_property
|
||||
from openstack.image.v2 import metadef_resource_type
|
||||
from openstack.image.v2 import service_info as _service_info
|
||||
from openstack.image.v2 import task
|
||||
@ -263,6 +264,20 @@ def create_one_metadef_namespace(attrs=None):
|
||||
return metadef_namespace.MetadefNamespace(**metadef_namespace_list)
|
||||
|
||||
|
||||
def create_one_metadef_property(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
metadef_property_list = {
|
||||
'name': 'cpu_cores',
|
||||
'title': 'vCPU Cores',
|
||||
'type': 'integer',
|
||||
}
|
||||
|
||||
# Overwrite default attributes if there are some attributes set
|
||||
metadef_property_list.update(attrs)
|
||||
return metadef_property.MetadefProperty(**metadef_property_list)
|
||||
|
||||
|
||||
def create_one_resource_type(attrs=None):
|
||||
"""Create a fake MetadefResourceType member.
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
# Copyright 2023 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstackclient.image.v2 import metadef_properties
|
||||
from openstackclient.tests.unit.image.v2 import fakes as image_fakes
|
||||
|
||||
|
||||
class TestMetadefPropertyList(image_fakes.TestImagev2):
|
||||
_metadef_property = [image_fakes.create_one_metadef_property()]
|
||||
|
||||
columns = ['name', 'title', 'type']
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.image_client.metadef_properties.side_effect = [
|
||||
self._metadef_property,
|
||||
[],
|
||||
]
|
||||
|
||||
self.cmd = metadef_properties.ListMetadefProperties(self.app, None)
|
||||
self.datalist = self._metadef_property
|
||||
|
||||
def test_metadef_property_list(self):
|
||||
arglist = ['my-namespace']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
|
||||
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 property list`` command to list the
|
||||
metadata definitions properties inside a specific namespace.
|
@ -397,6 +397,8 @@ 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_property_list = openstackclient.image.v2.metadef_properties:ListMetadefProperties
|
||||
|
||||
image_metadef_resource_type_list = openstackclient.image.v2.metadef_resource_types:ListMetadefResourceTypes
|
||||
|
||||
openstack.network.v2 =
|
||||
|
Loading…
Reference in New Issue
Block a user