Throw error if a non-existent cloud is requested

The error messages when a bogus cloud is requested are very confusing.
(They'll be things like "no auth url provided") Instead, be explicit
on the problem.

Change-Id: Idf68d1db7e5fccd712283775eb4d636d78ae5fc7
This commit is contained in:
Monty Taylor 2014-11-02 13:44:36 +01:00
parent fc0b80ed3b
commit 1c025d548f
2 changed files with 16 additions and 17 deletions

View File

@ -15,7 +15,7 @@
class CloudConfig(object):
def __init__(self, name, region, config):
self.name = name
self.name = name or 'openstack'
self.region = region
self.config = config

View File

@ -115,10 +115,14 @@ class OpenStackConfig(object):
def _get_base_cloud_config(self, name):
cloud = dict()
if name in self.cloud_config['clouds']:
our_cloud = self.cloud_config['clouds'][name]
else:
our_cloud = dict()
# Only validate cloud name if one was given
if name and name not in self.cloud_config['clouds']:
raise exceptions.OpenStackConfigException(
"Named cloud {name} requested that was not found.".format(
name=name))
our_cloud = self.cloud_config['clouds'].get(name, dict())
# Get the defaults (including env vars) first
cloud.update(self.defaults)
@ -208,15 +212,10 @@ class OpenStackConfig(object):
args = self._fix_args(kwargs, argparse=argparse)
if cloud:
name = cloud
else:
name = 'openstack'
if 'region_name' not in args:
args['region_name'] = self._get_region(name)
args['region_name'] = self._get_region(cloud)
config = self._get_base_cloud_config(name)
config = self._get_base_cloud_config(cloud)
# Can't just do update, because None values take over
for (key, val) in args.iteritems():
@ -233,15 +232,15 @@ class OpenStackConfig(object):
if key not in config or not config[key]:
raise exceptions.OpenStackConfigException(
'Unable to find full auth information for cloud'
' {name} in config files {files}'
' {cloud} in config files {files}'
' or environment variables.'.format(
name=name, files=','.join(self._config_files)))
cloud=cloud, files=','.join(self._config_files)))
if 'project_name' not in config and 'project_id' not in config:
raise exceptions.OpenStackConfigException(
'Neither project_name or project_id information found'
' for cloud {name} in config files {files}'
' for cloud {cloud} in config files {files}'
' or environment variables.'.format(
name=name, files=','.join(self._config_files)))
cloud=cloud, files=','.join(self._config_files)))
# If any of the defaults reference other values, we need to expand
for (key, value) in config.items():
@ -249,7 +248,7 @@ class OpenStackConfig(object):
config[key] = value.format(**config)
return cloud_config.CloudConfig(
name=name, region=config['region_name'], config=config)
name=cloud, region=config['region_name'], config=config)
if __name__ == '__main__':
config = OpenStackConfig().get_all_clouds()