diff options
author | Monty Taylor <mordred@inaugust.com> | 2015-10-01 10:50:27 -0400 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2015-10-01 13:51:43 -0400 |
commit | 7d84f102313e61aba00d7665250ac6f628f8e8f6 (patch) | |
tree | a70bec7eb1cc2f9a4177c5af2a1d70ce50a91d36 | |
parent | 733c04f6d381f523991c5ccfd56b9ff722111bf0 (diff) | |
download | os-client-config-7d84f102313e61aba00d7665250ac6f628f8e8f6.tar.gz |
Support passing force_ipv4 to the constructor
IPv6 support is detectable, so rather than having a user opt-in to it,
provide a flag that can be provided to tell it that detected IPv6
support is lying. This should have to be set for far fewer people and
should result in transparent opt-in to IPv6 where available.
Change-Id: Ib0c4c4e8b3b7b4bcee5fa3414719969274929b9a
-rw-r--r-- | README.rst | 18 | ||||
-rw-r--r-- | os_client_config/cloud_config.py | 10 | ||||
-rw-r--r-- | os_client_config/config.py | 36 | ||||
-rw-r--r-- | os_client_config/tests/base.py | 2 | ||||
-rw-r--r-- | os_client_config/tests/test_cloud_config.py | 6 | ||||
-rw-r--r-- | os_client_config/tests/test_config.py | 18 |
6 files changed, 64 insertions, 26 deletions
@@ -197,15 +197,18 @@ are connecting to OpenStack can share a cache should you desire. IPv6 ---- -IPv6 may be a thing you would prefer to use not only if the cloud supports it, -but also if your local machine support it. A simple boolean flag is settable -either in an environment variable, `OS_PREFER_IPV6`, or in the client section -of the clouds.yaml. +IPv6 is the future, and you should always use if if your cloud supports it and +if your local network supports it. Both of those are eaily detectable and all +friendly software should do the right thing. However, sometimes you might +exist in a location where you have an IPv6 stack, but something evil has +caused it to not actually function. In that case, there is a config option +you can set to unbreak you `force_ipv4`, or `OS_FORCE_IPV4` boolean +environment variable. :: client: - prefer_ipv6: true + force_ipv4: true clouds: mordred: profile: hp @@ -222,9 +225,8 @@ of the clouds.yaml. project_name: mordred@inaugust.com region_name: DFW -The above snippet will tell client programs to prefer returning an IPv6 -address. This will result in calls to, for instance, `shade`'s `get_public_ip` -to return an IPv4 address on HP, and an IPv6 address on Rackspace. +The above snippet will tell client programs to prefer returning an IPv4 +address. Usage ----- diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py index 86b4f50..c8b5269 100644 --- a/os_client_config/cloud_config.py +++ b/os_client_config/cloud_config.py @@ -17,11 +17,11 @@ import warnings class CloudConfig(object): def __init__(self, name, region, config, - prefer_ipv6=False, auth_plugin=None): + force_ipv4=False, auth_plugin=None): self.name = name self.region = region self.config = config - self._prefer_ipv6 = prefer_ipv6 + self._force_ipv4 = force_ipv4 self._auth = auth_plugin def __getattr__(self, key): @@ -107,7 +107,11 @@ class CloudConfig(object): @property def prefer_ipv6(self): - return self._prefer_ipv6 + return not self._force_ipv4 + + @property + def force_ipv4(self): + return self._force_ipv4 def get_auth(self): """Return a keystoneauth plugin from the auth credentials.""" diff --git a/os_client_config/config.py b/os_client_config/config.py index 2cea7ee..f43fe74 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -113,7 +113,7 @@ def _auth_update(old_dict, new_dict): class OpenStackConfig(object): def __init__(self, config_files=None, vendor_files=None, - override_defaults=None): + override_defaults=None, force_ipv4=None): self._config_files = config_files or CONFIG_FILES self._vendor_files = vendor_files or VENDOR_FILES @@ -135,11 +135,28 @@ class OpenStackConfig(object): # Grab ipv6 preference settings from env client_config = self.cloud_config.get('client', {}) - self.prefer_ipv6 = get_boolean( - os.environ.pop( - 'OS_PREFER_IPV6', client_config.get( - 'prefer_ipv6', client_config.get( - 'prefer-ipv6', False)))) + + if force_ipv4 is not None: + # If it's passed in to the constructor, honor it. + self.force_ipv4 = force_ipv4 + else: + # Get the backwards compat value + prefer_ipv6 = get_boolean( + os.environ.pop( + 'OS_PREFER_IPV6', client_config.get( + 'prefer_ipv6', client_config.get( + 'prefer-ipv6', True)))) + force_ipv4 = get_boolean( + os.environ.pop( + 'OS_FORCE_IPV4', client_config.get( + 'force_ipv4', client_config.get( + 'broken-ipv6', False)))) + + self.force_ipv4 = force_ipv4 + if not prefer_ipv6: + # this will only be false if someone set it explicitly + # honor their wishes + self.force_ipv4 = True # Next, process environment variables and add them to the mix self.envvar_key = os.environ.pop('OS_CLOUD_NAME', 'envvars') @@ -586,7 +603,10 @@ class OpenStackConfig(object): if hasattr(value, 'format'): config[key] = value.format(**config) - prefer_ipv6 = config.pop('prefer_ipv6', self.prefer_ipv6) + force_ipv4 = config.pop('force_ipv4', self.force_ipv4) + prefer_ipv6 = config.pop('prefer_ipv6', True) + if not prefer_ipv6: + force_ipv4 = True if cloud is None: cloud_name = '' @@ -595,7 +615,7 @@ class OpenStackConfig(object): return cloud_config.CloudConfig( name=cloud_name, region=config['region_name'], config=self._normalize_keys(config), - prefer_ipv6=prefer_ipv6, + force_ipv4=force_ipv4, auth_plugin=auth_plugin) @staticmethod diff --git a/os_client_config/tests/base.py b/os_client_config/tests/base.py index cbf58da..36c3bfb 100644 --- a/os_client_config/tests/base.py +++ b/os_client_config/tests/base.py @@ -40,7 +40,7 @@ VENDOR_CONF = { } USER_CONF = { 'client': { - 'prefer_ipv6': True, + 'force_ipv4': True, }, 'clouds': { '_test-cloud_': { diff --git a/os_client_config/tests/test_cloud_config.py b/os_client_config/tests/test_cloud_config.py index 4f5260f..c9317ad 100644 --- a/os_client_config/tests/test_cloud_config.py +++ b/os_client_config/tests/test_cloud_config.py @@ -50,7 +50,7 @@ class TestCloudConfig(base.TestCase): self.assertIsNone(cc.x) # Test default ipv6 - self.assertFalse(cc.prefer_ipv6) + self.assertFalse(cc.force_ipv4) def test_iteration(self): cc = cloud_config.CloudConfig("test1", "region-al", fake_config_dict) @@ -116,8 +116,8 @@ class TestCloudConfig(base.TestCase): def test_ipv6(self): cc = cloud_config.CloudConfig( - "test1", "region-al", fake_config_dict, prefer_ipv6=True) - self.assertTrue(cc.prefer_ipv6) + "test1", "region-al", fake_config_dict, force_ipv4=True) + self.assertTrue(cc.force_ipv4) def test_getters(self): cc = cloud_config.CloudConfig("test1", "region-al", fake_services_dict) diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py index 3331b33..271c40b 100644 --- a/os_client_config/tests/test_config.py +++ b/os_client_config/tests/test_config.py @@ -136,16 +136,28 @@ class TestConfig(base.TestCase): c.get_one_cloud(cloud='defaults', validate=False) def test_prefer_ipv6_true(self): + c = config.OpenStackConfig(config_files=[self.no_yaml], + vendor_files=[self.no_yaml]) + cc = c.get_one_cloud(cloud='defaults', validate=False) + self.assertTrue(cc.prefer_ipv6) + + def test_prefer_ipv6_false(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud(cloud='_test-cloud_') - self.assertTrue(cc.prefer_ipv6) + self.assertFalse(cc.prefer_ipv6) - def test_prefer_ipv6_false(self): + def test_force_ipv4_true(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + cc = c.get_one_cloud(cloud='_test-cloud_') + self.assertTrue(cc.force_ipv4) + + def test_force_ipv4_false(self): c = config.OpenStackConfig(config_files=[self.no_yaml], vendor_files=[self.no_yaml]) cc = c.get_one_cloud(cloud='defaults', validate=False) - self.assertFalse(cc.prefer_ipv6) + self.assertFalse(cc.force_ipv4) def test_get_one_cloud_auth_merge(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml]) |