本文整理汇总了Python中keystoneauth1.exceptions.Unauthorized方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.Unauthorized方法的具体用法?Python exceptions.Unauthorized怎么用?Python exceptions.Unauthorized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keystoneauth1.exceptions
的用法示例。
在下文中一共展示了exceptions.Unauthorized方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_trust
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def create_trust(ctxt):
LOG.debug("Creating Keystone trust")
trusts_auth_plugin = _get_trusts_auth_plugin()
loader = loading.get_plugin_loader("v3token")
auth = loader.load_from_options(
auth_url=trusts_auth_plugin.auth_url,
token=ctxt.auth_token,
project_name=ctxt.project_name,
project_domain_name=ctxt.project_domain)
session = ks_session.Session(
auth=auth, verify=not CONF.keystone.allow_untrusted)
try:
trustee_user_id = trusts_auth_plugin.get_user_id(session)
except ks_exceptions.Unauthorized as ex:
LOG.exception(ex)
raise exception.NotAuthorized("Trustee authentication failed")
trustor_user_id = ctxt.user
trustor_proj_id = ctxt.tenant
roles = ctxt.roles
LOG.debug("Granting Keystone trust. Trustor: %(trustor_user_id)s, trustee:"
" %(trustee_user_id)s, project: %(trustor_proj_id)s, roles:"
" %(roles)s",
{"trustor_user_id": trustor_user_id,
"trustee_user_id": trustee_user_id,
"trustor_proj_id": trustor_proj_id,
"roles": roles})
# Trusts are not supported before Keystone v3
client = kc_v3.Client(session=session)
trust = client.trusts.create(trustor_user=trustor_user_id,
trustee_user=trustee_user_id,
project=trustor_proj_id,
impersonation=True,
role_names=roles)
LOG.debug("Trust id: %s" % trust.id)
return trust.id
示例2: __init__
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def __init__(self, error, url, username, project):
kwargs = {
"error": error,
"url": url,
"username": username,
"project": project
}
self._helpful_trace = False
from keystoneauth1 import exceptions as ks_exc
if isinstance(error, (ks_exc.ConnectionError,
ks_exc.DiscoveryFailure)):
# this type of errors is general for all users no need to include
# username, project name. The original error message should be
# self-sufficient
self.msg_fmt = self.msg_fmt_2
message = error.message
if (message.startswith("Unable to establish connection to")
or isinstance(error, ks_exc.DiscoveryFailure)):
if "Max retries exceeded with url" in message:
if "HTTPConnectionPool" in message:
splitter = ": HTTPConnectionPool"
else:
splitter = ": HTTPSConnectionPool"
message = message.split(splitter, 1)[0]
elif isinstance(error, ks_exc.Unauthorized):
message = error.message.split(" (HTTP 401)", 1)[0]
else:
# something unexpected. include exception class as well.
self._helpful_trace = True
message = "[%s] %s" % (error.__class__.__name__, str(error))
super(AuthenticationFailed, self).__init__(message=message, **kwargs)
示例3: discover_placement_attr
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def discover_placement_attr(self, vim_obj, ks_client):
"""Fetch VIM placement information
Attributes can include regions, AZ.
"""
try:
regions_list = self._find_regions(ks_client)
except (exceptions.Unauthorized, exceptions.BadRequest) as e:
LOG.warning("Authorization failed for user")
raise nfvo.VimUnauthorizedException(message=e.message)
vim_obj['placement_attr'] = {'regions': regions_list}
return vim_obj
示例4: test_register_vim_invalid_auth
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def test_register_vim_invalid_auth(self):
attrs = {'regions.list.side_effect': exceptions.Unauthorized}
self._test_register_vim_auth(attrs)
示例5: get_auth_token
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def get_auth_token():
error_message = 'Keystone request failed: {}'
try:
session = get_keystone_session()
auth_token = session.get_token()
return auth_token
except (kaexception.Unauthorized, kaexception.DiscoveryFailure) as e:
LOG.exception(error_message.format(six.text_type(e)))
raise
except Exception as e:
LOG.exception(error_message.format(six.text_type(e)))
raise
示例6: validate_credentials
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def validate_credentials(self) -> None:
try:
self.conn.auth_token
except Unauthorized as err:
raise CredentialsError(str(err))
示例7: select_destinations
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def select_destinations(self, context, containers, extra_specs):
LOG.debug("Starting to schedule for containers: %s",
[c.uuid for c in containers])
if not self.traits_ensured:
self.placement_client._ensure_traits(context, consts.CUSTOM_TRAITS)
self.traits_ensured = True
alloc_reqs_by_rp_uuid, provider_summaries, allocation_request_version \
= None, None, None
request_filter.process_reqspec(context, extra_specs)
resources = utils.resources_from_request_spec(
context, containers[0], extra_specs)
try:
res = self.placement_client.get_allocation_candidates(context,
resources)
(alloc_reqs, provider_summaries, allocation_request_version) = res
except (ks_exc.EndpointNotFound,
ks_exc.MissingAuthPlugin,
ks_exc.Unauthorized,
ks_exc.DiscoveryFailure,
ks_exc.ConnectFailure):
# We have to handle the case that we failed to connect to the
# Placement service.
alloc_reqs, provider_summaries, allocation_request_version = (
None, None, None)
if not alloc_reqs:
LOG.info("Got no allocation candidates from the Placement "
"API. This could be due to insufficient resources "
"or a temporary occurrence as compute nodes start "
"up.")
raise exception.NoValidHost(reason="")
else:
# Build a dict of lists of allocation requests, keyed by
# provider UUID, so that when we attempt to claim resources for
# a host, we can grab an allocation request easily
alloc_reqs_by_rp_uuid = collections.defaultdict(list)
for ar in alloc_reqs:
for rp_uuid in ar['allocations']:
alloc_reqs_by_rp_uuid[rp_uuid].append(ar)
selections = self.driver.select_destinations(
context, containers, extra_specs, alloc_reqs_by_rp_uuid,
provider_summaries, allocation_request_version)
return selections
示例8: create_trust
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import Unauthorized [as 别名]
def create_trust(ctxt):
if ctxt.trust_id:
return
LOG.debug("Creating Keystone trust")
trusts_auth_plugin = _get_trusts_auth_plugin()
loader = loading.get_plugin_loader("v3token")
auth = loader.load_from_options(
auth_url=trusts_auth_plugin.auth_url,
token=ctxt.auth_token,
project_name=ctxt.project_name,
project_domain_name=ctxt.project_domain_name)
session = ks_session.Session(
auth=auth, verify=not CONF.keystone.allow_untrusted)
try:
trustee_user_id = trusts_auth_plugin.get_user_id(session)
except ks_exceptions.Unauthorized as ex:
LOG.exception(ex)
raise exception.NotAuthorized("Trustee authentication failed")
trustor_user_id = ctxt.user
trustor_proj_id = ctxt.tenant
roles = ctxt.roles
LOG.debug("Granting Keystone trust. Trustor: %(trustor_user_id)s, trustee:"
" %(trustee_user_id)s, project: %(trustor_proj_id)s, roles:"
" %(roles)s",
{"trustor_user_id": trustor_user_id,
"trustee_user_id": trustee_user_id,
"trustor_proj_id": trustor_proj_id,
"roles": roles})
# Trusts are not supported before Keystone v3
client = kc_v3.Client(session=session)
trust = client.trusts.create(trustor_user=trustor_user_id,
trustee_user=trustee_user_id,
project=trustor_proj_id,
impersonation=True,
role_names=roles)
LOG.debug("Trust id: %s" % trust.id)
ctxt.trust_id = trust.id