Add get_networks function

This commit is contained in:
Arif Ali 2022-11-03 16:22:59 +00:00
parent 08d658e1f9
commit 5932fcdbcd
Signed by: arif
GPG Key ID: 369608FBA1353A70

View File

@ -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="<site-id>",
@ -75,6 +96,7 @@ def main(args):
get_servers(creds)
get_cores(creds)
get_networks(creds)
if __name__ == '__main__':
main(_parse_args())