Exemplo n.º 1
0
def _convert_and_validate_segments(segments, valid_values=None):
    for segment in segments:
        segment.setdefault(pnet.NETWORK_TYPE, attr.ATTR_NOT_SPECIFIED)
        segment.setdefault(pnet.PHYSICAL_NETWORK, attr.ATTR_NOT_SPECIFIED)
        segmentation_id = segment.get(pnet.SEGMENTATION_ID)
        if segmentation_id:
            segment[pnet.SEGMENTATION_ID] = attr.convert_to_int(
                segmentation_id)
        else:
            segment[pnet.SEGMENTATION_ID] = attr.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)
Exemplo n.º 2
0
def _convert_and_validate_segments(segments, valid_values=None):
    unique = set()
    for segment in segments:
        unique.add(tuple(segment.iteritems()))
        network_type = segment.get(pnet.NETWORK_TYPE, attr.ATTR_NOT_SPECIFIED)
        segment[pnet.NETWORK_TYPE] = network_type
        physical_network = segment.get(pnet.PHYSICAL_NETWORK, attr.ATTR_NOT_SPECIFIED)
        segment[pnet.PHYSICAL_NETWORK] = physical_network
        segmentation_id = segment.get(pnet.SEGMENTATION_ID)
        if segmentation_id:
            segment[pnet.SEGMENTATION_ID] = attr.convert_to_int(segmentation_id)
        else:
            segment[pnet.SEGMENTATION_ID] = attr.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)
    if len(unique) != len(segments):
        raise SegmentsContainDuplicateEntry()
Exemplo n.º 3
0
def convert_to_int_if_needed(value):
    if not value or value is attr.ATTR_NOT_SPECIFIED:
        return value
    else:
        return attr.convert_to_int(value)
Exemplo n.º 4
0
 def test_convert_to_int_str(self):
     self.assertEqual(4, attributes.convert_to_int('4'))
     self.assertEqual(6, attributes.convert_to_int('6'))
     self.assertRaises(n_exc.InvalidInput,
                       attributes.convert_to_int,
                       'garbage')
Exemplo n.º 5
0
 def test_convert_to_int_int(self):
     self.assertEqual(-1, attributes.convert_to_int(-1))
     self.assertEqual(0, attributes.convert_to_int(0))
     self.assertEqual(1, attributes.convert_to_int(1))
Exemplo n.º 6
0
 def test_convert_to_int_int(self):
     self.assertEqual(attributes.convert_to_int(-1), -1)
     self.assertEqual(attributes.convert_to_int(0), 0)
     self.assertEqual(attributes.convert_to_int(1), 1)
Exemplo n.º 7
0
 def test_convert_to_int_str(self):
     self.assertEqual(4, attributes.convert_to_int("4"))
     self.assertEqual(6, attributes.convert_to_int("6"))
     self.assertRaises(n_exc.InvalidInput, attributes.convert_to_int, "garbage")
         'allow_post': False, 'allow_put': False,
         'validate': {'type:uuid_or_none': None}, 'is_visible': 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:subnet': None},
                       'default': PROXY_CONF.default_proxy_ip_pool,
                       'is_visible': True},
     'proxy_subnet_prefix_length': {
         'allow_post': True, 'allow_put': True,
         'convert_to': attr.convert_to_int,
         'default': attr.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': attr.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': attr.convert_to_boolean,
Exemplo n.º 9
0
 def test_convert_to_int_int(self):
     self.assertEqual(attributes.convert_to_int(-1), -1)
     self.assertEqual(attributes.convert_to_int(0), 0)
     self.assertEqual(attributes.convert_to_int(1), 1)
Exemplo n.º 10
0
 def test_convert_to_int_str(self):
     self.assertEqual(attributes.convert_to_int('4'), 4)
     self.assertEqual(attributes.convert_to_int('6'), 6)
     self.assertRaises(n_exc.InvalidInput,
                       attributes.convert_to_int,
                       'garbage')
Exemplo n.º 11
0
 def test_convert_to_int_int(self):
     self.assertEqual(-1, attributes.convert_to_int(-1))
     self.assertEqual(0, attributes.convert_to_int(0))
     self.assertEqual(1, attributes.convert_to_int(1))