def _build_group_expr_str(group_dict, cmd): group_expr_arr = [] buckets = None group_id = None if cmd != 'del': if "group_id" not in group_dict: msg = _("Must specify one group Id on group addition" " or modification") raise exceptions.InvalidInput(error_message=msg) group_id = "group_id=%s" % group_dict.pop('group_id') if cmd != 'remove-buckets': if "buckets" not in group_dict: msg = _("Must specify one or more buckets on group addition/" "modification or buckets insertion/deletion") raise exceptions.InvalidInput(error_message=msg) buckets = "%s" % group_dict.pop('buckets') if group_id: group_expr_arr.append(group_id) for key, value in group_dict.items(): group_expr_arr.append("%s=%s" % (key, value)) if buckets: group_expr_arr.append(buckets) return ','.join(group_expr_arr)
def verify_route_target_number_range(rt_nn_range): """Raise an exception for invalid tags or malformed range.""" for rt_nn in rt_nn_range: if not is_valid_route_target_number(rt_nn): raise NetworkRouteTargetRangeError( rt_nn_range=rt_nn_range, error=_("%s is not a valid Route Target number") % rt_nn) if rt_nn_range[1] < rt_nn_range[0]: raise NetworkRouteTargetRangeError( rt_nn_range=rt_nn_range, error=_("End of Route Target number range is less than start of " "Route Target number range"))
def validate_provider_segment(self, segment): physical_network = segment.get(api.PHYSICAL_NETWORK) if physical_network: msg = _("provider:physical_network specified for %s " "network") % segment.get(api.NETWORK_TYPE) raise exc.InvalidInput(error_message=msg) for key, value in six.iteritems(segment): if value and key not in [api.NETWORK_TYPE, api.SEGMENTATION_ID]: msg = _("%s prohibited for Route Target provider \ network") % key raise exc.InvalidInput(error_message=msg)
class NetworkRouteTargetRangeError(exc.NeutronException): message = _("Invalid network Route Target number range: '%(rt_nn_range)s' " "- '%(error)s'") def __init__(self, **kwargs): # Convert rt_nn_range tuple to 'start:end' format for display if isinstance(kwargs['rt_nn_range'], tuple): kwargs['rt_nn_range'] = "%d:%d" % kwargs['rt_nn_range'] super(NetworkRouteTargetRangeError, self).__init__(**kwargs)
def _notification_fanout(self, context, method, bgpvpn): LOG.debug(_('Fanout notify BGP VPN agents at %(topic)s ' 'the message %(method)s with %(bgpvpn)s'), {'topic': self.topic_bgpvpn_update, 'method': method, 'bgpvpn': bgpvpn}) cctxt = self.client.prepare(topic=self.topic_bgpvpn_update, fanout=True) cctxt.cast(context, method, bgpvpn=bgpvpn)
def _notification_host(self, context, method, port_bgpvpn_info, host): LOG.debug(_('Notify BGP VPN agent %(host)s at %(topic)s ' 'the message %(method)s with %(port_bgpvpn_info)s'), {'host': host, 'topic': self.topic_bgpvpn_update, 'method': method, 'port_bgpvpn_info': port_bgpvpn_info}) cctxt = self.client.prepare(topic=self.topic_bgpvpn_update, server=host) cctxt.cast(context, method, port_bgpvpn_info=port_bgpvpn_info)
def release_segment(self, session, segment): rt_nn = segment[api.SEGMENTATION_ID] with session.begin(subtransactions=True): try: alloc = (session.query(RouteTargetAllocation). filter_by(rt_nn=rt_nn). with_lockmode('update'). one()) alloc.allocated = False for lo, hi in self.rt_nn_ranges: if lo <= rt_nn <= hi: LOG.debug(_("Releasing Route Target number %s to " "pool"), rt_nn) break else: session.delete(alloc) LOG.debug(_("Releasing Route Target number %s outside " "pool"), rt_nn) except sa_exc.NoResultFound: LOG.warning(_LW("Route Target number %(rt_nn)s not found"), {'rt_nn': rt_nn})
def verify_route_target_number_range(rt_nn_range): """Raise an exception for invalid tags or malformed range.""" for rt_nn in rt_nn_range: if not is_valid_route_target_number(rt_nn): raise NetworkRouteTargetRangeError( rt_nn_range=rt_nn_range, error="%s is not a valid Route Target number" % rt_nn) if rt_nn_range[1] < rt_nn_range[0]: raise NetworkRouteTargetRangeError( rt_nn_range=rt_nn_range, error=_("End of Route Target number range is less than start of " "Route Target number range"))
def _sync_route_target_allocations(self): """Synchronize route_target_allocations table with configured ranges""" # Determine current configured allocatable route targets rt_nns = set() for rt_nn_range in self.rt_nn_ranges: rt_nn_min, rt_nn_max = rt_nn_range if rt_nn_max + 1 - rt_nn_min > MAX_RT_NN: LOG.error(_("Skipping unreasonable route target range " "%(rt_nn_min)s:%(rt_nn_max)s"), {'rt_nn_min': rt_nn_min, 'rt_nn_max': rt_nn_max}) else: rt_nns |= set(six.moves.range(rt_nn_min, rt_nn_max + 1)) session = db_api.get_session() with session.begin(subtransactions=True): # Remove from table unallocated route target not currently # allocatable allocs = session.query(RouteTargetAllocation ).with_lockmode("update") for alloc in allocs: try: # See if route target is allocatable rt_nns.remove(alloc.rt_nn) except KeyError: # Route target not allocatable, so check if its allocated if not alloc.allocated: # Not allocated, so remove it from table LOG.debug(_("Removing route target %s from pool"), alloc.rt_nn) session.delete(alloc) # Add missing allocatable route targets to table for rt_nn in sorted(rt_nns): alloc = RouteTargetAllocation(rt_nn=rt_nn) session.add(alloc)
def do_action_groups(self, action, kwargs_list): group_strs = [_build_group_expr_str(kw, action) for kw in kwargs_list] options = ['-'] if action == 'add' or action == 'del': cmd = '%s-groups' % action elif action == 'mod': cmd = '%s-group' % action options.insert(0, '--may-create') elif action == 'insert-buckets' or action == 'remove-buckets': cmd = action else: msg = _("Action is illegal") raise exceptions.InvalidInput(error_message=msg) if action == 'del' and {} in kwargs_list: self.run_ofctl(cmd, []) else: self.run_ofctl(cmd, options, '\n'.join(group_strs))
class RouteTargetInUse(exc.InUse): message = _("Unable to create the network. " "The route target %(rt_nn)s is in use.")
from neutron.db import api as db_api from neutron.plugins.ml2 import driver_api as api from neutron.plugins.ml2.drivers import helpers from neutron_lib.db import model_base from neutron_lib import exceptions as exc LOG = log.getLogger(__name__) MIN_RT_NN = 1 MAX_RT_NN = 2 ** 16 - 1 route_target_opts = [ cfg.IntOpt('rt_asn', default=64512, help=_("Route Target Autonomous System number.")), cfg.ListOpt('rt_nn_ranges', default=[], help=_("Comma-separated list of <rt_nn_min>:<rt_nn_max> tuples" " enumerating ranges of Route Target number that are " "available for tenant network allocation")), ] cfg.CONF.register_opts(route_target_opts, "ml2_type_route_target") # TODO(tmorin): find a clean way to not collide in the segment type namespace TYPE_ROUTE_TARGET = 'route_target' class NetworkRouteTargetRangeError(exc.NeutronException): message = _("Invalid network Route Target number range: '%(rt_nn_range)s' "
from neutron.plugins.ml2.drivers.openvswitch.agent import vlanmanager from neutron_lib.agent import l2_extension from neutron_lib.api.definitions import bgpvpn from neutron_lib.api.definitions import bgpvpn_routes_control as bgpvpn_rc from neutron_lib.callbacks import events from neutron_lib.callbacks import registry from neutron_lib.callbacks import resources from neutron_lib import constants as n_const LOG = logging.getLogger(__name__) bagpipe_bgpvpn_opts = [ cfg.StrOpt('mpls_bridge', default='br-mpls', help=_("OVS MPLS bridge to use")), ] # these options are for internal use only (fullstack tests), and hence # better kept in a separate table not looked at by oslo gen confi hooks internal_opts = [ cfg.StrOpt('tun_to_mpls_peer_patch_port', default='patch-to-mpls', help=_("OVS Peer patch port in tunnel bridge to MPLS bridge ")), cfg.StrOpt('mpls_to_tun_peer_patch_port', default='patch-from-tun', help=_("OVS Peer patch port in MPLS bridge to tunnel bridge ")), cfg.StrOpt('mpls_to_int_peer_patch_port', default='patch-mpls-to-int', help=_("OVS Peer patch port in MPLS bridge to int bridge ")), cfg.StrOpt('int_to_mpls_peer_patch_port',
BAGPIPE_NOTIFIERS = [BAGPIPE_NOTIFIER, BGPVPN_NOTIFIER] EVPN = "evpn" IPVPN = "ipvpn" VPN_TYPES = [EVPN, IPVPN] BGPVPN_L2 = "l2vpn" BGPVPN_L3 = "l3vpn" BGPVPN_TYPES = [BGPVPN_L2, BGPVPN_L3] BGPVPN_TYPES_MAP = {BGPVPN_L2: EVPN, BGPVPN_L3: IPVPN} bagpipe_bgp_opts = [ cfg.IntOpt( "ping_interval", default=10, help=_("The number of seconds the bagpipe-bgp client will " "wait between polling for restart detection."), ), cfg.StrOpt("bagpipe_bgp_ip", default="127.0.0.1", help=_("bagpipe-bgp REST service IP address.")), cfg.IntOpt("bagpipe_bgp_port", default=8082, help=_("bagpipe-bgp REST service IP port.")), cfg.StrOpt("mpls_bridge", default="br-mpls", help=_("OVS MPLS bridge to use")), cfg.StrOpt( "tun_to_mpls_peer_patch_port", default="patch-to-mpls", help=_("OVS Peer patch port in tunnel bridge to MPLS bridge " "(traffic to MPLS bridge)"), ), cfg.StrOpt( "tun_from_mpls_peer_patch_port", default="patch-from-mpls", help=_("OVS Peer patch port in tunnel bridge to MPLS bridge " "(traffic from MPLS bridge)"), ), cfg.StrOpt(
from networking_bagpipe.bagpipe_bgp import constants as bbgp_const from neutron.conf.agent import common as config from neutron_lib import constants as n_const from neutron_lib import exceptions as n_exc LOG = logging.getLogger(__name__) # Having this at line 231 is apparently not enough, so adding here as well: # pylint: disable=not-callable bagpipe_bgp_opts = [ cfg.IntOpt('ping_interval', default=10, help=_("The number of seconds the bagpipe-bgp client will " "wait between polling for restart detection.")), cfg.PortOpt('bagpipe_bgp_port', default=8082, help=_("bagpipe-bgp REST service IP port.")), ] # these options are for internal use only (fullstack tests), and hence # better kept in a separate table not looked at by oslo gen confi hooks internal_opts = [ cfg.HostAddressOpt('bagpipe_bgp_ip', default='127.0.0.1', help=_("bagpipe-bgp REST service IP address.")), ] cfg.CONF.register_opts(bagpipe_bgp_opts, "BAGPIPE") cfg.CONF.register_opts(internal_opts, "BAGPIPE")
from neutron.db import api as db_api from neutron.plugins.ml2.drivers import helpers from neutron_lib.db import model_base from neutron_lib import exceptions as exc from neutron_lib.plugins.ml2 import api LOG = log.getLogger(__name__) MIN_RT_NN = 1 MAX_RT_NN = 2 ** 16 - 1 route_target_opts = [ cfg.IntOpt('rt_asn', default=64512, help=_("Route Target Autonomous System number.")), cfg.ListOpt('rt_nn_ranges', default=[], help=_("Comma-separated list of <rt_nn_min>:<rt_nn_max> tuples" " enumerating ranges of Route Target number that are " "available for tenant network allocation")), ] cfg.CONF.register_opts(route_target_opts, "ml2_type_route_target") # TODO(tmorin): find a clean way to not collide in the segment type namespace TYPE_ROUTE_TARGET = 'route_target' class NetworkRouteTargetRangeError(exc.NeutronException): message = _("Invalid network Route Target number range: '%(rt_nn_range)s' "
# BGPVPN service VPN types BGPVPN_L2 = 'l2vpn' BGPVPN_L3 = 'l3vpn' BGPVPN_TYPES = [BGPVPN_L2, BGPVPN_L3] # Map from BGPVPN service VPN types to bagpipe-bgp VPN types BGPVPN_TYPES_MAP = {BGPVPN_L2: EVPN, BGPVPN_L3: IPVPN} RT_IMPORT = 'import_rt' RT_EXPORT = 'export_rt' RT_TYPES = [RT_IMPORT, RT_EXPORT] LINUXIF_PREFIX = "patch2tun" bagpipe_bgp_opts = [ cfg.IntOpt('ping_interval', default=10, help=_("The number of seconds the bagpipe-bgp client will " "wait between polling for restart detection.")), cfg.StrOpt('bagpipe_bgp_ip', default='127.0.0.1', help=_("bagpipe-bgp REST service IP address.")), cfg.IntOpt('bagpipe_bgp_port', default=8082, help=_("bagpipe-bgp REST service IP port.")), cfg.StrOpt('mpls_bridge', default='br-mpls', help=_("OVS MPLS bridge to use")), cfg.StrOpt('tun_to_mpls_peer_patch_port', default='patch-to-mpls', help=_("OVS Peer patch port in tunnel bridge to MPLS bridge " "(traffic to MPLS bridge)")), cfg.StrOpt('tun_from_mpls_peer_patch_port', default='patch-from-mpls', help=_("OVS Peer patch port in tunnel bridge to MPLS bridge " "(traffic from MPLS bridge)")), cfg.StrOpt('mpls_to_tun_peer_patch_port', default='patch-to-tun', help=_("OVS Peer patch port in MPLS bridge to tunnel bridge " "(traffic to tunnel bridge)")),