diff --git a/check_openstack.py b/check_openstack.py index 85e5968..3bf95d1 100755 --- a/check_openstack.py +++ b/check_openstack.py @@ -13,7 +13,7 @@ headers['content-type'] = 'application/json' def get_credentials(site_id): home = os.environ['HOME'] - with open('{}/clouds.yaml'.format(home),'r') as stream: + with open('{}/clouds.yaml'.format(home), 'r') as stream: creds = yaml.safe_load(stream)['clouds'][site_id]['auth'] creds['version'] = '2' @@ -26,11 +26,14 @@ def get_keystoneclient(creds): def get_servers(keystone): - url = keystone.service_catalog.get_endpoints(service_name="nova",endpoint_type="public")['compute'][0]['url'] + url = keystone.service_catalog.get_endpoints( + service_name="nova", + endpoint_type="public" + )['compute'][0]['url'] request = "servers" - r = requests.get("{}/{}".format(url,request),headers=headers) + r = requests.get("{}/{}".format(url, request), headers=headers) servers = r.json()[request] @@ -40,39 +43,45 @@ def get_servers(keystone): def get_cores(keystone): - url = keystone.service_catalog.get_endpoints(service_name="placement",endpoint_type="public")['placement'][0]['url'] + url = keystone.service_catalog.get_endpoints( + service_name="placement", + endpoint_type="public" + )['placement'][0]['url'] psc_request = "resource_providers" - r = requests.get("{}/{}".format(url,psc_request),headers=headers) + r = requests.get("{}/{}".format(url, psc_request), headers=headers) if psc_request in r.json(): for res in r.json()[psc_request]: uuid = res['uuid'] hostname = res['name'] - request = "/{}/{}/inventories".format(psc_request,uuid) - - r = requests.get("{}/{}".format(url,request),headers=headers) + request = "/{}/{}/inventories".format(psc_request, uuid) + + r = requests.get("{}/{}".format(url, request), headers=headers) inventory = r.json()['inventories'] - cores=0 + cores = 0 if 'VCPU' in inventory: - cores+=inventory['VCPU']['total'] + cores += inventory['VCPU']['total'] if 'PCPU' in inventory: - cores+=inventory['PCPU']['total'] + cores += inventory['PCPU']['total'] - print("{}: {}".format(hostname,cores)) + print("{}: {}".format(hostname, cores)) def get_networks(keystone): - url = keystone.service_catalog.get_endpoints(service_name="neutron",endpoint_type="public")['network'][0]['url'] + url = keystone.service_catalog.get_endpoints( + service_name="neutron", + endpoint_type="public" + )['network'][0]['url'] request = "networks" - r = requests.get("{}/v2.0/{}".format(url,request),headers=headers) + r = requests.get("{}/v2.0/{}".format(url, request), headers=headers) networks = r.json()[request] @@ -102,4 +111,4 @@ def main(args): if __name__ == '__main__': - main(_parse_args()) \ No newline at end of file + main(_parse_args()) diff --git a/get_relation_info.py b/get_relation_info.py index bbbc336..75b21e8 100755 --- a/get_relation_info.py +++ b/get_relation_info.py @@ -6,6 +6,7 @@ from juju.model import Model from juju import jasyncio + async def main(args): unit_name = args.unit_name @@ -34,6 +35,7 @@ async def main(args): finally: await model.disconnect() + async def _check_binding(unit, binding): rel_ids = await _get_rel_ids(unit, binding) @@ -41,7 +43,8 @@ async def _check_binding(unit, binding): for rel in rel_ids: - rel_info = await unit.run('relation-get -r {} - {}'.format(rel, unit.name)) + rel_info = await unit.run('relation-get -r {} - {}'.format( + rel, unit.name)) if 'Stdout' in rel_info.results: print(seperator) print('Relation info for {} - {}\n'.format(unit.name, rel)) @@ -64,7 +67,7 @@ def _parse_args(): parser.add_argument('-u', '--unit', metavar="", help="Unit to run against", dest="unit_name", required=True) - #parser.add_argument('-a', '--application', metavar="", + # parser.add_argument('-a', '--application', metavar="", # help="Application to run against", # dest="app_name") parser.add_argument('-b', '--binding', metavar="", @@ -72,5 +75,6 @@ def _parse_args(): dest="bind_check") return parser.parse_args() + if __name__ == '__main__': jasyncio.run(main(_parse_args()))