fine tuning, and only use REST API for everything

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

View File

@ -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())