本文整理汇总了Python中openstack.exceptions.HttpException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.HttpException方法的具体用法?Python exceptions.HttpException怎么用?Python exceptions.HttpException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openstack.exceptions
的用法示例。
在下文中一共展示了exceptions.HttpException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keystone_cached_conn
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def keystone_cached_conn(cloud_name, region, yaml_file):
key = (
cloud_name,
region )
if key in CACHE:
""" check the token to see if our connection is still valid """
_cloud_name, conn = CACHE[key]
try:
conn.authorize()
except HttpException:
del CACHE[key]
else:
return conn
try:
conn = _connect(cloud_name, region, yaml_file)
except Exception as e:
raise e
CACHE[key] = (conn.name, conn)
return conn
示例2: _wait_for_futures
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def _wait_for_futures(self, futures, raise_on_error=True):
'''Collect results or failures from a list of running future tasks.'''
results = []
retries = []
# Check on each result as its thread finishes
for completed in concurrent.futures.as_completed(futures):
try:
result = completed.result()
exceptions.raise_from_response(result)
results.append(result)
except (keystoneauth1.exceptions.RetriableConnectionFailure,
exceptions.HttpException) as e:
error_text = "Exception processing async task: {}".format(
str(e))
if raise_on_error:
self.log.exception(error_text)
raise
else:
self.log.debug(error_text)
# If we get an exception, put the result into a list so we
# can try again
retries.append(completed.result())
return results, retries
示例3: test_raise_http_exception
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def test_raise_http_exception(self):
response = mock.Mock()
response.status_code = 403
response.headers = {
'content-type': 'application/json',
'x-openstack-request-id': uuid.uuid4().hex,
}
exc = self.assertRaises(exceptions.HttpException,
self._do_raise, response,
error_message=self.message)
self.assertEqual(self.message, exc.message)
self.assertEqual(response.status_code, exc.status_code)
self.assertEqual(
response.headers.get('x-openstack-request-id'),
exc.request_id
)
示例4: test_server_metadata_update_forbidden
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def test_server_metadata_update_forbidden(self):
server = mock.Mock()
res_server = mock.Mock()
res_server.metadata = {
'k1': 'v1',
'forbidden_key': 'forbidden_data',
'k2': 'v2'
}
self.compute.get_server_metadata.return_value = res_server
self.compute.delete_server_metadata.side_effect = [
None, sdk_exc.HttpException(http_status=403), None]
self.compute.set_server_metadata.side_effect = [
None, sdk_exc.HttpException(http_status=403), None]
d = nova_v2.NovaClient(self.conn_params)
d.server_metadata_update(server, {'k3': 'v3', 'k4': 'v4', 'k5': 'v5'})
self.compute.set_server_metadata.assert_has_calls(
[mock.call(server, k3='v3'), mock.call(server, k4='v4'),
mock.call(server, k5='v5')], any_order=True)
self.compute.delete_server_metadata.assert_has_calls(
[mock.call(server, ['k1']), mock.call(server, ['forbidden_key']),
mock.call(server, ['k2'])], any_order=True)
示例5: __init__
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def __init__(self, prof=None, user_agent=None, **kwargs):
try:
conn = plugin.create_connection(prof=prof,
user_agent=user_agent,
**kwargs)
except exceptions.HttpException as ex:
exc.parse_exception(ex.details)
self.conn = conn
self.service = self.conn.cluster
######################################################################
# The following operations are interfaces exposed to other software
# which invokes senlinclient today.
# These methods form a temporary translation layer. This layer will be
# useless when OpenStackSDK has been adopted all senlin resources.
######################################################################
示例6: delete_network_pools
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def delete_network_pools(self, net_id):
if not self._recovered_pools:
LOG.info("Kuryr-controller not yet ready to delete network "
"pools.")
raise exceptions.ResourceNotReady(net_id)
os_net = clients.get_network_client()
# NOTE(ltomasbo): Note the pods should already be deleted, but their
# associated ports may not have been recycled yet, therefore not being
# on the available_ports_pools dict. The next call forces it to be on
# that dict before cleaning it up
self._trigger_return_to_pool()
for pool_key, ports in list(self._available_ports_pools.items()):
if self._get_pool_key_net(pool_key) != net_id:
continue
trunk_id = self._get_trunk_id(pool_key)
ports_id = [p_id for sg_ports in ports.values()
for p_id in sg_ports]
try:
self._drv_vif._remove_subports(trunk_id, ports_id)
except (os_exc.SDKException, os_exc.HttpException):
LOG.exception('Error removing subports from trunk: %s',
trunk_id)
continue
for port_id in ports_id:
try:
self._drv_vif._release_vlan_id(
self._existing_vifs[port_id].vlan_id)
del self._existing_vifs[port_id]
except KeyError:
LOG.debug('Port %s is not in the ports list.', port_id)
os_net.delete_port(port_id)
self._available_ports_pools[pool_key] = {}
示例7: _ensure
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def _ensure(self, create, find, *args):
okay_codes = (409, 500)
try:
result = create(args[0])
LOG.debug("Created %(obj)s", {'obj': result})
return result
except os_exc.HttpException as e:
if e.status_code not in okay_codes:
raise
result = find(*args)
if result:
LOG.debug("Found %(obj)s", {'obj': result})
return result
示例8: test_ensure_with_internalservererror
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def test_ensure_with_internalservererror(self):
self._verify_ensure_with_exception(
os_exc.HttpException(http_status=500))
示例9: create
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def create(self, firewall, direction, protocol=None, from_port=None,
to_port=None, cidr=None, src_dest_fw=None):
src_dest_fw_id = (src_dest_fw.id if isinstance(src_dest_fw,
OpenStackVMFirewall)
else src_dest_fw)
try:
if direction == TrafficDirection.INBOUND:
os_direction = 'ingress'
elif direction == TrafficDirection.OUTBOUND:
os_direction = 'egress'
else:
raise InvalidValueException("direction", direction)
# pylint:disable=protected-access
rule = self.provider.os_conn.network.create_security_group_rule(
security_group_id=firewall.id,
direction=os_direction,
port_range_max=to_port,
port_range_min=from_port,
protocol=protocol,
remote_ip_prefix=cidr,
remote_group_id=src_dest_fw_id)
firewall.refresh()
return OpenStackVMFirewallRule(firewall, rule.to_dict())
except HttpException as e:
firewall.refresh()
# 409=Conflict, raised for duplicate rule
if e.status_code == 409:
existing = self.find(firewall, direction=direction,
protocol=protocol, from_port=from_port,
to_port=to_port, cidr=cidr,
src_dest_fw_id=src_dest_fw_id)
return existing[0]
else:
raise e
示例10: insert_rule
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def insert_rule(self, session, **body):
"""Insert a firewall_rule into a firewall_policy in order.
:param session: The session to communicate through.
:type session: :class:`~openstack.session.Session`
:param dict body: The body requested to be updated on the router
:returns: The updated firewall policy
:rtype: :class:`~openstack.network.v2.firewall_policy.FirewallPolicy`
:raises: :class:`~openstack.exceptions.HttpException` on error.
"""
url = utils.urljoin(self.base_path, self.id, 'insert_rule')
return self._put_request(session, url, body)
示例11: remove_rule
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def remove_rule(self, session, **body):
"""Remove a firewall_rule from a firewall_policy.
:param session: The session to communicate through.
:type session: :class:`~openstack.session.Session`
:param dict body: The body requested to be updated on the router
:returns: The updated firewall policy
:rtype: :class:`~openstack.network.v2.firewall_policy.FirewallPolicy`
:raises: :class:`~openstack.exceptions.HttpException` on error.
"""
url = utils.urljoin(self.base_path, self.id, 'remove_rule')
return self._put_request(session, url, body)
示例12: _put_request
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def _put_request(self, session, url, json_data):
resp = session.put(url, json=json_data)
data = resp.json()
if not resp.ok:
message = None
if 'NeutronError' in data:
message = data['NeutronError']['message']
raise HttpException(message=message, response=resp)
self._body.attributes.update(data)
self._update_location()
return self
示例13: _do_raise
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def _do_raise(self, *args, **kwargs):
raise exceptions.HttpException(*args, **kwargs)
示例14: test_details
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def test_details(self):
details = "some details"
exc = self.assertRaises(exceptions.HttpException,
self._do_raise, self.message,
details=details)
self.assertEqual(self.message, exc.message)
self.assertEqual(details, exc.details)
示例15: test_http_status
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import HttpException [as 别名]
def test_http_status(self):
http_status = 123
exc = self.assertRaises(exceptions.HttpException,
self._do_raise, self.message,
http_status=http_status)
self.assertEqual(self.message, exc.message)
self.assertEqual(http_status, exc.status_code)