From 5932fcdbcd1cf2f1b0623debe7f886d9deceac8f Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Thu, 3 Nov 2022 16:22:59 +0000 Subject: [PATCH] Add get_networks function --- check_openstack.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/check_openstack.py b/check_openstack.py index fd92b28..e009e15 100644 --- a/check_openstack.py +++ b/check_openstack.py @@ -60,9 +60,30 @@ def get_cores(creds): if 'PCPU' in inventory: cores+=inventory['PCPU']['total'] - print("{}: {}".format(hostname,cores)) +def get_networks(creds): + keystone = get_keystoneclient(creds) + token = keystone.auth_token + + url = keystone.service_catalog.get_endpoints(service_name="neutron",endpoint_type="public")['network'][0]['url'] + + headers = {} + headers['content-type'] = 'application/json' + headers['x-auth-token'] = token + + data = {} + + request = "networks" + + r = requests.get("{}/v2.0/{}".format(url,request),headers=headers) + + networks = r.json()['networks'] + + for network in networks: + print(network['id']) + + def _parse_args(): parser = argparse.ArgumentParser() parser.add_argument('-s', '--site', metavar="", @@ -75,6 +96,7 @@ def main(args): get_servers(creds) get_cores(creds) + get_networks(creds) if __name__ == '__main__': main(_parse_args())