Skip to content

Instantly share code, notes, and snippets.

@jrwren
Forked from mitechie/check-juju-version.py
Last active May 25, 2017 17:22
Show Gist options
  • Save jrwren/4af3c71fd1b7e6d5f15802ed9f6a5cca to your computer and use it in GitHub Desktop.
Save jrwren/4af3c71fd1b7e6d5f15802ed9f6a5cca to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
## This will loop through your controllers and output the model
## version for each model on each controller in your system.
import json
from subprocess import (
PIPE,
run,
)
status_cmd = "juju status -m {}:{} --format=json"
res = run(['juju controllers --format=json'], shell=True, check=True,
stdout=PIPE)
if res:
controllers_json = res.stdout.decode()
else:
print("juju controllers --format=json failed.")
sys.exit(1)
controllers = json.loads(controllers_json)
for controller in controllers['controllers']:
print("Controller: {}".format(controller))
res = run(['juju models -c {} --format=json'.format(controller)],
shell=True, check=True, stdout=PIPE)
if res:
models_json = res.stdout.decode()
else:
print("juju models for the controller failed.")
sys.exit(1)
models = json.loads(models_json)
for model in models['models']:
if 'external' in model['owner']:
model_name = "{}/{}".format(model['owner'], model['name'])
else:
model_name = model['name']
res = run([status_cmd.format(controller, model_name)],
shell=True, check=True, stdout=PIPE)
if res:
status_json = json.loads(res.stdout.decode())
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