Slightly refactor vendor profile loading
In prep for the next patch which will add support for url-based vendor profiles, rearrange a few bits of the vendor profile loading code. This should make the next patch easier to read. Change-Id: I3b18678895006249c0e958944c88f09a365daee0
This commit is contained in:
parent
ca636b92e3
commit
1da367b537
@ -448,35 +448,37 @@ class OpenStackConfig(object):
|
|||||||
# Expand a profile if it exists. 'cloud' is an old confusing name
|
# Expand a profile if it exists. 'cloud' is an old confusing name
|
||||||
# for this.
|
# for this.
|
||||||
profile_name = our_cloud.get('profile', our_cloud.get('cloud', None))
|
profile_name = our_cloud.get('profile', our_cloud.get('cloud', None))
|
||||||
if profile_name and profile_name != self.envvar_key:
|
if not profile_name or profile_name == self.envvar_key:
|
||||||
if 'cloud' in our_cloud:
|
return
|
||||||
warnings.warn(
|
if 'cloud' in our_cloud:
|
||||||
"{0} use the keyword 'cloud' to reference a known "
|
warnings.warn(
|
||||||
"vendor profile. This has been deprecated in favor of the "
|
"{0} uses the keyword 'cloud' to reference a known "
|
||||||
"'profile' keyword.".format(self.config_filename))
|
"vendor profile. This has been deprecated in favor of the "
|
||||||
vendor_filename, vendor_file = self._load_vendor_file()
|
"'profile' keyword.".format(self.config_filename))
|
||||||
if vendor_file and profile_name in vendor_file['public-clouds']:
|
|
||||||
_auth_update(cloud, vendor_file['public-clouds'][profile_name])
|
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:
|
else:
|
||||||
profile_data = vendors.get_profile(profile_name)
|
# Can't find the requested vendor config, go about business
|
||||||
if profile_data:
|
warnings.warn("Couldn't find the vendor profile '{0}', for"
|
||||||
status = profile_data.pop('status', 'active')
|
" the cloud '{1}'".format(profile_name,
|
||||||
message = profile_data.pop('message', '')
|
name))
|
||||||
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))
|
|
||||||
|
|
||||||
def _project_scoped(self, cloud):
|
def _project_scoped(self, cloud):
|
||||||
return ('project_id' in cloud or 'project_name' in cloud
|
return ('project_id' in cloud or 'project_name' in cloud
|
||||||
|
33
openstack/config/vendors/__init__.py
vendored
33
openstack/config/vendors/__init__.py
vendored
@ -18,20 +18,25 @@ import os
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
_vendors_path = os.path.dirname(os.path.realpath(__file__))
|
_VENDORS_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||||
_vendor_defaults = None
|
_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):
|
def get_profile(profile_name):
|
||||||
global _vendor_defaults
|
vendor_defaults = _get_vendor_defaults()
|
||||||
if _vendor_defaults is None:
|
if profile_name in vendor_defaults:
|
||||||
_vendor_defaults = {}
|
return vendor_defaults[profile_name].copy()
|
||||||
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)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user