Determine region-specific endpoints correctly.
Previous behavior was hardcoded to pick the first endpoint
`endpoint = item['endpoints'][0]`
and then check if the region matched the configured region.
This fails for regions other than the first listed.
I've modified it to instead search through provided endpoints for a
matching region. If no region is configured, it falls back to original
behavior of picking first available endpoint.
For reference:
{'access': {'metadata': {'is_admin': 0, 'roles': []},
'serviceCatalog': [{'endpoints': [{'adminURL': 'someurl',
'id': 'someuuid',
'internalURL': 'someurl',
'publicURL': 'someurl',
'region': 'RegionOne'},
{'adminURL': 'someotherurl',
'id': 'someotheruuid',
'internalURL': 'someotherurl',
'publicURL': 'someotherurl',
'region': 'RegionTwo'}],
'endpoints_links': [],
'name': 'cinderv2',
'type': 'volumev2'},
Change-Id: I13eb1dff9fc3bfdefcdcdc50387b68189b0bba8a
diff --git a/collectd/files/plugin/collectd_openstack.py b/collectd/files/plugin/collectd_openstack.py
index e118332..f4745dd 100644
--- a/collectd/files/plugin/collectd_openstack.py
+++ b/collectd/files/plugin/collectd_openstack.py
@@ -108,9 +108,18 @@
data['access']['token']['expires']) - self.EXPIRATION_TOKEN_DELTA
self.service_catalog = []
for item in data['access']['serviceCatalog']:
- endpoint = item['endpoints'][0]
- if self.region and self.region != endpoint['region']:
- continue
+ endpoint = False
+ if self.region:
+ for e in item['endpoints']:
+ if self.region == e['region']:
+ endpoint = e
+ if not endpoint:
+ continue
+ else:
+ # If no region is defined, I guess we'll just keep the old
+ # behavior of picking the first one.
+ endpoint = item['endpoints'][0]
+
if 'internalURL' not in endpoint and 'publicURL' not in endpoint:
self.logger.warning(
"Skipping service '{}' with no valid URL".format(