当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.BadRequest方法代码示例

本文整理汇总了Python中neutron_lib.exceptions.BadRequest方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.BadRequest方法的具体用法?Python exceptions.BadRequest怎么用?Python exceptions.BadRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neutron_lib.exceptions的用法示例。


在下文中一共展示了exceptions.BadRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _validate_network_has_router_assoc

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _validate_network_has_router_assoc(self, context, network, plugin):
        filter = {'network_id': [network['id']],
                  'device_owner': [const.DEVICE_OWNER_ROUTER_INTF]}
        router_port = plugin.get_ports(context, filters=filter)
        if router_port:
            router_id = router_port[0]['device_id']
            filter = {'tenant_id': [network['tenant_id']]}
            bgpvpns = self.driver.get_bgpvpns(context, filters=filter)
            bgpvpns = [str(bgpvpn['id']) for bgpvpn in bgpvpns
                       if router_id in bgpvpn['routers']]
            if bgpvpns:
                msg = ('Network %(net_id)s is linked to a router which is '
                       'already associated to bgpvpn(s) %(bgpvpns)s'
                       % {'net_id': network['id'],
                          'bgpvpns': bgpvpns}
                       )
                raise n_exc.BadRequest(resource='bgpvpn', msg=msg) 
开发者ID:openstack,项目名称:networking-bgpvpn,代码行数:19,代码来源:plugin.py

示例2: _validate_router_has_net_assocs

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _validate_router_has_net_assocs(self, context, router, plugin):
        filter = {'device_id': [router['id']],
                  'device_owner': [const.DEVICE_OWNER_ROUTER_INTF]}
        router_ports = plugin.get_ports(context, filters=filter)
        if router_ports:
            filter = {'tenant_id': [router['tenant_id']]}
            bgpvpns = self.driver.get_bgpvpns(context, filters=filter)
            for port in router_ports:
                bgpvpns = [str(bgpvpn['id']) for bgpvpn in bgpvpns
                           if port['network_id'] in bgpvpn['networks']]
                if bgpvpns:
                    msg = ('router %(rtr_id)s has an attached network '
                           '%(net_id)s which is already associated to '
                           'bgpvpn(s) %(bgpvpns)s'
                           % {'rtr_id': router['id'],
                              'net_id': port['network_id'],
                              'bgpvpns': bgpvpns})
                    raise n_exc.BadRequest(resource='bgpvpn', msg=msg) 
开发者ID:openstack,项目名称:networking-bgpvpn,代码行数:20,代码来源:plugin.py

示例3: create_bgpvpn_router_association

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def create_bgpvpn_router_association(self, context, bgpvpn_id,
                                         router_association):
        router_assoc = router_association['router_association']
        router = self._validate_router(context, router_assoc['router_id'])
        bgpvpn = self.get_bgpvpn(context, bgpvpn_id)
        if not bgpvpn['type'] == constants.BGPVPN_L3:
            msg = ("Router associations require the bgpvpn to be of type %s"
                   % constants.BGPVPN_L3)
            raise n_exc.BadRequest(resource='bgpvpn', msg=msg)
        if not router['tenant_id'] == bgpvpn['tenant_id']:
            msg = "router doesn't belong to the bgpvpn owner"
            raise n_exc.NotAuthorized(resource='bgpvpn', msg=msg)
        if not (router_assoc['tenant_id'] == bgpvpn['tenant_id']):
            msg = "router association and bgpvpn should " \
                  "belong to the same tenant"
            raise n_exc.NotAuthorized(resource='bgpvpn', msg=msg)
        return self.driver.create_router_assoc(context, bgpvpn_id,
                                               router_assoc) 
开发者ID:openstack,项目名称:networking-bgpvpn,代码行数:20,代码来源:plugin.py

示例4: _get_id_for

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _get_id_for(self, resource, id_name):
        try:
            uuid = resource[id_name]
            msg = validators.validate_uuid(uuid)
        except KeyError:
            msg = _("%s must be specified") % id_name
        if msg:
            raise n_exc.BadRequest(resource=bgp_ext.BGP_SPEAKER_RESOURCE_NAME,
                                   msg=msg)
        return uuid 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:12,代码来源:bgp_db.py

示例5: test_add_bgp_peer_without_id

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def test_add_bgp_peer_without_id(self):
        with self.subnetpool_with_address_scope(4,
                                                prefixes=['8.0.0.0/8']) as sp:
            with self.bgp_speaker(sp['ip_version'], 1234) as speaker:
                self.assertRaises(n_exc.BadRequest,
                                  self.bgp_plugin.add_bgp_peer,
                                  self.context,
                                  speaker['id'],
                                  {}) 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:11,代码来源:test_bgp_db.py

示例6: test_add_bgp_peer_with_bad_id

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def test_add_bgp_peer_with_bad_id(self):
        with self.subnetpool_with_address_scope(4,
                                                prefixes=['8.0.0.0/8']) as sp:
            with self.bgp_speaker(sp['ip_version'], 1234) as speaker:
                self.assertRaises(n_exc.BadRequest,
                                  self.bgp_plugin.add_bgp_peer,
                                  self.context,
                                  speaker['id'],
                                  {'bgp_peer_id': 'aaa'}) 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:11,代码来源:test_bgp_db.py

示例7: test_add_bgp_peer_with_none_id

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def test_add_bgp_peer_with_none_id(self):
        with self.subnetpool_with_address_scope(4,
                                                prefixes=['8.0.0.0/8']) as sp:
            with self.bgp_speaker(sp['ip_version'], 1234) as speaker:
                self.assertRaises(n_exc.BadRequest,
                                  self.bgp_plugin.add_bgp_peer,
                                  self.context,
                                  speaker['id'],
                                  {'bgp_peer_id': None}) 
开发者ID:openstack,项目名称:neutron-dynamic-routing,代码行数:11,代码来源:test_bgp_db.py

示例8: _validate_network_type

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _validate_network_type(self, context, network_id):
        our_types = [m_const.TYPE_MIDONET, m_const.TYPE_UPLINK]
        network = self._core_plugin.get_network(context, network_id)
        for seg in self._segments(network):
            if seg[pnet.NETWORK_TYPE] in our_types:
                return
        LOG.warning("Incompatible network %s", network)
        raise n_exc.BadRequest(resource='router', msg='Incompatible network') 
开发者ID:openstack,项目名称:networking-midonet,代码行数:10,代码来源:l3_midonet.py

示例9: add_bgp_peer

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def add_bgp_peer(self, context, bgp_speaker_id, bgp_peer_info):
        # TODO(kengo): This is temporary workaround until upstream raise
        # an error when dictionary without 'bgp_peer_id' key is specified.
        if not self._get_id_for(bgp_peer_info, 'bgp_peer_id'):
            raise nexception.BadRequest(
                resource=bgp.BGP_SPEAKER_RESOURCE_NAME,
                msg="bgp_peer_id must be specified")
        with db_api.CONTEXT_WRITER.using(context):
            # In MidoNet, bgp-peer can be related to only one bgp-speaker.
            if self._get_bgp_speakers_by_bgp_peer_binding(
                    context, bgp_peer_info['bgp_peer_id']):
                raise bsri.MidonetBgpPeerInUse(
                    id=bgp_peer_info['bgp_peer_id'])
            if not self.get_router_associated_with_bgp_speaker(
                    context, bgp_speaker_id):
                # External network must be associated with the bgp speaker.
                raise bsri.ExternalNetworkUnbound()
            info = super(MidonetBgpPlugin, self).add_bgp_peer(
                context, bgp_speaker_id, bgp_peer_info)
            # get peer info for MidoNet
            bgp_peer = super(MidonetBgpPlugin, self).get_bgp_peer(
                context, info['bgp_peer_id'])
            # merge bgp_speaker information for MidoNet
            bgp_peer['bgp_speaker'] = self.get_bgp_speaker(
                context, bgp_speaker_id)
            self.client.create_bgp_peer_precommit(context, bgp_peer)

        try:
            self.client.create_bgp_peer_postcommit(bgp_peer)
        except Exception as ex:
            LOG.error("Failed to create MidoNet resources to add bgp "
                      "peer. bgp_peer=%(bgp_peer)s, "
                      "bgp_speaker_id=%(bgp_speaker_id)s, error=%(err)r",
                      {"bgp_peer": bgp_peer, "bgp_speaker_id": bgp_speaker_id,
                       "err": ex})
            with excutils.save_and_reraise_exception():
                super(MidonetBgpPlugin, self).remove_bgp_peer(
                    context, bgp_speaker_id, bgp_peer_info)

        return info 
开发者ID:openstack,项目名称:networking-midonet,代码行数:42,代码来源:plugin.py

示例10: _validate_network_for_floatingip

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _validate_network_for_floatingip(self, context, net_id):
        if not any(self._core_plugin._get_network(context, net_id).subnets):
            msg = _("Network %s does not contain any subnet") % net_id
            raise n_exc.BadRequest(resource='floatingip', msg=msg)

    # REVISIT(bikfalvi): This method is a copy of the base class method,
    # modified to use the _port_fixed_ips hook and replace the network
    # validation from IPv4 to any IP.
    # NOTE(yamamoto): And Floating IP QoS stuff commented out 
开发者ID:openstack,项目名称:networking-midonet,代码行数:11,代码来源:l3_db_midonet.py

示例11: _process_mido_portbindings_create_and_update

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _process_mido_portbindings_create_and_update(self, context, port_data,
                                                     port):

        port_id = port['id']

        # Set profile to {} if the binding:profile key exists but set to None.
        # This is for the special handling in the case the user wants to remove
        # the binding.
        profile = None
        if portbindings.PROFILE in port_data:
            profile = port_data.get(portbindings.PROFILE) or {}
        profile_set = validators.is_attr_set(profile)

        if_name = profile.get('interface_name') if profile_set else None
        if profile_set and profile:
            # Update or create, so validate the inputs
            if not if_name:
                msg = 'The interface name was not provided or empty'
                raise n_exc.BadRequest(resource='port', msg=msg)

            if self.get_port_host(context, port_id) is None:
                msg = 'Cannot set binding because the host is not bound'
                raise n_exc.BadRequest(resource='port', msg=msg)

        with context.session.begin(subtransactions=True):
            bind_port = context.session.query(PortBindingInfo).filter_by(
                port_id=port_id).first()
            if profile_set:
                if bind_port:
                    if if_name:
                        bind_port.interface_name = if_name
                    else:
                        context.session.delete(bind_port)
                elif if_name:
                    context.session.add(PortBindingInfo(
                        port_id=port_id, interface_name=if_name))
            else:
                if_name = bind_port.interface_name if bind_port else None

        self._extend_mido_portbinding(port, if_name) 
开发者ID:openstack,项目名称:networking-midonet,代码行数:42,代码来源:port_binding_db.py

示例12: _validate_port_create

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _validate_port_create(self, port):
        if (port.get('device_owner') == n_const.DEVICE_OWNER_ROUTER_GW
                and not port['fixed_ips']):
            msg = (_("No IPs assigned to the gateway port for"
                     " router %s") % port['device_id'])
            raise n_exc.BadRequest(resource='router', msg=msg) 
开发者ID:openstack,项目名称:networking-midonet,代码行数:8,代码来源:mech_driver.py

示例13: _notify_adding_interface_to_router

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def _notify_adding_interface_to_router(self, resource, event, trigger,
                                           **kwargs):
        context = kwargs.get('context')
        network_id = kwargs.get('network_id')
        router_id = kwargs.get('router_id')
        try:
            routers_bgpvpns = self.driver.get_bgpvpns(
                context,
                filters={
                    'routers': [router_id],
                },
            )
        except bgpvpn.BGPVPNRouterAssociationNotSupported:
            return
        nets_bgpvpns = self.driver.get_bgpvpns(
            context,
            filters={
                'networks': [network_id],
                'type': [constants.BGPVPN_L3],
            },
        )

        if routers_bgpvpns and nets_bgpvpns:
            msg = _('It is not allowed to add an interface to a router if '
                    'both the router and the network are bound to an '
                    'L3 BGPVPN.')
            raise n_exc.BadRequest(resource='bgpvpn', msg=msg) 
开发者ID:openstack,项目名称:networking-bgpvpn,代码行数:29,代码来源:plugin.py

示例14: get_and_validate_sort_keys

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def get_and_validate_sort_keys(sorts, model):
    """Extract sort keys from sorts and ensure they are valid for the model.

    :param sorts: A list of (key, direction) tuples.
    :param model: A sqlalchemy ORM model class.
    :returns: A list of the extracted sort keys.
    :raises BadRequest: If a sort key attribute references another resource
        and cannot be used in the sort.
    """

    sort_keys = [s[0] for s in sorts]
    for sort_key in sort_keys:
        try:
            sort_key_attr = getattr(model, sort_key)
        except AttributeError:
            # Extension attributes don't support sorting. Because it
            # existed in attr_info, it will be caught here.
            msg = _("'%s' is an invalid attribute for sort key") % sort_key
            raise n_exc.BadRequest(resource=model.__tablename__, msg=msg)
        if isinstance(sort_key_attr.property,
                      properties.RelationshipProperty):
            msg = _("Attribute '%(attr)s' references another resource and "
                    "cannot be used to sort '%(resource)s' resources"
                    ) % {'attr': sort_key, 'resource': model.__tablename__}
            raise n_exc.BadRequest(resource=model.__tablename__, msg=msg)

    return sort_keys 
开发者ID:openstack,项目名称:neutron-lib,代码行数:29,代码来源:utils.py

示例15: test_bad_request

# 需要导入模块: from neutron_lib import exceptions [as 别名]
# 或者: from neutron_lib.exceptions import BadRequest [as 别名]
def test_bad_request(self):
        self._check_nexc(
            ne.BadRequest,
            _('Bad A request: B.'),
            resource='A', msg='B') 
开发者ID:openstack,项目名称:neutron-lib,代码行数:7,代码来源:test_exceptions.py


注:本文中的neutron_lib.exceptions.BadRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。