Added nat_source flag for networks.

In some more complex clouds there can not only be more than one valid network
on a server that NAT can attach to, there can also be more than one valid
network from which to get a NAT address. Allow flagging a network so that it
can be found.

Change-Id: I3d8dd6d734a1013d2d4a43e11c3538c3a345820b
This commit is contained in:
Monty Taylor 2017-10-20 16:18:25 +02:00
parent 9c243d4006
commit 162a7a59fd
6 changed files with 25 additions and 0 deletions

View File

@ -58,3 +58,10 @@ by looking for a network that has subnets that have a gateway_ip. But it's
possible to have more than one network that satisfies that condition, so the
user might want to tell programs which one to pick. There can be only one
`nat_destination` per cloud.
`nat_source` is a boolean field that indicates which network floating
ips should be requested from. It defaults to false. Normally this can be
inferred by looking for a network that is attached to a route. But it's
possible to have more than one network that satisfies that condition, so the
user might want to tell programs which one to pick. There can be only one
`nat_source` per cloud.

View File

@ -581,3 +581,10 @@ class CloudConfig(object):
if net['nat_destination']:
return net['name']
return None
def get_nat_source(self):
"""Get network used for NAT source."""
for net in self.config['networks']:
if net.get('nat_source'):
return net['name']
return None

View File

@ -550,6 +550,7 @@ class OpenStackConfig(object):
network = dict(
name=name,
routes_externally=get_boolean(net.get('routes_externally')),
nat_source=get_boolean(net.get('nat_source')),
nat_destination=get_boolean(net.get('nat_destination')),
default_interface=get_boolean(net.get('default_interface')),
)

View File

@ -102,6 +102,7 @@ USER_CONF = {
'networks': [{
'name': 'a-public',
'routes_externally': True,
'nat_source': True,
}, {
'name': 'another-public',
'routes_externally': True,

View File

@ -224,6 +224,7 @@ class TestConfig(base.TestCase):
self.assertEqual(
['a-private', 'another-private', 'split-no-default'],
cc.get_internal_networks())
self.assertEqual('a-public', cc.get_nat_source())
self.assertEqual('another-private', cc.get_nat_destination())
self.assertEqual('another-public', cc.get_default_network())
self.assertEqual(
@ -239,6 +240,7 @@ class TestConfig(base.TestCase):
cc = c.get_one_cloud('_test-cloud-domain-scoped_')
self.assertEqual([], cc.get_external_networks())
self.assertEqual([], cc.get_internal_networks())
self.assertIsNone(cc.get_nat_source())
self.assertIsNone(cc.get_nat_destination())
self.assertIsNone(cc.get_default_network())
@ -1019,6 +1021,7 @@ class TestBackwardsCompatibility(base.TestCase):
'networks': [
{'name': 'private', 'routes_externally': False,
'nat_destination': False, 'default_interface': False,
'nat_source': False,
'routes_ipv4_externally': False,
'routes_ipv6_externally': False},
]

View File

@ -0,0 +1,6 @@
---
features:
- Added nat_source flag for networks. In some more complex clouds there
can not only be more than one valid network on a server that NAT can
attach to, there can also be more than one valid network from which to
get a NAT address. Allow flagging a network so that it can be found.