コード例 #1
0
 def _validate_network_mapping_info(self, network_mapping_info):
     self._set_mapping_info_defaults(network_mapping_info)
     network_id = network_mapping_info.get(NETWORK_ID)
     if not network_id:
         raise exceptions.InvalidInput(
             error_message=_("A network identifier must be specified "
                             "when connecting a network to a network "
                             "gateway. Unable to complete operation"))
     connection_attrs = set(network_mapping_info.keys())
     if not connection_attrs.issubset(ALLOWED_CONNECTION_ATTRIBUTES):
         raise exceptions.InvalidInput(
             error_message=(_("Invalid keys found among the ones provided "
                              "in request body: %(connection_attrs)s."),
                            connection_attrs))
     seg_type = network_mapping_info.get(SEGMENTATION_TYPE)
     seg_id = network_mapping_info.get(SEGMENTATION_ID)
     # It is important to validate that the segmentation ID is actually an
     # integer value
     try:
         seg_id = int(seg_id)
     except ValueError:
         msg = _("An invalid segmentation ID was specified. The "
                 "segmentation ID must be a positive integer number")
         raise exceptions.InvalidInput(error_message=msg)
     # The NSX plugin accepts 0 as a valid vlan tag
     seg_id_valid = seg_id == 0 or utils.is_valid_vlan_tag(seg_id)
     if seg_type.lower() == 'flat' and seg_id:
         msg = _("Cannot specify a segmentation id when "
                 "the segmentation type is flat")
         raise exceptions.InvalidInput(error_message=msg)
     elif (seg_type.lower() == 'vlan' and not seg_id_valid):
         msg = _("Invalid segmentation id (%s) for "
                 "vlan segmentation type") % seg_id
         raise exceptions.InvalidInput(error_message=msg)
     return network_id
コード例 #2
0
    def validate_provider_segment(self, segment):
        physical_network = segment.get(api.PHYSICAL_NETWORK)
        segmentation_id = segment.get(api.SEGMENTATION_ID)
        if physical_network:
            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)
            if segmentation_id:
                if not plugin_utils.is_valid_vlan_tag(segmentation_id):
                    msg = (_("segmentation_id out of range (%(min)s through "
                             "%(max)s)") %
                           {'min': p_const.MIN_VLAN_TAG,
                            'max': p_const.MAX_VLAN_TAG})
                    raise exc.InvalidInput(error_message=msg)
            else:
                if not self.network_vlan_ranges.get(physical_network):
                    msg = (_("Physical network %s requires segmentation_id "
                             "to be specified when creating a provider "
                             "network") % physical_network)
                    raise exc.InvalidInput(error_message=msg)
        elif segmentation_id:
            msg = _("segmentation_id requires physical_network for VLAN "
                    "provider network")
            raise exc.InvalidInput(error_message=msg)

        for key, value in segment.items():
            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)
コード例 #3
0
ファイル: type_vlan.py プロジェクト: williamwang0/MusicGen
    def validate_provider_segment(self, segment):
        physical_network = segment.get(api.PHYSICAL_NETWORK)
        segmentation_id = segment.get(api.SEGMENTATION_ID)
        ranges = self.get_network_segment_ranges()
        if physical_network:
            if physical_network not in ranges:
                msg = (_("physical_network '%s' unknown "
                         "for VLAN provider network") % physical_network)
                raise exc.InvalidInput(error_message=msg)
            if segmentation_id:
                if not plugin_utils.is_valid_vlan_tag(segmentation_id):
                    msg = (_("segmentation_id out of range (%(min)s through "
                             "%(max)s)") % {
                                 'min': p_const.MIN_VLAN_TAG,
                                 'max': p_const.MAX_VLAN_TAG
                             })
                    raise exc.InvalidInput(error_message=msg)
            else:
                if not ranges.get(physical_network):
                    msg = (_("Physical network %s requires segmentation_id "
                             "to be specified when creating a provider "
                             "network") % physical_network)
                    raise exc.InvalidInput(error_message=msg)
        elif segmentation_id:
            msg = _("segmentation_id requires physical_network for VLAN "
                    "provider network")
            raise exc.InvalidInput(error_message=msg)

        for key, value in segment.items():
            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)
コード例 #4
0
ファイル: networkgw_db.py プロジェクト: openstack/vmware-nsx
 def _validate_network_mapping_info(self, network_mapping_info):
     self._set_mapping_info_defaults(network_mapping_info)
     network_id = network_mapping_info.get(NETWORK_ID)
     if not network_id:
         raise exceptions.InvalidInput(
             error_message=_("A network identifier must be specified "
                             "when connecting a network to a network "
                             "gateway. Unable to complete operation"))
     connection_attrs = set(network_mapping_info.keys())
     if not connection_attrs.issubset(ALLOWED_CONNECTION_ATTRIBUTES):
         raise exceptions.InvalidInput(
             error_message=(_("Invalid keys found among the ones provided "
                              "in request body: %(connection_attrs)s."),
                            connection_attrs))
     seg_type = network_mapping_info.get(SEGMENTATION_TYPE)
     seg_id = network_mapping_info.get(SEGMENTATION_ID)
     # It is important to validate that the segmentation ID is actually an
     # integer value
     try:
         seg_id = int(seg_id)
     except ValueError:
         msg = _("An invalid segmentation ID was specified. The "
                 "segmentation ID must be a positive integer number")
         raise exceptions.InvalidInput(error_message=msg)
     # The NSX plugin accepts 0 as a valid vlan tag
     seg_id_valid = seg_id == 0 or utils.is_valid_vlan_tag(seg_id)
     if seg_type.lower() == 'flat' and seg_id:
         msg = _("Cannot specify a segmentation id when "
                 "the segmentation type is flat")
         raise exceptions.InvalidInput(error_message=msg)
     elif (seg_type.lower() == 'vlan' and not seg_id_valid):
         msg = _("Invalid segmentation id (%s) for "
                 "vlan segmentation type") % seg_id
         raise exceptions.InvalidInput(error_message=msg)
     return network_id
コード例 #5
0
 def _validate_network(self, context, net_data):
     network_type = net_data.get(pnet.NETWORK_TYPE)
     segmentation_id = net_data.get(pnet.SEGMENTATION_ID)
     segmentation_id_set = validators.is_attr_set(segmentation_id)
     if not context.is_admin:
         err_msg = _("Only an admin can create a DVS provider " "network")
         raise n_exc.InvalidInput(error_message=err_msg)
     err_msg = None
     if (network_type == c_utils.NetworkTypes.FLAT
             or network_type == c_utils.NetworkTypes.PORTGROUP):
         if segmentation_id_set:
             err_msg = (_("Segmentation ID cannot be specified with "
                          "%s network type"), network_type)
     elif network_type == c_utils.NetworkTypes.VLAN:
         if not segmentation_id_set:
             err_msg = _("Segmentation ID must be specified with "
                         "vlan network type")
         if (segmentation_id_set
                 and not utils.is_valid_vlan_tag(segmentation_id)):
             err_msg = (_("%(segmentation_id)s out of range "
                          "(%(min_id)s through %(max_id)s)") % {
                              'segmentation_id': segmentation_id,
                              'min_id': constants.MIN_VLAN_TAG,
                              'max_id': constants.MAX_VLAN_TAG
                          })
     else:
         err_msg = (_("%(net_type_param)s %(net_type_value)s not "
                      "supported") % {
                          'net_type_param': pnet.NETWORK_TYPE,
                          'net_type_value': network_type
                      })
     if err_msg:
         raise n_exc.InvalidInput(error_message=err_msg)
コード例 #6
0
 def _validate_network(self, context, net_data):
     network_type = net_data.get(pnet.NETWORK_TYPE)
     network_type_set = validators.is_attr_set(network_type)
     segmentation_id = net_data.get(pnet.SEGMENTATION_ID)
     segmentation_id_set = validators.is_attr_set(segmentation_id)
     physical_network = net_data.get(pnet.PHYSICAL_NETWORK)
     if network_type == 'vlan':
         bindings = nsx_db.get_network_bindings_by_vlanid_and_physical_net(
             context.session, segmentation_id, physical_network)
         if bindings:
             err_msg = _("Network with that dvs-id and vlan tag already "
                         "exists")
             raise n_exc.InvalidInput(error_message=err_msg)
     if not context.is_admin:
         err_msg = _("Only an admin can create a DVS provider " "network")
         raise n_exc.InvalidInput(error_message=err_msg)
     err_msg = None
     if not network_type_set:
         err_msg = _("Network provider information must be " "specified")
         raise n_exc.InvalidInput(error_message=err_msg)
     if (network_type == c_utils.NetworkTypes.FLAT
             or network_type == c_utils.NetworkTypes.PORTGROUP):
         if segmentation_id_set:
             err_msg = (_("Segmentation ID cannot be specified with "
                          "%s network type"), network_type)
     elif network_type == c_utils.NetworkTypes.VLAN:
         if not segmentation_id_set:
             err_msg = _("Segmentation ID must be specified with "
                         "vlan network type")
         if (segmentation_id_set
                 and not utils.is_valid_vlan_tag(segmentation_id)):
             err_msg = (_("%(segmentation_id)s out of range "
                          "(%(min_id)s through %(max_id)s)") % {
                              'segmentation_id': segmentation_id,
                              'min_id': constants.MIN_VLAN_TAG,
                              'max_id': constants.MAX_VLAN_TAG
                          })
     else:
         err_msg = (_("%(net_type_param)s %(net_type_value)s not "
                      "supported") % {
                          'net_type_param': pnet.NETWORK_TYPE,
                          'net_type_value': network_type
                      })
     if err_msg:
         raise n_exc.InvalidInput(error_message=err_msg)
コード例 #7
0
ファイル: plugin.py プロジェクト: openstack/vmware-nsx
 def _validate_network(self, context, net_data):
     network_type = net_data.get(pnet.NETWORK_TYPE)
     network_type_set = validators.is_attr_set(network_type)
     segmentation_id = net_data.get(pnet.SEGMENTATION_ID)
     segmentation_id_set = validators.is_attr_set(segmentation_id)
     physical_network = net_data.get(pnet.PHYSICAL_NETWORK)
     if network_type == 'vlan':
         bindings = nsx_db.get_network_bindings_by_vlanid_and_physical_net(
             context.session, segmentation_id, physical_network)
         if bindings:
             err_msg = _("Network with that dvs-id and vlan tag already "
                         "exists")
             raise n_exc.InvalidInput(error_message=err_msg)
     if not context.is_admin:
         err_msg = _("Only an admin can create a DVS provider "
                     "network")
         raise n_exc.InvalidInput(error_message=err_msg)
     err_msg = None
     if not network_type_set:
         err_msg = _("Network provider information must be "
                     "specified")
         raise n_exc.InvalidInput(error_message=err_msg)
     if (network_type == c_utils.NetworkTypes.FLAT or
         network_type == c_utils.NetworkTypes.PORTGROUP):
         if segmentation_id_set:
             err_msg = (_("Segmentation ID cannot be specified with "
                         "%s network type"), network_type)
     elif network_type == c_utils.NetworkTypes.VLAN:
         if not segmentation_id_set:
             err_msg = _("Segmentation ID must be specified with "
                         "vlan network type")
         if (segmentation_id_set and
             not utils.is_valid_vlan_tag(segmentation_id)):
             err_msg = (_("%(segmentation_id)s out of range "
                          "(%(min_id)s through %(max_id)s)") %
                        {'segmentation_id': segmentation_id,
                         'min_id': constants.MIN_VLAN_TAG,
                         'max_id': constants.MAX_VLAN_TAG})
     else:
         err_msg = (_("%(net_type_param)s %(net_type_value)s not "
                      "supported") %
                    {'net_type_param': pnet.NETWORK_TYPE,
                     'net_type_value': network_type})
     if err_msg:
         raise n_exc.InvalidInput(error_message=err_msg)
コード例 #8
0
 def _validate_segment_id(self, seg_id):
     if not seg_id:
         raise l2gw_exc.L2GatewaySegmentationRequired
     return plugin_utils.is_valid_vlan_tag(seg_id)
コード例 #9
0
ファイル: test_utils.py プロジェクト: takanattie/neutron-lib
 def test_is_valid_vlan_tag_invalid_data(self):
     for v in [constants.MIN_VLAN_TAG - 1, constants.MIN_VLAN_TAG - 2,
               constants.MAX_VLAN_TAG + 1, constants.MAX_VLAN_TAG + 2]:
         self.assertFalse(utils.is_valid_vlan_tag(v))
コード例 #10
0
ファイル: test_utils.py プロジェクト: takanattie/neutron-lib
 def test_is_valid_vlan_tag(self):
     for v in [constants.MIN_VLAN_TAG, constants.MIN_VLAN_TAG + 2,
               constants.MAX_VLAN_TAG, constants.MAX_VLAN_TAG - 2]:
         self.assertTrue(utils.is_valid_vlan_tag(v))
コード例 #11
0
ファイル: driver.py プロジェクト: openstack/vmware-nsx
 def _validate_segment_id(self, seg_id):
     if not seg_id:
         raise l2gw_exc.L2GatewaySegmentationRequired
     return plugin_utils.is_valid_vlan_tag(seg_id)