Add image.service_info resources

Add service info discovery resources for image service:
- import (import constraints)
- store (supported image stores)

Change-Id: I978c156f41386ce05feed9d6b3e92a7a675b70c9
This commit is contained in:
Artem Goncharov 2019-02-20 18:37:22 +01:00 committed by Monty Taylor
parent 96eae95e3b
commit e9e1bbe9ce
8 changed files with 166 additions and 0 deletions

View File

@ -64,3 +64,11 @@ Schema Operations
.. automethod:: openstack.image.v2._proxy.Proxy.get_member_schema .. automethod:: openstack.image.v2._proxy.Proxy.get_member_schema
.. automethod:: openstack.image.v2._proxy.Proxy.get_tasks_schema .. automethod:: openstack.image.v2._proxy.Proxy.get_tasks_schema
.. automethod:: openstack.image.v2._proxy.Proxy.get_task_schema .. automethod:: openstack.image.v2._proxy.Proxy.get_task_schema
Service Info Discovery Operations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: openstack.image.v2._proxy.Proxy
.. automethod:: openstack.image.v2._proxy.Proxy.stores
.. automethod:: openstack.image.v2._proxy.Proxy.get_import_info

View File

@ -15,3 +15,4 @@ Image v2 Resources
v2/image v2/image
v2/member v2/member
v2/task v2/task
v2/service_info

View File

@ -0,0 +1,20 @@
openstack.image.v2.service_info
===============================
.. automodule:: openstack.image.v2.service_info
The Store Class
----------------
The ``Store`` class inherits from :class:`~openstack.resource.Resource`.
.. autoclass:: openstack.image.v2.service_info.Store
:members:
The Import Info Class
---------------------
The ``Import`` class inherits from :class:`~openstack.resource.Resource`.
.. autoclass:: openstack.image.v2.service_info.Import
:members:

View File

@ -23,6 +23,7 @@ from openstack.image.v2 import image as _image
from openstack.image.v2 import member as _member from openstack.image.v2 import member as _member
from openstack.image.v2 import schema as _schema from openstack.image.v2 import schema as _schema
from openstack.image.v2 import task as _task from openstack.image.v2 import task as _task
from openstack.image.v2 import service_info as _si
from openstack import resource from openstack import resource
from openstack import utils from openstack import utils
@ -660,3 +661,20 @@ class Proxy(_base_proxy.BaseImageProxy):
""" """
return self._get(_schema.Schema, requires_id=False, return self._get(_schema.Schema, requires_id=False,
base_path='/schemas/task') base_path='/schemas/task')
def stores(self, **query):
"""Return a generator of supported image stores
:returns: A generator of store objects
:rtype: :class:`~openstack.image.v2.service_info.Store`
"""
return self._list(_si.Store, **query)
def get_import_info(self):
"""Get a info about image constraints
:returns: One :class:`~openstack.image.v2.service_info.Import`
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_si.Import, require_id=False)

View File

@ -0,0 +1,36 @@
# 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
class Import(resource.Resource):
base_path = '/info/import'
# capabilities
allow_fetch = True
#: import methods
import_methods = resource.Body('import-methods', type=dict)
class Store(resource.Resource):
resources_key = 'stores'
base_path = '/info/stores'
# capabilities
allow_list = True
#: Description of the store
description = resource.Body('description')
#: default
is_default = resource.Body('default', type=bool)

View File

@ -18,6 +18,7 @@ from openstack.image.v2 import image
from openstack.image.v2 import member from openstack.image.v2 import member
from openstack.image.v2 import schema from openstack.image.v2 import schema
from openstack.image.v2 import task from openstack.image.v2 import task
from openstack.image.v2 import service_info as si
from openstack.tests.unit.image.v2 import test_image as fake_image from openstack.tests.unit.image.v2 import test_image as fake_image
from openstack.tests.unit import test_proxy_base from openstack.tests.unit import test_proxy_base
@ -229,3 +230,14 @@ class TestImageProxy(test_proxy_base.TestProxyBase):
expected_args=[schema.Schema], expected_args=[schema.Schema],
expected_kwargs={'base_path': '/schemas/task', expected_kwargs={'base_path': '/schemas/task',
'requires_id': False}) 'requires_id': False})
def test_stores(self):
self.verify_list(self.proxy.stores, si.Store)
def test_import_info(self):
self._verify2("openstack.proxy.Proxy._get",
self.proxy.get_import_info,
method_args=[],
method_kwargs={},
expected_args=[si.Import],
expected_kwargs={'require_id': False})

View File

@ -0,0 +1,68 @@
# 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.tests.unit import base
from openstack.image.v2 import service_info as si
IDENTIFIER = 'IDENTIFIER'
EXAMPLE_IMPORT = {
'import-methods': {
'description': 'Import methods available.',
'type': 'array',
'value': [
'glance-direct',
'web-download'
]
}
}
EXAMPLE_STORE = {
'id': 'fast',
'description': 'Fast access to rbd store',
'default': True
}
class TestStore(base.TestCase):
def test_basic(self):
sot = si.Store()
self.assertIsNone(sot.resource_key)
self.assertEqual('stores', sot.resources_key)
self.assertEqual('/info/stores', sot.base_path)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_fetch)
self.assertFalse(sot.allow_commit)
self.assertFalse(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = si.Store(**EXAMPLE_STORE)
self.assertEqual(EXAMPLE_STORE['id'], sot.id)
self.assertEqual(EXAMPLE_STORE['description'], sot.description)
self.assertEqual(EXAMPLE_STORE['default'], sot.is_default)
class TestImport(base.TestCase):
def test_basic(self):
sot = si.Import()
self.assertIsNone(sot.resource_key)
self.assertIsNone(sot.resources_key)
self.assertEqual('/info/import', sot.base_path)
self.assertFalse(sot.allow_create)
self.assertTrue(sot.allow_fetch)
self.assertFalse(sot.allow_commit)
self.assertFalse(sot.allow_delete)
self.assertFalse(sot.allow_list)
def test_make_it(self):
sot = si.Import(**EXAMPLE_IMPORT)
self.assertEqual(EXAMPLE_IMPORT['import-methods'], sot.import_methods)

View File

@ -0,0 +1,3 @@
---
features:
- Add image service info discovery (import constraints and supported stores)