summaryrefslogtreecommitdiff
path: root/os_client_config
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-07-04 10:55:25 -0400
committerMonty Taylor <mordred@inaugust.com>2015-07-09 09:11:31 -0400
commit1065ea4dbf91a1416e267223d0db96719490653b (patch)
treede9895d318786b228942dd9817c910d1d8bac8a2 /os_client_config
parent3410dc09500c742ca905c9d98ad0eafdf0df2300 (diff)
downloados-client-config-1065ea4dbf91a1416e267223d0db96719490653b.tar.gz
Add support for configuring region lists with yaml
yaml supports encoding lists in a manner that is cleaner than comma separated lists. While the old commas-in-region_name will still work, add a 'regions' option that can be used to configure lists of regions. Remove the comma-separated-list from the docs so that people don't try to use it - even though it will work. Change-Id: Ieb0aedb9c03fd26e644e9ba733b935f2c69daaf0
Diffstat (limited to 'os_client_config')
-rw-r--r--os_client_config/config.py24
-rw-r--r--os_client_config/tests/base.py11
-rw-r--r--os_client_config/tests/test_config.py26
-rw-r--r--os_client_config/vendors/hp.yaml4
-rw-r--r--os_client_config/vendors/rackspace.yaml7
-rw-r--r--os_client_config/vendors/runabove.yaml4
-rw-r--r--os_client_config/vendors/unitedstack.yaml4
7 files changed, 68 insertions, 12 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 55328cc..93d7aa0 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -199,14 +199,24 @@ class OpenStackConfig(object):
return self._cache_arguments
def _get_regions(self, cloud):
- try:
- return self.cloud_config['clouds'][cloud]['region_name']
- except KeyError:
- # No region configured
- return ''
+ if cloud not in self.cloud_config['clouds']:
+ return ['']
+ config = self._normalize_keys(self.cloud_config['clouds'][cloud])
+ if 'regions' in config:
+ return config['regions']
+ elif 'region_name' in config:
+ regions = config['region_name'].split(',')
+ if len(regions) > 1:
+ warnings.warn(
+ "Comma separated lists in region_name are deprecated."
+ " Please use a yaml list in the regions"
+ " parameter in {0} instead.".format(self.config_filename))
+ return regions
+ else:
+ return ['']
def _get_region(self, cloud=None):
- return self._get_regions(cloud).split(',')[0]
+ return self._get_regions(cloud)[0]
def get_cloud_names(self):
return self.cloud_config['clouds'].keys()
@@ -301,7 +311,7 @@ class OpenStackConfig(object):
clouds = []
for cloud in self.get_cloud_names():
- for region in self._get_regions(cloud).split(','):
+ for region in self._get_regions(cloud):
clouds.append(self.get_one_cloud(cloud, region_name=region))
return clouds
diff --git a/os_client_config/tests/base.py b/os_client_config/tests/base.py
index 8bb9145..569b52e 100644
--- a/os_client_config/tests/base.py
+++ b/os_client_config/tests/base.py
@@ -67,6 +67,17 @@ USER_CONF = {
},
'region_name': 'test-region',
},
+ '_test_cloud_regions': {
+ 'auth': {
+ 'username': 'testuser',
+ 'password': 'testpass',
+ 'project-id': 'testproject',
+ },
+ 'regions': [
+ 'region1',
+ 'region2',
+ ],
+ },
'_test_cloud_hyphenated': {
'auth': {
'username': 'testuser',
diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py
index 4c244d2..dde7d83 100644
--- a/os_client_config/tests/test_config.py
+++ b/os_client_config/tests/test_config.py
@@ -32,7 +32,11 @@ class TestConfig(base.TestCase):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
clouds = c.get_all_clouds()
- user_clouds = [cloud for cloud in base.USER_CONF['clouds'].keys()]
+ # We add one by hand because the regions cloud is going to exist
+ # twice since it has two regions in it
+ user_clouds = [
+ cloud for cloud in base.USER_CONF['clouds'].keys()
+ ] + ['_test_cloud_regions']
configured_clouds = [cloud.name for cloud in clouds]
self.assertItemsEqual(user_clouds, configured_clouds)
@@ -132,6 +136,7 @@ class TestConfig(base.TestCase):
'_test-cloud_',
'_test_cloud_hyphenated',
'_test_cloud_no_vendor',
+ '_test_cloud_regions',
],
sorted(c.get_cloud_names()))
c = config.OpenStackConfig(config_files=[self.no_yaml],
@@ -216,6 +221,25 @@ class TestConfigArgparse(base.TestCase):
self.assertEqual(cc.region_name, 'test-region')
self.assertIsNone(cc.snack_type)
+ def test_get_one_cloud_no_argparse_regions(self):
+ c = config.OpenStackConfig(config_files=[self.cloud_yaml],
+ vendor_files=[self.vendor_yaml])
+
+ cc = c.get_one_cloud(cloud='_test_cloud_regions', argparse=None)
+ self._assert_cloud_details(cc)
+ self.assertEqual(cc.region_name, 'region1')
+ self.assertIsNone(cc.snack_type)
+
+ def test_get_one_cloud_no_argparse_region2(self):
+ c = config.OpenStackConfig(config_files=[self.cloud_yaml],
+ vendor_files=[self.vendor_yaml])
+
+ cc = c.get_one_cloud(
+ cloud='_test_cloud_regions', region_name='region2', argparse=None)
+ self._assert_cloud_details(cc)
+ self.assertEqual(cc.region_name, 'region2')
+ self.assertIsNone(cc.snack_type)
+
def test_fix_env_args(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
diff --git a/os_client_config/vendors/hp.yaml b/os_client_config/vendors/hp.yaml
index 2773433..4da4956 100644
--- a/os_client_config/vendors/hp.yaml
+++ b/os_client_config/vendors/hp.yaml
@@ -2,5 +2,7 @@ name: hp
profile:
auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0
- region_name: region-a.geo-1,region-b.geo-1
+ regions:
+ - region-a.geo-1
+ - region-b.geo-1
dns_service_type: hpext:dns
diff --git a/os_client_config/vendors/rackspace.yaml b/os_client_config/vendors/rackspace.yaml
index a350584..ad7825d 100644
--- a/os_client_config/vendors/rackspace.yaml
+++ b/os_client_config/vendors/rackspace.yaml
@@ -2,7 +2,12 @@ name: rackspace
profile:
auth:
auth_url: https://identity.api.rackspacecloud.com/v2.0/
- region_name: DFW,ORD,IAD,SYD,HKG
+ regions:
+ - DFW
+ - HKG
+ - IAD
+ - ORD
+ - SYD
database_service_type: rax:database
compute_service_name: cloudServersOpenStack
image_api_version: '2'
diff --git a/os_client_config/vendors/runabove.yaml b/os_client_config/vendors/runabove.yaml
index 381020a..57e75f3 100644
--- a/os_client_config/vendors/runabove.yaml
+++ b/os_client_config/vendors/runabove.yaml
@@ -2,7 +2,9 @@ name: runabove
profile:
auth:
auth_url: https://auth.runabove.io/v2.0
- region_name: SBG-1,BHS-1
+ regions:
+ - BHS-1
+ - SBG-1
image_api_version: '2'
image_format: qcow2
floating_ip_source: None
diff --git a/os_client_config/vendors/unitedstack.yaml b/os_client_config/vendors/unitedstack.yaml
index db9b612..f22bd8a 100644
--- a/os_client_config/vendors/unitedstack.yaml
+++ b/os_client_config/vendors/unitedstack.yaml
@@ -2,7 +2,9 @@ name: unitedstack
profile:
auth:
auth_url: https://identity.api.ustack.com/v3
- region_name: bj1,gd1
+ regions:
+ - bj1
+ - gd1
identity_api_version: '3'
image_api_version: '2'
image_format: raw