mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
nova: fix endpoint URL determination in _v3_setup()
Some OpenStack setups return multiple entries for the same service. This change makes the code consider all matching entries instead of just the first one.
This commit is contained in:
parent
1da1a97d7d
commit
6e00e415d3
@ -191,6 +191,16 @@ def get_entry_multi(dict_, pairs, raise_error=True):
|
||||
return {}
|
||||
|
||||
|
||||
def get_endpoint_url_v3(catalog, service_type, region_name):
|
||||
for service_entry in catalog:
|
||||
if service_entry['type'] == service_type:
|
||||
for endpoint_entry in service_entry['endpoints']:
|
||||
if (endpoint_entry['region'] == region_name and
|
||||
endpoint_entry['interface'] == 'public'):
|
||||
return endpoint_entry['url']
|
||||
return None
|
||||
|
||||
|
||||
def sanatize_novaclient(kwargs):
|
||||
variables = (
|
||||
'username', 'api_key', 'project_id', 'auth_url', 'insecure',
|
||||
@ -353,21 +363,16 @@ class SaltNova(object):
|
||||
|
||||
def _v3_setup(self, region_name):
|
||||
if region_name is not None:
|
||||
servers_endpoints = get_entry(self.catalog, 'type', 'compute')['endpoints']
|
||||
self.kwargs['bypass_url'] = get_entry_multi(
|
||||
servers_endpoints,
|
||||
[('region', region_name), ('interface', 'public')]
|
||||
)['url']
|
||||
self.client_kwargs['bypass_url'] = get_endpoint_url_v3(self.catalog, 'compute', region_name)
|
||||
log.debug('Using Nova bypass_url: %s', self.client_kwargs['bypass_url'])
|
||||
|
||||
self.compute_conn = client.Client(version=self.version, session=self.session, **self.client_kwargs)
|
||||
|
||||
volume_endpoints = get_entry(self.catalog, 'type', 'volume', raise_error=False).get('endpoints', {})
|
||||
if volume_endpoints:
|
||||
if region_name is not None:
|
||||
self.kwargs['bypass_url'] = get_entry_multi(
|
||||
volume_endpoints,
|
||||
[('region', region_name), ('interface', 'public')]
|
||||
)['url']
|
||||
self.client_kwargs['bypass_url'] = get_endpoint_url_v3(self.catalog, 'volume', region_name)
|
||||
log.debug('Using Cinder bypass_url: %s', self.client_kwargs['bypass_url'])
|
||||
|
||||
self.volume_conn = client.Client(version=self.version, session=self.session, **self.client_kwargs)
|
||||
if hasattr(self, 'extensions'):
|
||||
|
Loading…
Reference in New Issue
Block a user