def validate_provider_segment(self, segment): physical_network = segment.get(api.PHYSICAL_NETWORK) if not physical_network: msg = _("physical_network required for VLAN provider network") raise exc.InvalidInput(error_message=msg) if physical_network not in self.network_vlan_ranges: msg = (_("physical_network '%s' unknown for VLAN provider network") % physical_network) raise exc.InvalidInput(error_message=msg) segmentation_id = segment.get(api.SEGMENTATION_ID) if segmentation_id is None: msg = _("segmentation_id required for VLAN provider network") raise exc.InvalidInput(error_message=msg) if not utils.is_valid_vlan_tag(segmentation_id): msg = (_("segmentation_id out of range (%(min)s through " "%(max)s)") % {'min': q_const.MIN_VLAN_TAG, 'max': q_const.MAX_VLAN_TAG}) raise exc.InvalidInput(error_message=msg) for key, value in segment.iteritems(): if value and key not in [api.NETWORK_TYPE, api.PHYSICAL_NETWORK, api.SEGMENTATION_ID]: msg = _("%s prohibited for VLAN provider network") % key raise exc.InvalidInput(error_message=msg) return segment
def _process_vlan_net(self, segmentation_id, segmentation_id_set): if not segmentation_id_set: msg = _("provider:segmentation_id required") raise q_exc.InvalidInput(error_message=msg) if not utils.is_valid_vlan_tag(segmentation_id): msg = (_("provider:segmentation_id out of range " "(%(min_id)s through %(max_id)s)") % {'min_id': q_const.MIN_VLAN_TAG, 'max_id': q_const.MAX_VLAN_TAG}) raise q_exc.InvalidInput(error_message=msg)
def _process_vlan_net(self, segmentation_id, segmentation_id_set): if not segmentation_id_set: msg = _("provider:segmentation_id required") raise q_exc.InvalidInput(error_message=msg) if not utils.is_valid_vlan_tag(segmentation_id): msg = (_("provider:segmentation_id out of range " "(%(min_id)s through %(max_id)s)") % { 'min_id': q_const.MIN_VLAN_TAG, 'max_id': q_const.MAX_VLAN_TAG }) raise q_exc.InvalidInput(error_message=msg)
def verify_vlan_range(vlan_range): """Raise an exception for invalid tags or malformed range.""" for vlan_tag in vlan_range: if not utils.is_valid_vlan_tag(vlan_tag): raise q_exc.NetworkVlanRangeError( vlan_range=vlan_range, error=_("%s is not a valid VLAN tag") % vlan_tag) if vlan_range[1] < vlan_range[0]: raise q_exc.NetworkVlanRangeError( vlan_range=vlan_range, error=_("End of VLAN range is less than start of VLAN range"))
def _process_provider_create(self, context, attrs): network_type = attrs.get(provider.NETWORK_TYPE) physical_network = attrs.get(provider.PHYSICAL_NETWORK) segmentation_id = attrs.get(provider.SEGMENTATION_ID) network_type_set = attributes.is_attr_set(network_type) physical_network_set = attributes.is_attr_set(physical_network) segmentation_id_set = attributes.is_attr_set(segmentation_id) if not (network_type_set or physical_network_set or segmentation_id_set): return (None, None, None) if not network_type_set: msg = _("provider:network_type required") raise q_exc.InvalidInput(error_message=msg) elif network_type == constants.TYPE_FLAT: if segmentation_id_set: msg = _("provider:segmentation_id specified for flat network") raise q_exc.InvalidInput(error_message=msg) else: segmentation_id = constants.FLAT_VLAN_ID elif network_type == constants.TYPE_VLAN: if not segmentation_id_set: msg = _("provider:segmentation_id required") raise q_exc.InvalidInput(error_message=msg) if not utils.is_valid_vlan_tag(segmentation_id): msg = (_("provider:segmentation_id out of range " "(%(min_id)s through %(max_id)s)") % {'min_id': q_const.MIN_VLAN_TAG, 'max_id': q_const.MAX_VLAN_TAG}) raise q_exc.InvalidInput(error_message=msg) elif network_type == constants.TYPE_LOCAL: if physical_network_set: msg = _("provider:physical_network specified for local " "network") raise q_exc.InvalidInput(error_message=msg) else: physical_network = None if segmentation_id_set: msg = _("provider:segmentation_id specified for local " "network") raise q_exc.InvalidInput(error_message=msg) else: segmentation_id = constants.LOCAL_VLAN_ID else: msg = _("provider:network_type %s not supported") % network_type raise q_exc.InvalidInput(error_message=msg) if network_type in [constants.TYPE_VLAN, constants.TYPE_FLAT]: if physical_network_set: if physical_network not in self.network_vlan_ranges: msg = (_("Unknown provider:physical_network %s") % physical_network) raise q_exc.InvalidInput(error_message=msg) elif 'default' in self.network_vlan_ranges: physical_network = 'default' else: msg = _("provider:physical_network required") raise q_exc.InvalidInput(error_message=msg) return (network_type, physical_network, segmentation_id)
def _process_provider_create(self, context, attrs): network_type = attrs.get(provider.NETWORK_TYPE) physical_network = attrs.get(provider.PHYSICAL_NETWORK) segmentation_id = attrs.get(provider.SEGMENTATION_ID) network_type_set = attributes.is_attr_set(network_type) physical_network_set = attributes.is_attr_set(physical_network) segmentation_id_set = attributes.is_attr_set(segmentation_id) if not (network_type_set or physical_network_set or segmentation_id_set): return (None, None, None) if not network_type_set: msg = _("provider:network_type required") raise q_exc.InvalidInput(error_message=msg) elif network_type == constants.TYPE_FLAT: if segmentation_id_set: msg = _("provider:segmentation_id specified for flat network") raise q_exc.InvalidInput(error_message=msg) else: segmentation_id = constants.FLAT_VLAN_ID elif network_type == constants.TYPE_VLAN: if not segmentation_id_set: msg = _("provider:segmentation_id required") raise q_exc.InvalidInput(error_message=msg) if not utils.is_valid_vlan_tag(segmentation_id): msg = (_("provider:segmentation_id out of range " "(%(min_id)s through %(max_id)s)") % { 'min_id': q_const.MIN_VLAN_TAG, 'max_id': q_const.MAX_VLAN_TAG }) raise q_exc.InvalidInput(error_message=msg) elif network_type == constants.TYPE_GRE: if not self.enable_tunneling: msg = _("GRE networks are not enabled") raise q_exc.InvalidInput(error_message=msg) if physical_network_set: msg = _("provider:physical_network specified for GRE " "network") raise q_exc.InvalidInput(error_message=msg) else: physical_network = None if not segmentation_id_set: msg = _("provider:segmentation_id required") raise q_exc.InvalidInput(error_message=msg) elif network_type == constants.TYPE_LOCAL: if physical_network_set: msg = _("provider:physical_network specified for local " "network") raise q_exc.InvalidInput(error_message=msg) else: physical_network = None if segmentation_id_set: msg = _("provider:segmentation_id specified for local " "network") raise q_exc.InvalidInput(error_message=msg) else: segmentation_id = None else: msg = _("provider:network_type %s not supported") % network_type raise q_exc.InvalidInput(error_message=msg) if network_type in [constants.TYPE_VLAN, constants.TYPE_FLAT]: if physical_network_set: if physical_network not in self.network_vlan_ranges: msg = _("Unknown provider:physical_network " "%s") % physical_network raise q_exc.InvalidInput(error_message=msg) elif 'default' in self.network_vlan_ranges: physical_network = 'default' else: msg = _("provider:physical_network required") raise q_exc.InvalidInput(error_message=msg) return (network_type, physical_network, segmentation_id)