本文整理汇总了Python中neutronclient.common.exceptions.BadRequest方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.BadRequest方法的具体用法?Python exceptions.BadRequest怎么用?Python exceptions.BadRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neutronclient.common.exceptions
的用法示例。
在下文中一共展示了exceptions.BadRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def handle(self, request, data, **kwargs):
router_id = self.initial['router_id']
try:
route = {'nexthop': data['nexthop'],
'destination': data['destination']}
api.router_static_route_add(request,
router_id,
route)
msg = _('Static route added')
LOG.debug(msg)
messages.success(request, msg)
return True
except neutron_exc.BadRequest as e:
msg = (_('Invalid format for routes : %s') % e)
LOG.info(msg)
messages.error(request, msg)
redirect = reverse(self.failure_url, args=[router_id])
exceptions.handle(request, msg, redirect=redirect)
except Exception as e:
msg = (_('Failed to add route : %s') % e)
LOG.info(msg)
messages.error(request, msg)
redirect = reverse(self.failure_url, args=[router_id])
exceptions.handle(request, msg, redirect=redirect)
示例2: args2body
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def args2body(self, parsed_args):
body = {
'direction': parsed_args.direction
}
if parsed_args.min:
body['min'] = parsed_args.min
else:
if not parsed_args.max:
raise exceptions.BadRequest('Either min or max must be set')
if parsed_args.max:
body['max'] = parsed_args.max
if parsed_args.parent:
body['parent'] = parsed_args.parent
return {self.resource: body}
示例3: check_router_type_not_changed_to_centralized
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def check_router_type_not_changed_to_centralized(self, router):
"""Step to check router is not updated from distributed to centralized.
Args:
router (dict): router dict
Raises:
AssertionError: if BadRequest is not appeared or exception message
is unexpected.
"""
exception_message = ("Migration from distributed router to "
"centralized is not supported.")
assert_that(calling(self.update_router).with_args(
router=router, distributed=False, check=False),
raises(exceptions.BadRequest, exception_message))
示例4: check_type_unchangeable_for_active_router
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def check_type_unchangeable_for_active_router(self, router):
"""Step to check that router type can't be changed for active router.
Args:
router (dict): router dict
Raises:
AssertionError: if BadRequest is not appeared or exception message
is unexpected.
"""
exception_message = (
"Cannot upgrade active router to distributed. "
"Please set router admin_state_up to False prior to upgrade")
assert_that(
calling(self.update_router).with_args(
router=router, distributed=True, check=False),
raises(exceptions.BadRequest, exception_message))
示例5: allocate_floating_ip
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def allocate_floating_ip(self, context, pool=None):
"""Add a floating IP to a project from a pool."""
client = get_client(context)
pool = pool or CONF.default_floating_pool
pool_id = self._get_floating_ip_pool_id_by_name_or_id(client, pool)
param = {'floatingip': {'floating_network_id': pool_id}}
try:
fip = client.create_floatingip(param)
except (neutron_client_exc.IpAddressGenerationFailureClient,
neutron_client_exc.ExternalIpAddressExhaustedClient) as e:
raise exception.NoMoreFloatingIps(six.text_type(e))
except neutron_client_exc.OverQuotaClient as e:
raise exception.FloatingIpLimitExceeded(six.text_type(e))
except neutron_client_exc.BadRequest as e:
raise exception.FloatingIpBadRequest(six.text_type(e))
return fip['floatingip']['floating_ip_address']
示例6: create_security_group
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def create_security_group(self, context, name, description):
neutron = neutronapi.get_client(context)
body = self._make_neutron_security_group_dict(name, description)
try:
security_group = neutron.create_security_group(
body).get('security_group')
except n_exc.BadRequest as e:
raise exception.Invalid(six.text_type(e))
except n_exc.NeutronClientException as e:
exc_info = sys.exc_info()
LOG.exception(_LE("Neutron Error creating security group %s"),
name)
if e.status_code == 401:
# TODO(arosen) Cannot raise generic response from neutron here
# as this error code could be related to bad input or over
# quota
raise exc.HTTPBadRequest()
elif e.status_code == 409:
self.raise_over_quota(six.text_type(e))
six.reraise(*exc_info)
return self._convert_to_nova_security_group_format(security_group)
示例7: test_loadbalancer_update_configs
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def test_loadbalancer_update_configs(self,
update_lb_key,
update_value,
setup_with_loadbalancer):
ncpm, active_loadbalancer = setup_with_loadbalancer
active_loadbalancer_id = active_loadbalancer['loadbalancer']['id']
self.loadbalancer_updater.call_factory(
ncpm, 'update_loadbalancer', active_loadbalancer_id
)
update_dict = {update_lb_key: update_value}
try:
updated = self.loadbalancer_updater.call_method(
lbconf={'loadbalancer': update_dict}
)
except BadRequest as exc:
exc_message_first_line = exc.message.split('\n')[0]
expected_first_line =\
'Cannot update read-only attribute %s' % update_lb_key
assert exc_message_first_line == expected_first_line
return
assert updated['loadbalancer'][update_lb_key] == update_value
示例8: test_healthmonitor_update_configs
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def test_healthmonitor_update_configs(self,
update_healthmonitor_key,
update_value,
setup_with_healthmonitor):
ncpm, active_healthmonitor, pool, member = setup_with_healthmonitor
active_healthmonitor_id = active_healthmonitor['healthmonitor']['id']
self.healthmonitor_updater.call_factory(
ncpm, 'update_lbaas_healthmonitor', active_healthmonitor_id
)
if update_healthmonitor_key == 'expected_codes':
update_value = '300'
update_dict = {update_healthmonitor_key: update_value}
try:
updated = self.healthmonitor_updater.call_method(
lbaas_healthmonitor_conf={'healthmonitor': update_dict}
)
except BadRequest as exc:
exc_message_first_line = exc.message.split('\n')[0]
expected_first_line =\
'Cannot update read-only attribute %s' %\
update_healthmonitor_key
assert exc_message_first_line == expected_first_line
return
assert updated['healthmonitor'][update_healthmonitor_key] ==\
update_value
示例9: args2body
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def args2body(self, parsed_args):
body = {
'network': parsed_args.network
}
if parsed_args.min:
body['min'] = parsed_args.min
else:
raise exceptions.BadRequest('min must be set')
if parsed_args.max:
body['max'] = parsed_args.max
return {self.resource: body}
示例10: _update_port_dns_name
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def _update_port_dns_name(self, context, instance, network, port_id,
neutron):
"""Update an instance port dns_name attribute with instance.hostname.
The dns_name attribute of a port on a network with a non-blank
dns_domain attribute will be sent to the external DNS service
(Designate) if DNS integration is enabled in Neutron. This requires the
assignment of the dns_name to the port to be done with a Neutron client
using the user's context. allocate_for_instance uses a port with admin
context if the port binding extensions is enabled in Neutron. In this
case, we assign in this method the dns_name attribute to the port with
an additional update request. Only a very small fraction of ports will
require this additional update request.
"""
if (constants.DNS_INTEGRATION in self.extensions and
self._has_port_binding_extension(context) and
network.get('dns_domain')):
try:
port_req_body = {'port': {'dns_name': instance.hostname}}
neutron.update_port(port_id, port_req_body)
except neutron_client_exc.BadRequest:
LOG.warning(_LW('Neutron error: Instance hostname '
'%(hostname)s is not a valid DNS name'),
{'hostname': instance.hostname}, instance=instance)
msg = (_('Instance hostname %(hostname)s is not a valid DNS '
'name') % {'hostname': instance.hostname})
raise exception.InvalidInput(reason=msg)
示例11: test_allocate_floating_ip_no_ipv4_subnet
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def test_allocate_floating_ip_no_ipv4_subnet(self):
api = neutronapi.API()
net_id = uuid.uuid4()
error_msg = ('Bad floatingip request: Network %s does not contain '
'any IPv4 subnet' % net_id)
with test.nested(
mock.patch.object(client.Client, 'create_floatingip'),
mock.patch.object(api,
'_get_floating_ip_pool_id_by_name_or_id')) as (
create_mock, get_mock):
create_mock.side_effect = exceptions.BadRequest(error_msg)
self.assertRaises(exception.FloatingIpBadRequest,
api.allocate_floating_ip, self.context,
'ext_net')
示例12: test_create_security_group_with_bad_request
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def test_create_security_group_with_bad_request(self):
name = 'test-security-group'
description = None
body = {'security_group': {'name': name,
'description': description}}
message = "Invalid input. Reason: 'None' is not a valid string."
self.moxed_client.create_security_group(
body).AndRaise(n_exc.BadRequest(message=message))
self.mox.ReplayAll()
sg_api = neutron_driver.SecurityGroupAPI()
self.assertRaises(exception.Invalid,
sg_api.create_security_group, self.context, name,
description)
示例13: test_listener_update_configs
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def test_listener_update_configs(self,
update_listener_key,
update_value,
setup_with_listener):
ncpm, active_listener = setup_with_listener
active_listener_id = active_listener['listener']['id']
self.listener_updater.call_factory(
ncpm, 'update_listener', active_listener_id
)
if update_listener_key == 'default_tls_container_ref':
update_value = 'string_for_read_only_fail'
elif update_listener_key == 'sni_container_refs':
# NOTE: THIS TEST WILL ALWAYS SUCCEED
return NotImplemented
update_dict = {update_listener_key: update_value}
try:
updated = self.listener_updater.call_method(
listener_conf={'listener': update_dict}
)
except BadRequest as exc:
exc_message_first_line = exc.message.split('\n')[0]
expected_first_line =\
'Cannot update read-only attribute %s' % update_listener_key
assert exc_message_first_line == expected_first_line
return
assert updated['listener'][update_listener_key] == update_value
示例14: test_pool_update_configs
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def test_pool_update_configs(self,
update_pool_key,
update_value,
setup_with_pool):
ncpm, active_pool = setup_with_pool
active_pool_id = active_pool['pool']['id']
self.pool_updater.call_factory(
ncpm, 'update_lbaas_pool', active_pool_id
)
if update_pool_key == 'lb_algorithm':
if 'ROUND_ROBIN' in update_value:
update_value = 'SOURCE_IP'
else:
update_value = 'ROUND_ROBIN'
elif update_pool_key == 'session_persistence':
update_value = None
update_dict = {update_pool_key: update_value}
try:
updated = self.pool_updater.call_method(
lbaas_pool_conf={'pool': update_dict}
)
except BadRequest as exc:
exc_message_first_line = exc.message.split('\n')[0]
expected_first_line =\
'Cannot update read-only attribute %s' % update_pool_key
assert exc_message_first_line == expected_first_line
return
assert updated['pool'][update_pool_key] == update_value
示例15: test_member_update_configs
# 需要导入模块: from neutronclient.common import exceptions [as 别名]
# 或者: from neutronclient.common.exceptions import BadRequest [as 别名]
def test_member_update_configs(self,
update_member_key,
update_value,
setup_with_pool_member):
ncpm, active_pool, active_member = setup_with_pool_member
active_member_id = active_member['member']['id']
self.member_updater.call_factory(
ncpm, 'update_lbaas_member', active_member_id
)
if update_member_key == 'lb_algorithm':
if 'ROUND_ROBIN' in update_value:
update_value = 'SOURCE_IP'
else:
update_value = 'ROUND_ROBIN'
elif update_member_key == 'session_persistence':
update_value = None
update_dict = {update_member_key: update_value}
try:
updated = self.member_updater.call_method(
pool_id=active_pool['pool']['id'],
member_conf={'member': update_dict}
)
except BadRequest as exc:
exc_message_first_line = exc.message.split('\n')[0]
expected_first_line =\
'Cannot update read-only attribute %s' % update_member_key
assert exc_message_first_line == expected_first_line
return
assert updated['member'][update_member_key] == update_value