grab the site id from command line

This commit is contained in:
Arif Ali 2022-11-03 11:34:34 +00:00
parent d26633b37e
commit 1e632d468e
Signed by: arif
GPG Key ID: 369608FBA1353A70

View File

@ -3,33 +3,33 @@
import os
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():
with open('/home/arif/clouds.yaml','r') as stream:
creds = yaml.safe_load(stream)['clouds']['arif-home']['auth']
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']
creds['version'] = '2'
return creds
def get_auth_token():
creds = get_credentials()
def get_auth_token(creds):
keystone_client = keystone_auth(**creds)
return keystone_client.auth_token
def get_servers():
creds = get_credentials()
def get_servers(creds):
nova_client = nova_auth(**creds)
print(nova_client.servers.list())
def get_cores():
def get_cores(creds):
url="http://placement.example.com:8778"
token = get_auth_token()
token = get_auth_token(creds)
headers = {}
headers['content-type'] = 'application/json'
@ -59,9 +59,18 @@ def get_cores():
print("{}: {}".format(hostname,cores))
def main():
get_servers()
get_cores()
def _parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--site', metavar="<site-id>",
help="Site to run against", dest="site_id",
required=True)
return parser.parse_args()
def main(args):
creds = get_credentials(args.site_id)
get_servers(creds)
get_cores(creds)
if __name__ == '__main__':
main()
main(_parse_args())