Last active
May 25, 2017 18:52
-
-
Save mitechie/3076bd165611c5afea7f06ebea534280 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ignore that; I ran it via python rather than just executing, missed the py3 req.