From 278a761df68d1e7d4d93ee2c6fb91f1a0e82e78a Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 30 Mar 2016 16:10:04 -0700 Subject: [PATCH] Change network info indication to a generic list Networks can have more information than just internal or external. Notably, if you have two private networks and you're trying to assign floating ips, you need to know which network should be the recipient. This should be backwards compatible with existing external_network and internal_network options. Change-Id: I0d469339ba00486683fcd3ce2995002fa0a576d1 --- README.rst | 12 ++++--- os_client_config/config.py | 24 ++++++++++++++ os_client_config/tests/test_config.py | 31 +++++++++++++++++++ .../notes/network-list-e6e9dafdd8446263.yaml | 11 +++++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/network-list-e6e9dafdd8446263.yaml diff --git a/README.rst b/README.rst index 2e584bd..15f4bf0 100644 --- a/README.rst +++ b/README.rst @@ -289,12 +289,16 @@ region. regions: - name: ams01 values: - external_network: inap-17037-WAN1654 - internal_network: inap-17037-LAN4820 + networks: + - name: inap-17037-WAN1654 + routes_externally: true + - name: inap-17037-LAN6745 - name: nyj01 values: - external_network: inap-17037-WAN7752 - internal_network: inap-17037-LAN6745 + networks: + - name: inap-17037-WAN1654 + routes_externally: true + - name: inap-17037-LAN6745 Usage ----- diff --git a/os_client_config/config.py b/os_client_config/config.py index 2f6adeb..98870f6 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -477,6 +477,7 @@ class OpenStackConfig(object): cloud = self._fix_backwards_auth_plugin(cloud) cloud = self._fix_backwards_project(cloud) cloud = self._fix_backwards_interface(cloud) + cloud = self._fix_backwards_networks(cloud) cloud = self._handle_domain_id(cloud) return cloud @@ -485,6 +486,29 @@ class OpenStackConfig(object): or 'project_id' in cloud['auth'] or 'project_name' in cloud['auth']) + def _fix_backwards_networks(self, cloud): + # Leave the external_network and internal_network keys in the + # dict because consuming code might be expecting them. + networks = cloud.get('networks', []) + for key in ('external_network', 'internal_network'): + external = key.startswith('external') + if key in cloud and 'networks' in cloud: + raise exceptions.OpenStackConfigException( + "Both {key} and networks were specified in the config." + " Please remove {key} from the config and use the network" + " list to configure network behavior.".format(key=key)) + if key in cloud: + warnings.warn( + "{key} is deprecated. Please replace with an entry in" + " a dict inside of the networks list with name: {name}" + " and routes_externally: {external}".format( + key=key, name=cloud[key], external=external)) + networks.append(dict( + name=cloud[key], + routes_externally=external)) + cloud['networks'] = networks + return cloud + def _handle_domain_id(self, cloud): # Allow people to just specify domain once if it's the same mappings = { diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py index 10a3d7b..0db1457 100644 --- a/os_client_config/tests/test_config.py +++ b/os_client_config/tests/test_config.py @@ -753,3 +753,34 @@ class TestBackwardsCompatibility(base.TestCase): } } self.assertEqual(expected, result) + + def test_backwards_network_fail(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + cloud = { + 'external_network': 'public', + 'networks': [ + {'name': 'private', 'routes_externally': False}, + ] + } + self.assertRaises( + exceptions.OpenStackConfigException, + c._fix_backwards_networks, cloud) + + def test_backwards_network(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + cloud = { + 'external_network': 'public', + 'internal_network': 'private', + } + result = c._fix_backwards_networks(cloud) + expected = { + 'external_network': 'public', + 'internal_network': 'private', + 'networks': [ + {'name': 'public', 'routes_externally': True}, + {'name': 'private', 'routes_externally': False}, + ] + } + self.assertEqual(expected, result) diff --git a/releasenotes/notes/network-list-e6e9dafdd8446263.yaml b/releasenotes/notes/network-list-e6e9dafdd8446263.yaml new file mode 100644 index 0000000..8375488 --- /dev/null +++ b/releasenotes/notes/network-list-e6e9dafdd8446263.yaml @@ -0,0 +1,11 @@ +--- +features: + - Support added for configuring metadata about networks + for a cloud in a list of dicts, rather than in the + external_network and internal_network entries. The dicts + support a name and a routes_externally field, as well as + any other arbitrary metadata needed by consuming + applications. +deprecations: + - external_network and internal_network are deprecated and + should be replaced with the list of network dicts.