本文整理汇总了Python中keystoneauth1.exceptions.NotFound方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.NotFound方法的具体用法?Python exceptions.NotFound怎么用?Python exceptions.NotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keystoneauth1.exceptions
的用法示例。
在下文中一共展示了exceptions.NotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_one
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def find_one(
self,
path,
**kwargs
):
"""Find a resource by name or ID
:param string path:
The API-specific portion of the URL path
:returns:
resource dict
"""
bulk_list = self.find_bulk(path, **kwargs)
num_bulk = len(bulk_list)
if num_bulk == 0:
msg = "none found"
raise exceptions.NotFound(msg)
elif num_bulk > 1:
msg = "many found"
raise RuntimeError(msg)
return bulk_list[0]
示例2: update_inventory
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def update_inventory(
self, resource_provider_uuid, inventories,
resource_provider_generation=None):
if resource_provider_generation is None:
resource_provider_generation = self.get_resource_provider(
resource_provider_uuid=resource_provider_uuid)['generation']
url = '/resource_providers/%s/inventories' % resource_provider_uuid
body = {
'resource_provider_generation': resource_provider_generation,
'inventories': inventories
}
try:
return self.put(url, body).json()
except ks_exc.NotFound:
raise exception.PlacementResourceProviderNotFound(
resource_provider=resource_provider_uuid)
示例3: get_external_project_owner
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def get_external_project_owner():
kc = keystone_client.get_client(pecan.request.cfg)
project_name = pecan.request.cfg.api.gnocchi_external_project_owner
domain_name = pecan.request.cfg.api.gnocchi_external_domain_name
try:
domains = kc.domains.list(name=domain_name)
project = kc.projects.find(
name=project_name,
domain_id=domains[0].id)
return project.id
except ka_exceptions.NotFound:
LOG.warning("Unable to get domain or project information. "
"domain_name : %(domain_name)s, "
"project_name : %(project_name)s",
{'domain_name': domain_name,
'project_name': project_name})
return None
示例4: update_resource_provider
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def update_resource_provider(self, resource_provider):
"""Update the resource provider identified by uuid.
:param resource_provider: The resource provider. A dict with
the uuid (required),
the name (required) and
the parent_provider_uuid (optional).
:raises PlacementResourceProviderNotFound: No such resource provider.
:raises PlacementResourceProviderNameNotUnique: Conflict with another
resource provider with
the same name.
:returns: The updated resource provider.
"""
url = '/resource_providers/%s' % resource_provider['uuid']
# update does not tolerate if the uuid is repeated in the body
update_body = resource_provider.copy()
update_body.pop('uuid')
try:
return self._put(url, update_body).json()
except ks_exc.NotFound:
raise n_exc.PlacementResourceProviderNotFound(
resource_provider=resource_provider['uuid'])
except ks_exc.Conflict:
raise n_exc.PlacementResourceProviderNameNotUnique(
name=resource_provider['name'])
示例5: delete_resource_provider_inventories
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def delete_resource_provider_inventories(self, resource_provider_uuid):
"""Delete all inventory records for the resource provider.
:param resource_provider_uuid: UUID of the resource provider.
:raises PlacementResourceProviderNotFound: If the resource provider
is not found.
:returns: None.
"""
url = '/resource_providers/%s/inventories' % (
resource_provider_uuid)
try:
self._delete(url)
except ks_exc.NotFound as e:
if "No resource provider with uuid" in e.details:
raise n_exc.PlacementResourceProviderNotFound(
resource_provider=resource_provider_uuid)
else:
raise
示例6: delete_resource_provider_inventory
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def delete_resource_provider_inventory(self, resource_provider_uuid,
resource_class):
"""Delete inventory of the resource class for a resource provider.
:param resource_provider_uuid: UUID of the resource provider.
:param resource_class: The name of the resource class
:raises PlacementResourceProviderNotFound: If the resource provider
is not found.
:raises PlacementInventoryNotFound: No inventory of class.
:returns: None.
"""
url = '/resource_providers/%s/inventories/%s' % (
resource_provider_uuid, resource_class)
try:
self._delete(url)
except ks_exc.NotFound as e:
if "No resource provider with uuid" in e.details:
raise n_exc.PlacementResourceProviderNotFound(
resource_provider=resource_provider_uuid)
elif "No inventory of class" in e.details:
raise n_exc.PlacementInventoryNotFound(
resource_provider=resource_provider_uuid,
resource_class=resource_class)
else:
raise
示例7: get_data
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def get_data(self):
manager = api.cloudkittyclient(self.request)
services = manager.rating.hashmap.get_service().get('services', [])
services = sorted(services, key=lambda service: service['name'])
list_services = []
for s in services:
try:
service = manager.info.get_metric(metric_name=s['name'])
unit = service['unit']
except exceptions.NotFound:
unit = "-"
list_services.append({
"id": s['service_id'],
"name": s['name'],
"unit": unit
})
return list_services
示例8: __init__
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def __init__(self, request, *args, **kwargs):
super(CreateFieldForm, self).__init__(request, *args, **kwargs)
service_id = kwargs['initial']['service_id']
manager = api.cloudkittyclient(request).rating.hashmap
service = manager.get_service(service_id=service_id)
self.fields['service_name'].initial = service['name']
try:
fields = manager.get_field(service_id=service['name'])['fields']
except exceptions.NotFound:
fields = None
if fields:
fields = api.identify(fields)
choices = sorted([(field, field) for field in fields['metadata']])
self.fields['field'] = forms.DynamicChoiceField(
label=_("Field"))
self.fields['field'].choices = choices
else:
self.fields['field'] = forms.CharField(
label=_("Field"))
示例9: get_allocations_for_consumer_by_provider
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def get_allocations_for_consumer_by_provider(self, context, rp_uuid,
consumer):
"""Return allocations for a consumer and a resource provider.
:param context: The zun.context.RequestContext auth context
:param rp_uuid: UUID of the resource provider
:param consumer: UUID of the consumer
:return: the resources dict of the consumer's allocation keyed by
resource classes
"""
try:
# NOTE(cdent): This trims to just the allocations being
# used on this resource provider. In the future when there
# are shared resources there might be other providers.
allocations = self.get_allocations_for_consumer(context, consumer)
return allocations.get(
rp_uuid, {}).get('resources', {})
except ks_exc.NotFound:
return {}
# TODO(hongbin): revisit the commit below
# NOTE(jaypipes): Currently, this method is ONLY used in three places:
# 1. By the scheduler to allocate resources on the selected destination
# hosts.
# 2. By the conductor LiveMigrationTask to allocate resources on a forced
# destination host. In this case, the source node allocations have
# already been moved to the migration record so the instance should not
# have allocations and _move_operation_alloc_request will not be called.
# 3. By the conductor ComputeTaskManager to allocate resources on a forced
# destination host during evacuate. This case will call the
# _move_operation_alloc_request method.
# This method should not be called by the resource tracker.
示例10: ensure_user_in_group
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def ensure_user_in_group(client, user, group):
"""Ensure user is in the specified group
:type client: keystoneclient.v3.client.Client
:type user: keystoneclient.v3.users.User
:type group: keystoneclient.v3.groups.Group
:return:
"""
try:
client.users.check_in_group(user, group)
logger.info('user %s is already in group %s', user.name, group.name)
except NotFound:
client.users.add_to_group(user, group)
logger.info('added user %s to group %s', user.name, group.name)
示例11: find
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def find(
self,
path,
value=None,
attr=None,
):
"""Find a single resource by name or ID
:param string path:
The API-specific portion of the URL path
:param string search:
search expression
:param string attr:
name of attribute for secondary search
"""
try:
ret = self._request('GET', "/%s/%s" % (path, value)).json()
except ks_exceptions.NotFound:
kwargs = {attr: value}
try:
ret = self.find_one("/%s/detail" % (path), **kwargs)
except ks_exceptions.NotFound:
msg = "%s not found" % value
raise exceptions.NotFound(msg)
return ret
示例12: delete_trust
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def delete_trust(trust_id):
LOG.debug("Deleting trust id: %s", trust_id)
auth = _get_trusts_auth_plugin(trust_id)
session = ks_session.Session(
auth=auth, verify=not CONF.keystone.allow_untrusted)
client = kc_v3.Client(session=session)
try:
client.trusts.delete(trust_id)
except ks_exceptions.NotFound:
LOG.debug("Trust id not found: %s", trust_id)
示例13: delete_trust_id
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def delete_trust_id(trust_id, auth_plugin):
"""Delete a trust previously setup for the vitrage user."""
client = get_client_on_behalf_user(auth_plugin)
try:
client.trusts.delete(trust_id)
except ka_exception.NotFound:
pass
示例14: delete_trust
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def delete_trust(ctxt):
if ctxt.trust_id:
LOG.debug("Deleting trust id: %s", ctxt.trust_id)
auth = _get_trusts_auth_plugin(ctxt.trust_id)
session = ks_session.Session(
auth=auth, verify=not CONF.keystone.allow_untrusted)
client = kc_v3.Client(session=session)
try:
client.trusts.delete(ctxt.trust_id)
except ks_exceptions.NotFound:
LOG.debug("Trust id not found: %s", ctxt.trust_id)
ctxt.trust_id = None
示例15: _test_get_inventory_not_found
# 需要导入模块: from keystoneauth1 import exceptions [as 别名]
# 或者: from keystoneauth1.exceptions import NotFound [as 别名]
def _test_get_inventory_not_found(self, details, expected_exception):
rp_uuid = uuidutils.generate_uuid()
resource_class = 'fake_resource_class'
self.mock_request.side_effect = ks_exc.NotFound(details=details)
self.assertRaises(expected_exception, self.client.get_inventory,
rp_uuid, resource_class)