From 5532a666d43b44454c0ffbd3cabe3d1bb6aa158a Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Thu, 3 Nov 2022 23:00:23 +0000 Subject: [PATCH] add endpoint_type variable, and fine tune grab of credentials --- check_openstack.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/check_openstack.py b/check_openstack.py index 3bf95d1..87f8b4c 100755 --- a/check_openstack.py +++ b/check_openstack.py @@ -10,13 +10,17 @@ from keystoneclient.v3.client import Client as keystone_auth headers = {} headers['content-type'] = 'application/json' +endpoint_type = "public" + def get_credentials(site_id): home = os.environ['HOME'] with open('{}/clouds.yaml'.format(home), 'r') as stream: - creds = yaml.safe_load(stream)['clouds'][site_id]['auth'] + clouds = yaml.safe_load(stream)['clouds'] + + creds = clouds[site_id]['auth'] + creds['version'] = clouds[site_id]['identity_api_version'] - creds['version'] = '2' return creds @@ -28,7 +32,7 @@ def get_servers(keystone): url = keystone.service_catalog.get_endpoints( service_name="nova", - endpoint_type="public" + endpoint_type=endpoint_type, )['compute'][0]['url'] request = "servers" @@ -45,7 +49,7 @@ def get_cores(keystone): url = keystone.service_catalog.get_endpoints( service_name="placement", - endpoint_type="public" + endpoint_type=endpoint_type, )['placement'][0]['url'] psc_request = "resource_providers" @@ -76,7 +80,7 @@ def get_networks(keystone): url = keystone.service_catalog.get_endpoints( service_name="neutron", - endpoint_type="public" + endpoint_type=endpoint_type, )['network'][0]['url'] request = "networks"