Use Keystone v3 API for getting users and tenants
In multi-domain environments, it is necessary to use the Keystone v3
API.
Change-Id: Ic9df43c655802caf564653baf5397ea697b7a4aa
Co-Authored-By: Danil Akhmetov <dakhmetov@mirantis.com>
diff --git a/collectd/files/plugin/collectd_openstack.py b/collectd/files/plugin/collectd_openstack.py
index a8fa999..1aeeb36 100644
--- a/collectd/files/plugin/collectd_openstack.py
+++ b/collectd/files/plugin/collectd_openstack.py
@@ -169,12 +169,11 @@
def _build_url(self, service, resource):
s = (self.get_service(service) or {})
- # the adminURL must be used to access resources with Keystone API v2
- if service == 'keystone' and \
- (resource in ['tenants', 'users'] or 'OS-KS' in resource):
- url = s.get('admin_url')
- else:
- url = s.get('url')
+ url = s.get('url')
+ # v3 API must be used in order to obtain tenants in multi-domain envs
+ if service == 'keystone' and (resource in ['projects',
+ 'users', 'roles']):
+ url = url.replace('v2.0', 'v3')
if url:
if url[-1] != '/':
diff --git a/collectd/files/plugin/openstack_keystone.py b/collectd/files/plugin/openstack_keystone.py
index b84fbc6..e631baf 100644
--- a/collectd/files/plugin/openstack_keystone.py
+++ b/collectd/files/plugin/openstack_keystone.py
@@ -40,11 +40,11 @@
return 'enabled' if d.get('enabled') else 'disabled'
# tenants
- r = self.get('keystone', 'tenants')
+ r = self.get('keystone', 'projects')
if not r:
self.logger.warning('Could not find Keystone tenants')
return
- tenants_details = r.json().get('tenants', [])
+ tenants_details = r.json().get('projects', [])
status = self.count_objects_group_by(tenants_details,
group_by_func=groupby)
for s, nb in status.iteritems():
@@ -70,7 +70,7 @@
}
# roles
- r = self.get('keystone', 'OS-KSADM/roles')
+ r = self.get('keystone', 'roles')
if not r:
self.logger.warning('Could not find Keystone roles')
return