def verify_tunnel_range(tunnel_range, tunnel_type): """Verify a given tunnel range is valid given it's tunnel type. Existing validation is done for GRE, VXLAN and GENEVE types as per _TUNNEL_MAPPINGS. :param tunnel_range: An iterable who's 0 index is the min tunnel range and who's 1 index is the max tunnel range. :param tunnel_type: The tunnel type of the range. :returns: None if the tunnel_range is valid. :raises: NetworkTunnelRangeError if tunnel_range is invalid. """ if tunnel_type in _TUNNEL_MAPPINGS: for ident in tunnel_range: if not _TUNNEL_MAPPINGS[tunnel_type](ident): raise exceptions.NetworkTunnelRangeError( tunnel_range=tunnel_range, error=_("%(id)s is not a valid %(type)s identifier") % { 'id': ident, 'type': tunnel_type }) if tunnel_range[1] < tunnel_range[0]: raise exceptions.NetworkTunnelRangeError( tunnel_range=tunnel_range, error=_("End of tunnel range is less " "than start of tunnel range"))
def _parse_nexus_vni_range(self, tunnel_range): """Raise an exception for invalid tunnel range or malformed range.""" for ident in tunnel_range: if not self._is_valid_nexus_vni(ident): raise exc.NetworkTunnelRangeError( tunnel_range=tunnel_range, error=_("%(id)s is not a valid Nexus VNI value.") % {'id': ident}) if tunnel_range[1] < tunnel_range[0]: raise exc.NetworkTunnelRangeError( tunnel_range=tunnel_range, error=_("End of tunnel range is less than start of " "tunnel range."))
def verify_tunnel_range(tunnel_range, tunnel_type): """Raise an exception for invalid tunnel range or malformed range.""" mappings = {p_const.TYPE_GRE: is_valid_gre_id, p_const.TYPE_VXLAN: is_valid_vxlan_vni, p_const.TYPE_GENEVE: is_valid_geneve_vni} if tunnel_type in mappings: for ident in tunnel_range: if not mappings[tunnel_type](ident): raise exceptions.NetworkTunnelRangeError( tunnel_range=tunnel_range, error=_("%(id)s is not a valid %(type)s identifier") % {'id': ident, 'type': tunnel_type}) if tunnel_range[1] < tunnel_range[0]: raise exceptions.NetworkTunnelRangeError( tunnel_range=tunnel_range, error=_("End of tunnel range is less " "than start of tunnel range"))
def parse_l3_vni_ranges(self, l3_vxlan_ranges_cfg_entries): """Interpret a list of strings as vxlan_begin:vxlan_end entries.""" l3_vxlan_ranges = [] for entry in l3_vxlan_ranges_cfg_entries: entry = entry.strip() try: vni_min, vni_max = entry.split(':') vni_min = vni_min.strip() vni_max = vni_max.strip() vni_range = int(vni_min), int(vni_max) except ValueError as ex: raise exc.NetworkTunnelRangeError(tunnel_range=entry, error=ex) l3_vxlan_ranges.append(vni_range) return l3_vxlan_ranges
def _parse_tunnel_ranges(self, tunnel_ranges, current_range): for entry in tunnel_ranges: entry = entry.strip() try: tun_min, tun_max = entry.split(':') tun_min = tun_min.strip() tun_max = tun_max.strip() tunnel_range = int(tun_min), int(tun_max) except ValueError as ex: raise exc.NetworkTunnelRangeError(tunnel_range=entry, error=ex) plugin_utils.verify_tunnel_range(tunnel_range, self.get_type()) current_range.append(tunnel_range) LOG.info(_LI("%(type)s ID ranges: %(range)s"), {'type': self.get_type(), 'range': current_range})
def _parse_nexus_vni_ranges(self, tunnel_ranges, current_range): for entry in tunnel_ranges: entry = entry.strip() try: tun_min, tun_max = entry.split(':') tun_min = tun_min.strip() tun_max = tun_max.strip() tunnel_range = int(tun_min), int(tun_max) except ValueError as ex: raise exc.NetworkTunnelRangeError(tunnel_range=entry, error=ex) self._parse_nexus_vni_range(tunnel_range) current_range.append(tunnel_range) LOG.info("Nexus VXLAN ID ranges: %(range)s", {'range': current_range})