Skip to content

Instantly share code, notes, and snippets.

@smoser smoser/
Last active Nov 28, 2018

What would you like to do?
maas dump image status: this is a very basic maas client that shows what images a maas has. Possibly useful as a start for other single purpose clients or a generic one.


This is a simple python client that shows succinct information on boot resources that you have available in your maas.

It uses the same login credenitals that the maas cli uses, and depends on that being set up.

The data output is is space delimited os/release, arch/subarch, build_serial, label, synced.


$ maas list
admin ABCDEFG:abcdefg:12345afjd

$ ./maas-dump-image-status admin
$ maas-dump-image-status home-smoser
centos/centos66 amd64/generic 20141129_01 daily True
centos/centos70 amd64/generic 20141129_01 daily True
ubuntu/precise amd64/hwe-p 20160201 daily True
ubuntu/precise amd64/hwe-q 20160201 daily True
ubuntu/precise amd64/hwe-r 20160201 daily True
ubuntu/precise amd64/hwe-s 20160201 daily True
ubuntu/precise amd64/hwe-t 20160201 daily True
ubuntu/trusty amd64/hwe-t 20160209 daily True
ubuntu/trusty amd64/hwe-u 20160209 daily True
ubuntu/trusty amd64/hwe-v 20160209 daily True
ubuntu/trusty amd64/hwe-w 20160209 daily True
ubuntu/wily amd64/hwe-w 20160204 daily True
ubuntu/xenial amd64/hwe-w 20160211 daily True

Other way to get this data

This information can be obtained with the maas cli, it is just more painful to do so.

$ maas home-smoser boot-resources read > resources.json
$ ruris=$(python -c 'import json, sys; 
print(" ".join([r["resource_uri"].split("/")[-2] for r in json.load(sys.stdin)]))' < resources.json)
$ echo $ruris
18 17 32 33 34 35 31 28 29 26 27 37 30 36 38
$ maas home-smoser boot-resource read 18
    "name": "centos/centos66", 
    "subarches": "generic", 
    "architecture": "amd64/generic", 
    "sets": {
        "20160801_01": {
            "files": {
                "root-tgz": {
                    "filename": "root-tgz", 
                    "filetype": "root-tgz", 
                    "sha256": "286b0740fc244d5eb85b55c1349e6d4603d292a6c9a1be036b77ed289c8ab35b", 
                    "complete": true, 
                    "size": 248031463
            "label": "daily", 
            "version": "20160801_01", 
            "complete": true, 
            "size": 248031463
    "type": "Synced", 
    "id": 18, 
    "resource_uri": "/MAAS/api/1.0/boot-resources/18/"
# based on answer
# no python3 libs filed
import argparse
import json
import sys
from urllib.parse import urlparse
from maascli.config import ProfileConfig
from apiclient import maas_client
def load_maascli_info(name):
with as config:
for profile_name in config:
profile = config[profile_name]
if profile_name == name:
return (name, profile["url"], profile["credentials"])
raise KeyError(name)
class Client(object):
def __init__(self, name, url, creds): = name
self.url = url
self.creds = creds
auth = maas_client.MAASOAuth(*creds)
self.client = maas_client.MAASClient(
auth, maas_client.MAASDispatcher(), url)
self.path = urlparse(self.url).path
def __repr__(self):
return "Client(name=%s, url=%s, creds=...)" % (, self.url)
def get(self, path):
if isinstance(path, bytes):
path = path.decode('utf-8')
if path.startswith(self.path):
path = path[len(self.path):]
return json.loads(self.client.get(path).read().decode())
def main():
parser = argparse.ArgumentParser(
description="dump information about boot resources in maas")
parser.add_argument('maasname', help='maas to connect to (from maas list)')
args = parser.parse_args()
name, url, creds = load_maascli_info(args.maasname)
client = Client(name, url, creds)
except KeyError as e:
"'%s' is not a valid maas client name. see 'maas list'\n" %
boot_resources = client.get("boot-resources/")
for resource in boot_resources:
data = client.get(resource['resource_uri'])
for s in data['sets'].values():
print("%s %s %s %s %s" % (
data['name'], data['architecture'],
s['version'], s['label'], s['complete']))
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.