Esempio n. 1
0
    def _validate(self, context, subport, trunk_port_mtu):
        # Check that the subport doesn't reference the same port_id as a
        # trunk we may be in the middle of trying to create, in other words
        # make the validation idiot proof.
        if subport['port_id'] == self.trunk_port_id:
            raise trunk_exc.ParentPortInUse(port_id=subport['port_id'])

        # Check MTU sanity - subport MTU must not exceed trunk MTU.
        # If for whatever reason trunk_port_mtu is not available,
        # the MTU sanity check cannot be enforced.
        if trunk_port_mtu:
            port_mtu = self._get_port_mtu(context, subport['port_id'])
            if port_mtu and port_mtu > trunk_port_mtu:
                raise trunk_exc.SubPortMtuGreaterThanTrunkPortMtu(
                    port_id=subport['port_id'],
                    port_mtu=port_mtu,
                    trunk_id=self.trunk_port_id,
                    trunk_mtu=trunk_port_mtu
                )

        # If the segmentation details are missing, we will need to
        # figure out defaults when the time comes to support Ironic.
        # We can reasonably expect segmentation details to be provided
        # in all other cases for now.
        try:
            segmentation_type = subport["segmentation_type"]
            segmentation_id = (
                converters.convert_to_int(subport["segmentation_id"]))
        except KeyError:
            msg = _("Invalid subport details '%s': missing segmentation "
                    "information. Must specify both segmentation_id and "
                    "segmentation_type") % subport
            raise n_exc.InvalidInput(error_message=msg)
        except n_exc.InvalidInput:
            msg = _("Invalid subport details: segmentation_id '%s' is "
                    "not an integer") % subport["segmentation_id"]
            raise n_exc.InvalidInput(error_message=msg)

        if segmentation_type not in self._segmentation_types:
            msg = _("Unknown segmentation_type '%s'") % segmentation_type
            raise n_exc.InvalidInput(error_message=msg)

        if not self._segmentation_types[segmentation_type](segmentation_id):
            msg = _("Segmentation ID '%s' is not in range") % segmentation_id
            raise n_exc.InvalidInput(error_message=msg)

        # Check if the subport is already participating in an active trunk
        trunk_validator = TrunkPortValidator(subport['port_id'])
        trunk_validator.validate(context, parent_port=False)
        return subport
Esempio n. 2
0
    def _validate(self, context, subport, trunk_port_mtu):
        # Check that the subport doesn't reference the same port_id as a
        # trunk we may be in the middle of trying to create, in other words
        # make the validation idiot proof.
        if subport['port_id'] == self.trunk_port_id:
            raise trunk_exc.ParentPortInUse(port_id=subport['port_id'])

        # Check MTU sanity - subport MTU must not exceed trunk MTU.
        # If for whatever reason trunk_port_mtu is not available,
        # the MTU sanity check cannot be enforced.
        if trunk_port_mtu:
            port_mtu = self._get_port_mtu(context, subport['port_id'])
            if port_mtu and port_mtu > trunk_port_mtu:
                raise trunk_exc.SubPortMtuGreaterThanTrunkPortMtu(
                    port_id=subport['port_id'],
                    port_mtu=port_mtu,
                    trunk_id=self.trunk_port_id,
                    trunk_mtu=trunk_port_mtu)

        # If the segmentation details are missing, we will need to
        # figure out defaults when the time comes to support Ironic.
        # We can reasonably expect segmentation details to be provided
        # in all other cases for now.
        try:
            segmentation_type = subport["segmentation_type"]
            segmentation_id = (converters.convert_to_int(
                subport["segmentation_id"]))
        except KeyError:
            msg = _("Invalid subport details '%s': missing segmentation "
                    "information. Must specify both segmentation_id and "
                    "segmentation_type") % subport
            raise n_exc.InvalidInput(error_message=msg)
        except n_exc.InvalidInput:
            msg = _("Invalid subport details: segmentation_id '%s' is "
                    "not an integer") % subport["segmentation_id"]
            raise n_exc.InvalidInput(error_message=msg)

        if segmentation_type not in self._segmentation_types:
            msg = _("Unknown segmentation_type '%s'") % segmentation_type
            raise n_exc.InvalidInput(error_message=msg)

        if not self._segmentation_types[segmentation_type](segmentation_id):
            msg = _("Segmentation ID '%s' is not in range") % segmentation_id
            raise n_exc.InvalidInput(error_message=msg)

        # Check if the subport is already participating in an active trunk
        trunk_validator = TrunkPortValidator(subport['port_id'])
        trunk_validator.validate(context, parent_port=False)
        return subport
Esempio n. 3
0
 def _raise_if_segmentation_details_missing(self, subport):
     try:
         segmentation_type = subport["segmentation_type"]
         segmentation_id = (
             converters.convert_to_int(subport["segmentation_id"]))
         return (segmentation_type, segmentation_id)
     except KeyError:
         msg = _("Invalid subport details '%s': missing segmentation "
                 "information. Must specify both segmentation_id and "
                 "segmentation_type") % subport
         raise n_exc.InvalidInput(error_message=msg)
     except n_exc.InvalidInput:
         msg = _("Invalid subport details: segmentation_id '%s' is "
                 "not an integer") % subport["segmentation_id"]
         raise n_exc.InvalidInput(error_message=msg)
Esempio n. 4
0
 def _raise_if_segmentation_details_missing(self, subport):
     try:
         segmentation_type = subport["segmentation_type"]
         segmentation_id = (
             converters.convert_to_int(subport["segmentation_id"]))
         return (segmentation_type, segmentation_id)
     except KeyError:
         msg = _("Invalid subport details '%s': missing segmentation "
                 "information. Must specify both segmentation_id and "
                 "segmentation_type") % subport
         raise n_exc.InvalidInput(error_message=msg)
     except n_exc.InvalidInput:
         msg = _("Invalid subport details: segmentation_id '%s' is "
                 "not an integer") % subport["segmentation_id"]
         raise n_exc.InvalidInput(error_message=msg)
Esempio n. 5
0
def _convert_and_validate_segments(segments, valid_values=None):
    for segment in segments:
        segment.setdefault(pnet.NETWORK_TYPE, constants.ATTR_NOT_SPECIFIED)
        segment.setdefault(pnet.PHYSICAL_NETWORK, constants.ATTR_NOT_SPECIFIED)
        segmentation_id = segment.get(pnet.SEGMENTATION_ID)
        if segmentation_id:
            segment[pnet.SEGMENTATION_ID] = converters.convert_to_int(
                segmentation_id)
        else:
            segment[pnet.SEGMENTATION_ID] = constants.ATTR_NOT_SPECIFIED
        if len(segment.keys()) != 3:
            msg = (_("Unrecognized attribute(s) '%s'") %
                   ', '.join(set(segment.keys()) -
                             set([pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK,
                                  pnet.SEGMENTATION_ID])))
            raise webob.exc.HTTPBadRequest(msg)
Esempio n. 6
0
def _convert_and_validate_segments(segments, valid_values=None):
    for segment in segments:
        segment.setdefault(pnet.NETWORK_TYPE, constants.ATTR_NOT_SPECIFIED)
        segment.setdefault(pnet.PHYSICAL_NETWORK, constants.ATTR_NOT_SPECIFIED)
        segmentation_id = segment.get(pnet.SEGMENTATION_ID)
        if segmentation_id:
            segment[pnet.SEGMENTATION_ID] = converters.convert_to_int(
                segmentation_id)
        else:
            segment[pnet.SEGMENTATION_ID] = constants.ATTR_NOT_SPECIFIED
        if len(segment.keys()) != 3:
            msg = (_("Unrecognized attribute(s) '%s'") % ', '.join(
                set(segment.keys()) - set([
                    pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK,
                    pnet.SEGMENTATION_ID
                ])))
            raise webob.exc.HTTPBadRequest(msg)
Esempio n. 7
0
    def _validate(self, context, subport):
        # Check that the subport doesn't reference the same port_id as a
        # trunk we may be in the middle of trying to create, in other words
        # make the validation idiot proof.
        if subport['port_id'] == self.trunk_port_id:
            raise trunk_exc.ParentPortInUse(port_id=subport['port_id'])

        # If the segmentation details are missing, we will need to
        # figure out defaults when the time comes to support Ironic.
        # We can reasonably expect segmentation details to be provided
        # in all other cases for now.
        try:
            segmentation_type = subport["segmentation_type"]
            segmentation_id = (
                converters.convert_to_int(subport["segmentation_id"]))
        except KeyError:
            msg = _("Invalid subport details '%s': missing segmentation "
                    "information. Must specify both segmentation_id and "
                    "segmentation_type") % subport
            raise n_exc.InvalidInput(error_message=msg)
        except n_exc.InvalidInput:
            msg = _("Invalid subport details: segmentation_id '%s' is "
                    "not an integer") % subport["segmentation_id"]
            raise n_exc.InvalidInput(error_message=msg)

        if segmentation_type not in self._segmentation_types:
            msg = _("Unknown segmentation_type '%s'") % segmentation_type
            raise n_exc.InvalidInput(error_message=msg)

        if not self._segmentation_types[segmentation_type](segmentation_id):
            msg = _("Segmentation ID '%s' is not in range") % segmentation_id
            raise n_exc.InvalidInput(error_message=msg)

        trunk_validator = TrunkPortValidator(subport['port_id'])
        trunk_validator.validate(context)
        return subport
Esempio n. 8
0
    def _validate(self, context, subport):
        # Check that the subport doesn't reference the same port_id as a
        # trunk we may be in the middle of trying to create, in other words
        # make the validation idiot proof.
        if subport['port_id'] == self.trunk_port_id:
            raise trunk_exc.ParentPortInUse(port_id=subport['port_id'])

        # If the segmentation details are missing, we will need to
        # figure out defaults when the time comes to support Ironic.
        # We can reasonably expect segmentation details to be provided
        # in all other cases for now.
        try:
            segmentation_type = subport["segmentation_type"]
            segmentation_id = (
                converters.convert_to_int(subport["segmentation_id"]))
        except KeyError:
            msg = _("Invalid subport details '%s': missing segmentation "
                    "information. Must specify both segmentation_id and "
                    "segmentation_type") % subport
            raise n_exc.InvalidInput(error_message=msg)
        except n_exc.InvalidInput:
            msg = _("Invalid subport details: segmentation_id '%s' is "
                    "not an integer") % subport["segmentation_id"]
            raise n_exc.InvalidInput(error_message=msg)

        if segmentation_type not in self._segmentation_types:
            msg = _("Unknown segmentation_type '%s'") % segmentation_type
            raise n_exc.InvalidInput(error_message=msg)

        if not self._segmentation_types[segmentation_type](segmentation_id):
            msg = _("Segmentation ID '%s' is not in range") % segmentation_id
            raise n_exc.InvalidInput(error_message=msg)

        trunk_validator = TrunkPortValidator(subport['port_id'])
        trunk_validator.validate(context)
        return subport
Esempio n. 9
0
 def test_convert_to_int_str(self):
     self.assertEqual(4, converters.convert_to_int('4'))
     self.assertEqual(6, converters.convert_to_int('6'))
     self.assertRaises(n_exc.InvalidInput, converters.convert_to_int,
                       'garbage')
Esempio n. 10
0
 def test_convert_to_int_int(self):
     self.assertEqual(-1, converters.convert_to_int(-1))
     self.assertEqual(0, converters.convert_to_int(0))
     self.assertEqual(1, converters.convert_to_int(1))
Esempio n. 11
0
 def test_convert_to_int_str(self):
     self.assertEqual(4, converters.convert_to_int('4'))
     self.assertEqual(6, converters.convert_to_int('6'))
     self.assertRaises(n_exc.InvalidInput,
                       converters.convert_to_int,
                       'garbage')
Esempio n. 12
0
 def test_convert_to_int_int(self):
     self.assertEqual(-1, converters.convert_to_int(-1))
     self.assertEqual(0, converters.convert_to_int(0))
     self.assertEqual(1, converters.convert_to_int(1))
Esempio n. 13
0
         'allow_put': False,
         'validate': {
             'type:string_or_none': None
         },
         'default': PROXY_CONF.default_proxy_ip_pool,
         'is_visible': True
     },
     'proxy_subnet_prefix_length': {
         'allow_post':
         True,
         'allow_put':
         True,
         'convert_to':
         conv.convert_to_int,
         'default':
         conv.convert_to_int(PROXY_CONF.default_proxy_subnet_prefix_length),
         'is_visible':
         True
     },
     # Proxy IP version is the same as the standard L3 pool ip version
 },
 gp.POLICY_TARGETS: {
     # This policy target will be used to reach the -proxied- PTG
     'proxy_gateway': {
         'allow_post': True,
         'allow_put': False,
         'default': False,
         'convert_to': conv.convert_to_boolean,
         'is_visible': True,
         'required_by_policy': True,
         'enforce_policy': True
         'convert_to': conv.convert_to_boolean,
         'is_visible': True, 'required_by_policy': True,
         'enforce_policy': True},
     # TODO(ivar): The APIs should allow the creation of a group with a
     # custom subnet prefix length. It may be useful for both the proxy
     # groups and traditional ones.
 },
 gp.L3_POLICIES: {
     'proxy_ip_pool': {'allow_post': True, 'allow_put': False,
                       'validate': {'type:string_or_none': None},
                       'default': PROXY_CONF.default_proxy_ip_pool,
                       'is_visible': True},
     'proxy_subnet_prefix_length': {
         'allow_post': True, 'allow_put': True,
         'convert_to': conv.convert_to_int,
         'default': conv.convert_to_int(
             PROXY_CONF.default_proxy_subnet_prefix_length),
         'is_visible': True},
     # Proxy IP version is the same as the standard L3 pool ip version
 },
 gp.POLICY_TARGETS: {
     # This policy target will be used to reach the -proxied- PTG
     'proxy_gateway': {
         'allow_post': True, 'allow_put': False, 'default': False,
         'convert_to': conv.convert_to_boolean,
         'is_visible': True, 'required_by_policy': True,
         'enforce_policy': True},
     # This policy target is the default gateway for the -current- PTG
     # Only for internal use.
     'group_default_gateway': {
         'allow_post': True, 'allow_put': False, 'default': False,
         'convert_to': conv.convert_to_boolean,