From 5fd8ce1330739e493d6a42fe9584d95917e9e06b Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Thu, 3 Nov 2022 16:59:58 +0000 Subject: [PATCH] fine tuning, and only use REST API for everything --- check_openstack.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/check_openstack.py b/check_openstack.py index e009e15..5b8b511 100644 --- a/check_openstack.py +++ b/check_openstack.py @@ -5,7 +5,6 @@ import requests import yaml import argparse -from novaclient.client import Client as nova_auth from keystoneclient.v3.client import Client as keystone_auth def get_credentials(site_id): @@ -20,18 +19,29 @@ def get_keystoneclient(creds): return keystone_auth(**creds) def get_auth_token(creds): - keystone_client = keystone_auth(**creds) + keystone_client = get_keystoneclient(creds) return keystone_client.auth_token -def get_servers(creds): - nova_client = nova_auth(**creds) +def get_servers(keystone,token): - print(nova_client.servers.list()) + url = keystone.service_catalog.get_endpoints(service_name="nova",endpoint_type="public")['compute'][0]['url'] -def get_cores(creds): - keystone = get_keystoneclient(creds) - token = keystone.auth_token + headers = {} + headers['content-type'] = 'application/json' + headers['x-auth-token'] = token + + request = "/servers" + + r = requests.get("{}/{}".format(url,request),headers=headers) + + servers = r.json()['servers'] + + for server in servers: + print("id: {}".format(server['id'])) + + +def get_cores(keystone,token): url = keystone.service_catalog.get_endpoints(service_name="placement",endpoint_type="public")['placement'][0]['url'] @@ -62,9 +72,7 @@ def get_cores(creds): print("{}: {}".format(hostname,cores)) -def get_networks(creds): - keystone = get_keystoneclient(creds) - token = keystone.auth_token +def get_networks(keystone,token): url = keystone.service_catalog.get_endpoints(service_name="neutron",endpoint_type="public")['network'][0]['url'] @@ -81,8 +89,7 @@ def get_networks(creds): networks = r.json()['networks'] for network in networks: - print(network['id']) - + print("id: {}".format(network['id'])) def _parse_args(): parser = argparse.ArgumentParser() @@ -94,9 +101,12 @@ def _parse_args(): def main(args): creds = get_credentials(args.site_id) - get_servers(creds) - get_cores(creds) - get_networks(creds) + keystone = get_keystoneclient(creds) + token = keystone.auth_token + + get_servers(keystone,token) + get_cores(keystone,token) + get_networks(keystone,token) if __name__ == '__main__': main(_parse_args())