diff --git a/openstack/config/loader.py b/openstack/config/loader.py index 030fc029b..e5ac28a75 100644 --- a/openstack/config/loader.py +++ b/openstack/config/loader.py @@ -448,35 +448,37 @@ class OpenStackConfig(object): # Expand a profile if it exists. 'cloud' is an old confusing name # for this. profile_name = our_cloud.get('profile', our_cloud.get('cloud', None)) - if profile_name and profile_name != self.envvar_key: - if 'cloud' in our_cloud: - warnings.warn( - "{0} use the keyword 'cloud' to reference a known " - "vendor profile. This has been deprecated in favor of the " - "'profile' keyword.".format(self.config_filename)) - vendor_filename, vendor_file = self._load_vendor_file() - if vendor_file and profile_name in vendor_file['public-clouds']: - _auth_update(cloud, vendor_file['public-clouds'][profile_name]) + if not profile_name or profile_name == self.envvar_key: + return + if 'cloud' in our_cloud: + warnings.warn( + "{0} uses the keyword 'cloud' to reference a known " + "vendor profile. This has been deprecated in favor of the " + "'profile' keyword.".format(self.config_filename)) + + vendor_filename, vendor_file = self._load_vendor_file() + if vendor_file and profile_name in vendor_file['public-clouds']: + _auth_update(cloud, vendor_file['public-clouds'][profile_name]) + else: + profile_data = vendors.get_profile(profile_name) + if profile_data: + status = profile_data.pop('status', 'active') + message = profile_data.pop('message', '') + if status == 'deprecated': + warnings.warn( + "{profile_name} is deprecated: {message}".format( + profile_name=profile_name, message=message)) + elif status == 'shutdown': + raise exceptions.ConfigException( + "{profile_name} references a cloud that no longer" + " exists: {message}".format( + profile_name=profile_name, message=message)) + _auth_update(cloud, profile_data) else: - profile_data = vendors.get_profile(profile_name) - if profile_data: - status = profile_data.pop('status', 'active') - message = profile_data.pop('message', '') - if status == 'deprecated': - warnings.warn( - "{profile_name} is deprecated: {message}".format( - profile_name=profile_name, message=message)) - elif status == 'shutdown': - raise exceptions.ConfigException( - "{profile_name} references a cloud that no longer" - " exists: {message}".format( - profile_name=profile_name, message=message)) - _auth_update(cloud, profile_data) - else: - # Can't find the requested vendor config, go about business - warnings.warn("Couldn't find the vendor profile '{0}', for" - " the cloud '{1}'".format(profile_name, - name)) + # Can't find the requested vendor config, go about business + warnings.warn("Couldn't find the vendor profile '{0}', for" + " the cloud '{1}'".format(profile_name, + name)) def _project_scoped(self, cloud): return ('project_id' in cloud or 'project_name' in cloud diff --git a/openstack/config/vendors/__init__.py b/openstack/config/vendors/__init__.py index 3e1d20a5a..f46a64351 100644 --- a/openstack/config/vendors/__init__.py +++ b/openstack/config/vendors/__init__.py @@ -18,20 +18,25 @@ import os import yaml -_vendors_path = os.path.dirname(os.path.realpath(__file__)) -_vendor_defaults = None +_VENDORS_PATH = os.path.dirname(os.path.realpath(__file__)) +_VENDOR_DEFAULTS = {} + + +def _get_vendor_defaults(): + global _VENDOR_DEFAULTS + if not _VENDOR_DEFAULTS: + for vendor in glob.glob(os.path.join(_VENDORS_PATH, '*.yaml')): + with open(vendor, 'r') as f: + vendor_data = yaml.safe_load(f) + _VENDOR_DEFAULTS[vendor_data['name']] = vendor_data['profile'] + for vendor in glob.glob(os.path.join(_VENDORS_PATH, '*.json')): + with open(vendor, 'r') as f: + vendor_data = json.load(f) + _VENDOR_DEFAULTS[vendor_data['name']] = vendor_data['profile'] + return _VENDOR_DEFAULTS def get_profile(profile_name): - global _vendor_defaults - if _vendor_defaults is None: - _vendor_defaults = {} - for vendor in glob.glob(os.path.join(_vendors_path, '*.yaml')): - with open(vendor, 'r') as f: - vendor_data = yaml.safe_load(f) - _vendor_defaults[vendor_data['name']] = vendor_data['profile'] - for vendor in glob.glob(os.path.join(_vendors_path, '*.json')): - with open(vendor, 'r') as f: - vendor_data = json.load(f) - _vendor_defaults[vendor_data['name']] = vendor_data['profile'] - return _vendor_defaults.get(profile_name) + vendor_defaults = _get_vendor_defaults() + if profile_name in vendor_defaults: + return vendor_defaults[profile_name].copy()