Last active
May 7, 2025 13:37
-
-
Save mpontillo/e216dad87b39d4fbe6ee1d8fa2716057 to your computer and use it in GitHub Desktop.
MAAS jq tricks and how to move interfaces between fabrics (via changing the interface's VLAN)
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
maas refresh | |
profile=$(maas list | head -1 | awk '{ print $1 }') | |
# This generates a single JSON object. | |
maas $PROFILE machines read | jq '[.[] | {hostname:.hostname, system_id: .system_id, status:.status}]' | |
... | |
maas $PROFILE machines read | jq '.[] | {hostname:.hostname, system_id: .system_id, status:.status}' --compact-output | |
{"hostname":"pxe-bond1","system_id":"xrey6h","status":4} | |
{"hostname":"pxe-bond2","system_id":"rsx7he","status":0} | |
{"hostname":"pxe-disks1","system_id":"4ppna7","status":4} | |
{"hostname":"pxe-disks2","system_id":"6hfncx","status":22} | |
{"hostname":"pxe-juju","system_id":"7q7p87","status":4} | |
{"hostname":"pxe-vdisks1","system_id":"bn436f","status":6} | |
{"hostname":"pxe-vdisks2","system_id":"abpwnq","status":4} | |
{"hostname":"pxe1","system_id":"$SYSTEM_ID","status":4} | |
{"hostname":"pxe2","system_id":"qmebxg","status":4} | |
{"hostname":"honest-cobra","system_id":"t7daa3","status":0} | |
maas $PROFILE interfaces read $SYSTEM_ID | jq '.[] | {id:.id, name:.name, mac:.mac_address, vid:.vlan.vid, fabric:.vlan.fabric}' --compact-output | |
{"id":23,"name":"ens3","mac":"52:54:00:74:1e:ce","vid":0,"fabric":"fabric-2"} | |
{"id":37,"name":"eth0","mac":"44:55:66:77:88:99","vid":0,"fabric":"fabric-2"} | |
{"id":39,"name":"eth1","mac":"00:11:22:33:44:55","vid":0,"fabric":"fabric-0"} | |
maas $PROFILE fabrics read | jq '[.[] | {name:.name, vlans:.vlans[] | {id:.id, vid:.vid}}]' | |
... | |
$ maas $PROFILE fabrics read | jq '.[] | {name:.name, vlans:.vlans[] | {id:.id, vid:.vid}}' --compact-output | |
{"name":"fabric-0","vlans":{"id":5001,"vid":0}} | |
{"name":"fabric-2","vlans":{"id":5003,"vid":0}} | |
maas $PROFILE interface update $SYSTEM_ID 37 vlan=5001 | |
Success. | |
Machine-readable output follows: | |
... | |
$ maas $PROFILE interfaces read $SYSTEM_ID | jq '.[] | {id:.id, name:.name, mac:.mac_address, vid:.vlan.vid, fabric:.vlan.fabric}' --compact-output | |
{"id":23,"name":"ens3","mac":"52:54:00:74:1e:ce","vid":0,"fabric":"fabric-2"} | |
{"id":37,"name":"eth0","mac":"44:55:66:77:88:99","vid":0,"fabric":"fabric-0"} | |
{"id":39,"name":"eth1","mac":"00:11:22:33:44:55","vid":0,"fabric":"fabric-0"} | |
# Interfaces with their subnet links | |
maas $PROFILE interfaces read $SYSTEM_ID | jq '.[] | {id:.id, name:.name, mac:.mac_address, vid:.vlan.vid, fabric:.vlan.fabric, links:.links[] |{id: .id, ip:.ip_address, mode:.mode, subnet:.subnet.cidr}}' --compact-output | |
{"id":23,"name":"ens3","mac":"52:54:00:74:1e:ce","vid":0,"fabric":"fabric-2","links":{"id":2035,"ip":null,"mode":"auto","subnet":"172.16.99.0/24"}} | |
{"id":37,"name":"eth0","mac":"00:01:02:03:04:05","vid":0,"fabric":"fabric-2","links":{"id":2386,"ip":null,"mode":"link_up","subnet":"172.16.99.0/24"}} | |
{"id":44,"name":"eth1","mac":"11:22:33:44:55:66","vid":0,"fabric":"fabric-0","links":{"id":2387,"ip":null,"mode":"link_up","subnet":null}} | |
# Interfaces with parents | |
maas $PROFILE interfaces read $SYSTEM_ID | jq -c '.[] | {name:.name, parents:.parents, mac:.mac_address}' | |
# List machines having a particular tag. | |
maas admin tag machines nuc | jq -c '.[] | {hostname:.hostname, system_id:.system_id}' | |
# List VLANs with their fabrics. | |
maas $PROFILE fabrics read | jq '.[] | {id:.id, fabric_name:.name, vlans:.vlans[] | {id:.id, name:.name, vid:.vid}}' --compact-output | |
{"id":1,"fabric_name":"fabric-1","vlans":{"id":5002,"name":"untagged","vid":0}} | |
{"id":4,"fabric_name":"fabric-4","vlans":{"id":5008,"name":"untagged","vid":0}} | |
{"id":0,"fabric_name":"default","vlans":{"id":5003,"name":"104","vid":104}} | |
{"id":0,"fabric_name":"default","vlans":{"id":5005,"name":"106","vid":106}} | |
{"id":0,"fabric_name":"default","vlans":{"id":5004,"name":"","vid":100}} | |
{"id":0,"fabric_name":"default","vlans":{"id":5001,"name":"untagged","vid":0}} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment