From 6d8633f5dd2e32f8da800e00296398b40ee7bc90 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 20 Oct 2017 16:18:25 +0200 Subject: [PATCH] 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 --- doc/source/user/config/network-config.rst | 7 +++++++ openstack/config/cloud_config.py | 7 +++++++ openstack/config/loader.py | 1 + openstack/tests/unit/config/base.py | 1 + openstack/tests/unit/config/test_config.py | 3 +++ releasenotes/notes/nat-source-field-7c7db2a724616d59.yaml | 6 ++++++ 6 files changed, 25 insertions(+) create mode 100644 releasenotes/notes/nat-source-field-7c7db2a724616d59.yaml diff --git a/doc/source/user/config/network-config.rst b/doc/source/user/config/network-config.rst index 09571804e..ea8541478 100644 --- a/doc/source/user/config/network-config.rst +++ b/doc/source/user/config/network-config.rst @@ -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 router. 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. diff --git a/openstack/config/cloud_config.py b/openstack/config/cloud_config.py index ea5f0f617..e5b2be2a4 100644 --- a/openstack/config/cloud_config.py +++ b/openstack/config/cloud_config.py @@ -583,3 +583,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 diff --git a/openstack/config/loader.py b/openstack/config/loader.py index 288c97dde..2c186fe82 100644 --- a/openstack/config/loader.py +++ b/openstack/config/loader.py @@ -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')), ) diff --git a/openstack/tests/unit/config/base.py b/openstack/tests/unit/config/base.py index 60ca63d12..fab573d16 100644 --- a/openstack/tests/unit/config/base.py +++ b/openstack/tests/unit/config/base.py @@ -102,6 +102,7 @@ USER_CONF = { 'networks': [{ 'name': 'a-public', 'routes_externally': True, + 'nat_source': True, }, { 'name': 'another-public', 'routes_externally': True, diff --git a/openstack/tests/unit/config/test_config.py b/openstack/tests/unit/config/test_config.py index 60ef0cc8d..b67d04124 100644 --- a/openstack/tests/unit/config/test_config.py +++ b/openstack/tests/unit/config/test_config.py @@ -225,6 +225,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( @@ -240,6 +241,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()) @@ -1020,6 +1022,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}, ] diff --git a/releasenotes/notes/nat-source-field-7c7db2a724616d59.yaml b/releasenotes/notes/nat-source-field-7c7db2a724616d59.yaml new file mode 100644 index 000000000..3341c9f25 --- /dev/null +++ b/releasenotes/notes/nat-source-field-7c7db2a724616d59.yaml @@ -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.