本文整理汇总了Python中keystoneauth1.adapter.Adapter方法的典型用法代码示例。如果您正苦于以下问题:Python adapter.Adapter方法的具体用法?Python adapter.Adapter怎么用?Python adapter.Adapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keystoneauth1.adapter
的用法示例。
在下文中一共展示了adapter.Adapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_microversion_for_list
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def _get_microversion_for_list(cls, session):
"""Get microversion to use when listing resources.
The base version uses the following logic:
1. If the session has a default microversion for the current service,
just use it.
2. If ``self._max_microversion`` is not ``None``, use minimum between
it and the maximum microversion supported by the server.
3. Otherwise use ``None``.
Subclasses can override this method if more complex logic is needed.
:param session: :class`keystoneauth1.adapter.Adapter`
:return: microversion as string or ``None``
"""
if session.default_microversion:
return session.default_microversion
return utils.maximum_supported_microversion(session,
cls._max_microversion)
示例2: delete
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def delete(self, session, error_message=None, **kwargs):
"""Delete the remote resource based on this instance.
:param session: The session to use for making this request.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param dict kwargs: Parameters that will be passed to
_prepare_request()
:return: This :class:`Resource` instance.
:raises: :exc:`~openstack.exceptions.MethodNotSupported` if
:data:`Resource.allow_commit` is not set to ``True``.
:raises: :exc:`~openstack.exceptions.ResourceNotFound` if
the resource was not found.
"""
response = self._raw_delete(session, **kwargs)
kwargs = {}
if error_message:
kwargs['error_message'] = error_message
self._translate_response(response, has_body=False, **kwargs)
return self
示例3: placement
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def placement(self):
if self._placement:
return self._placement
placement_version = self._get_client_option('placement',
'api_version')
placement_interface = self._get_client_option('placement',
'interface')
placement_region_name = self._get_client_option('placement',
'region_name')
# Set accept header on every request to ensure we notify placement
# service of our response body media type preferences.
headers = {'accept': 'application/json'}
self._placement = ka_adapter.Adapter(
session=self.session,
service_type='placement',
default_microversion=placement_version,
interface=placement_interface,
region_name=placement_region_name,
additional_headers=headers)
return self._placement
示例4: setUp
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def setUp(self):
super(TestBackup, self).setUp()
self.resp = mock.Mock()
self.resp.body = None
self.resp.json = mock.Mock(return_value=self.resp.body)
self.resp.headers = {}
self.resp.status_code = 202
self.sess = mock.Mock(spec=adapter.Adapter)
self.sess.get = mock.Mock()
self.sess.post = mock.Mock(return_value=self.resp)
self.sess.default_microversion = None
示例5: setUp
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def setUp(self):
super(TestNodeSetProvisionState, self).setUp()
self.node = node.Node(**FAKE)
self.session = mock.Mock(spec=adapter.Adapter,
default_microversion=None)
示例6: setUp
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def setUp(self):
super(TestWaitForAllocation, self).setUp()
self.session = mock.Mock(spec=adapter.Adapter)
self.session.default_microversion = '1.52'
self.session.log = mock.Mock()
self.fake = dict(FAKE, state='allocating', node_uuid=None)
self.allocation = allocation.Allocation(**self.fake)
示例7: setUp
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def setUp(self):
super(TestTagMixin, self).setUp()
self.service_name = "service"
self.base_path = "base_path"
class Test(resource.Resource, resource.TagMixin):
service = self.service_name
base_path = self.base_path
resources_key = 'resources'
allow_create = True
allow_fetch = True
allow_head = True
allow_commit = True
allow_delete = True
allow_list = True
self.test_class = Test
self.request = mock.Mock(spec=resource._Request)
self.request.url = "uri"
self.request.body = "body"
self.request.headers = "headers"
self.response = FakeResponse({})
self.sot = Test.new(id="id", tags=[])
self.sot._prepare_request = mock.Mock(return_value=self.request)
self.sot._translate_response = mock.Mock()
self.session = mock.Mock(spec=adapter.Adapter)
self.session.get = mock.Mock(return_value=self.response)
self.session.put = mock.Mock(return_value=self.response)
self.session.delete = mock.Mock(return_value=self.response)
示例8: setUp
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def setUp(self):
super(TestStartIntrospection, self).setUp()
self.session = mock.Mock(spec=adapter.Adapter)
self.proxy = _proxy.Proxy(self.session)
示例9: test_create
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def test_create(self):
sot = zone_export.ZoneExport()
response = mock.Mock()
response.json = mock.Mock(return_value='')
self.session = mock.Mock(spec=adapter.Adapter)
self.session.default_microversion = '1.1'
sot.create(self.session)
self.session.post.assert_called_once_with(
mock.ANY, json=None,
headers=None,
microversion=self.session.default_microversion)
示例10: setUp
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def setUp(self):
super(TestZone, self).setUp()
self.resp = mock.Mock()
self.resp.body = None
self.resp.json = mock.Mock(return_value=self.resp.body)
self.resp.status_code = 200
self.sess = mock.Mock(spec=adapter.Adapter)
self.sess.post = mock.Mock(return_value=self.resp)
self.sess.default_microversion = None
示例11: test_create
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def test_create(self):
sot = zone_import.ZoneImport()
response = mock.Mock()
response.json = mock.Mock(return_value='')
self.session = mock.Mock(spec=adapter.Adapter)
self.session.default_microversion = '1.1'
sot.create(self.session)
self.session.post.assert_called_once_with(
mock.ANY, json=None,
headers={'content-type': 'text/dns'},
microversion=self.session.default_microversion)
示例12: setUp
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def setUp(self):
super(TestImage, self).setUp()
self.resp = mock.Mock()
self.resp.body = None
self.resp.json = mock.Mock(return_value=self.resp.body)
self.sess = mock.Mock(spec=adapter.Adapter)
self.sess.post = mock.Mock(return_value=self.resp)
self.sess.put = mock.Mock(return_value=FakeResponse({}))
self.sess.delete = mock.Mock(return_value=FakeResponse({}))
self.sess.get = mock.Mock(return_value=FakeResponse({}))
self.sess.default_microversion = None
self.sess.retriable_status_codes = None
self.sess.log = _log.setup_logging('openstack')
示例13: _get_microversion_for
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def _get_microversion_for(self, session, action):
"""Get microversion to use for the given action.
The base version uses :meth:`_get_microversion_for_list`.
Subclasses can override this method if more complex logic is needed.
:param session: :class`keystoneauth1.adapter.Adapter`
:param action: One of "fetch", "commit", "create", "delete", "patch".
Unused in the base implementation.
:return: microversion as string or ``None``
"""
if action not in ('fetch', 'commit', 'create', 'delete', 'patch'):
raise ValueError('Invalid action: %s' % action)
return self._get_microversion_for_list(session)
示例14: _assert_microversion_for
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def _assert_microversion_for(self, session, action, expected,
error_message=None):
"""Enforce that the microversion for action satisfies the requirement.
:param session: :class`keystoneauth1.adapter.Adapter`
:param action: One of "fetch", "commit", "create", "delete".
:param expected: Expected microversion.
:param error_message: Optional error message with details. Will be
prepended to the message generated here.
:return: resulting microversion as string.
:raises: :exc:`~openstack.exceptions.NotSupported` if the version
used for the action is lower than the expected one.
"""
def _raise(message):
if error_message:
error_message.rstrip('.')
message = '%s. %s' % (error_message, message)
raise exceptions.NotSupported(message)
actual = self._get_microversion_for(session, action)
if expected is None:
return actual
elif actual is None:
message = ("API version %s is required, but the default "
"version will be used.") % expected
_raise(message)
actual_n = discover.normalize_version_number(actual)
expected_n = discover.normalize_version_number(expected)
if actual_n < expected_n:
message = ("API version %(expected)s is required, but %(actual)s "
"will be used.") % {'expected': expected,
'actual': actual}
_raise(message)
return actual
示例15: fetch
# 需要导入模块: from keystoneauth1 import adapter [as 别名]
# 或者: from keystoneauth1.adapter import Adapter [as 别名]
def fetch(self, session, requires_id=True,
base_path=None, error_message=None, **params):
"""Get a remote resource based on this instance.
:param session: The session to use for making this request.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param boolean requires_id: A boolean indicating whether resource ID
should be part of the requested URI.
:param str base_path: Base part of the URI for fetching resources, if
different from
:data:`~openstack.resource.Resource.base_path`.
:param str error_message: An Error message to be returned if
requested object does not exist.
:param dict params: Additional parameters that can be consumed.
:return: This :class:`Resource` instance.
:raises: :exc:`~openstack.exceptions.MethodNotSupported` if
:data:`Resource.allow_fetch` is not set to ``True``.
:raises: :exc:`~openstack.exceptions.ResourceNotFound` if
the resource was not found.
"""
if not self.allow_fetch:
raise exceptions.MethodNotSupported(self, "fetch")
request = self._prepare_request(requires_id=requires_id,
base_path=base_path)
session = self._get_session(session)
microversion = self._get_microversion_for(session, 'fetch')
response = session.get(request.url, microversion=microversion,
params=params)
kwargs = {}
if error_message:
kwargs['error_message'] = error_message
self.microversion = microversion
self._translate_response(response, **kwargs)
return self