#!/usr/bin/env python ### Loops through your controllers and outputs the model version for each ### model on each controller. ### JAAS NOTE: if you're not actively logged into JAAS the script will fail ### until you auth. Rerun after authenticating and it should work on the ### second go. import json from subprocess import check_output import sys status_cmd = "juju status -m {}:{} --format=json" res = check_output(['juju controllers --format=json'], shell=True) if res: controllers_json = res else: print("juju controllers --format=json failed.") sys.exit(1) controllers = json.loads(res.decode('utf-8')) for controller in controllers['controllers']: print("Controller: {}".format(controller)) res = check_output(['juju models -c {} --format=json'.format(controller)], shell=True) if res: models_json = res else: print("juju models for the controller failed.") sys.exit(1) models = json.loads(models_json.decode('utf-8')) for model in models['models']: if 'external' in model['owner']: model_name = "{}/{}".format(model['owner'], model['name']) else: model_name = model['name'] res = check_output([status_cmd.format(controller, model_name)], shell=True) if res: status_json = json.loads(res.decode('utf-8')) else: print("juju status for the model failed.") sys.exit(1) print(" Model {} - {}".format(model['name'], status_json['model']['version']))