added api requirements for new "openstack image metadefs namespace list" command

Change-Id: Ibb86d74419faf066edca1a43d2d4da005db780ea
This commit is contained in:
Areg Grigoryan 2022-08-25 13:53:50 +02:00 committed by Stephen Finucane
parent 0529c30ae2
commit 703375a8cb
8 changed files with 143 additions and 0 deletions

View File

@ -51,3 +51,11 @@ Service Info Discovery Operations
.. autoclass:: openstack.image.v2._proxy.Proxy
:noindex:
:members: stores, get_import_info
Metadef Namespace Operations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: openstack.image.v2._proxy.Proxy
:noindex:
:members: metadef_namespaces

View File

@ -14,5 +14,6 @@ Image v2 Resources
v2/image
v2/member
v2/metadef_namespace
v2/task
v2/service_info

View File

@ -0,0 +1,13 @@
openstack.image.v2.metadef_namespace
=====================================
.. automodule:: openstack.image.v2.metadef_namespace
The MetadefNamespace Class
----------------------------
The ``MetadefNamespace`` class inherits
from :class:`~openstack.resource.Resource`.
.. autoclass:: openstack.image.v2.metadef_namespace.MetadefNamespace
:members:

View File

@ -17,6 +17,7 @@ from openstack import exceptions
from openstack.image import _base_proxy
from openstack.image.v2 import image as _image
from openstack.image.v2 import member as _member
from openstack.image.v2 import metadef_namespace as _metadef_namespace
from openstack.image.v2 import schema as _schema
from openstack.image.v2 import service_info as _si
from openstack.image.v2 import task as _task
@ -841,3 +842,12 @@ class Proxy(_base_proxy.BaseImageProxy):
when no resource can be found.
"""
return self._get(_si.Import, require_id=False)
def metadef_namespaces(self, **query):
"""Get a info about image metadef namespaces
:returns: A generator object of metadef namespaces
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._list(_metadef_namespace.MetadefNamespace, **query)

View File

@ -0,0 +1,41 @@
# 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 openstack import resource
# TODO(schwicke): create and delete still need to be implemented
class MetadefNamespace(resource.Resource):
resources_key = 'namespaces'
base_path = '/metadefs/namespaces'
allow_fetch = True
allow_list = True
_query_mapping = resource.QueryParameters(
"limit",
"marker",
"resource_types",
"sort_dir",
"sort_key",
"visibility"
)
created_at = resource.Body('created_at')
description = resource.Body('description')
display_name = resource.Body('display_name')
is_protected = resource.Body('protected', type=bool)
namespace = resource.Body('namespace')
owner = resource.Body('owner')
resource_type_associations = resource.Body('resource_type_associations',
type=list,
list_type=dict)
visibility = resource.Body('visibility')

View File

@ -0,0 +1,59 @@
# 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 openstack.image.v2 import metadef_namespace
from openstack.tests.unit import base
EXAMPLE = {
'display_name': 'Cinder Volume Type',
'created_at': '2014-08-28T17:13:06Z',
'is_protected': True,
'namespace': 'OS::Cinder::Volumetype',
'owner': 'admin',
'resource_type_associations': [
{
'created_at': '2014-08-28T17:13:06Z',
'name': 'OS::Glance::Image',
'updated_at': '2014-08-28T17:13:06Z'
}
]
}
class TestMetadefNamespace(base.TestCase):
def test_basic(self):
sot = metadef_namespace.MetadefNamespace()
self.assertIsNone(sot.resource_key)
self.assertEqual('namespaces', sot.resources_key)
self.assertEqual('/metadefs/namespaces', sot.base_path)
self.assertTrue(sot.allow_fetch)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = metadef_namespace.MetadefNamespace(**EXAMPLE)
self.assertEqual(EXAMPLE['namespace'], sot.namespace)
self.assertEqual(EXAMPLE['owner'], sot.owner)
self.assertEqual(EXAMPLE['created_at'], sot.created_at)
self.assertEqual(EXAMPLE['is_protected'], sot.is_protected)
self.assertEqual(EXAMPLE['display_name'], sot.display_name)
self.assertListEqual(EXAMPLE['resource_type_associations'],
sot.resource_type_associations)
self.assertDictEqual(
{
'limit': 'limit',
'marker': 'marker',
'resource_types': 'resource_types',
'sort_dir': 'sort_dir',
'sort_key': 'sort_key',
'visibility': 'visibility'
}, sot._query_mapping._mapping)

View File

@ -19,6 +19,7 @@ from openstack import exceptions
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 schema
from openstack.image.v2 import service_info as si
from openstack.image.v2 import task
@ -553,3 +554,9 @@ class TestMisc(TestImageProxy):
method_kwargs={},
expected_args=[si.Import],
expected_kwargs={'require_id': False})
class TestMetadefNamespace(TestImageProxy):
def test_metadef_namespaces(self):
self.verify_list(self.proxy.metadef_namespaces,
metadef_namespace.MetadefNamespace)

View File

@ -0,0 +1,4 @@
---
features:
-|
Adds support to query metadef namespaces from glance.