本文整理汇总了Python中neutron.api.v2.attributes.convert_to_int函数的典型用法代码示例。如果您正苦于以下问题:Python convert_to_int函数的具体用法?Python convert_to_int怎么用?Python convert_to_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convert_to_int函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _convert_and_validate_segments
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)
示例2: _convert_and_validate_segments
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()
示例3: convert_to_int_if_needed
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)
示例4: test_convert_to_int_str
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')
示例5: test_convert_to_int_int
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))
示例6: test_convert_to_int_int
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)
示例7: test_convert_to_int_str
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")
示例8: TODO
'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,