QUESTION on MAAS CLI

Mike Pontillo mike.pontillo at canonical.com
Fri Jun 16 00:38:47 UTC 2017


On Thu, Jun 15, 2017 at 10:51 AM, Thawngzapum Lian <tlian at salesforce.com>
wrote:

> How to "Add alias or VLAN" to a bond interface?
> It is quite simple using web interface. But having a hard time to do it
> via CLI.
>
> I was looking into
>   maas $PROFILE interface update ***
>   maas $PROFILE interface link-subnet ***
>
> NO success.
>
> Can anyone please give a pointer?
>

Hi Thawngzapum,

   I think I can provide some tips.

   When working with the JSON output from the MAAS CLI, I often use the
'jq' tool to help me make sense of what's important. For example, you could
fetch the list of interface links for a particular machine in a similar way
that the UI presents them by doing the following (where $SYSTEM_ID is the
system_id of your machine):

$ 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":138,"name":"eno1","mac":"0c:c4:7a:00:00:fa","vid":100,"fabric":"fabric-0","links":{"id":1966,"ip":null,"mode":"auto","subnet":"
192.168.100.0/24"}}

    If you have a setup like this, you can add an alias with for a static
IP address by doing something like:

$ maas $PROFILE interface link-subnet $SYSTEM_ID eno1 mode=static subnet=
172.16.100.0/24 ip_address=192.168.100.55 \
    | 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":138,"name":"eno1","mac":"0c:c4:7a:00:00:fa","vid":100,"fabric":"fabric-0","links":{"id":1966,"ip":null,"mode":"auto","subnet":"
192.168.100.0/24"}}
{"id":138,"name":"eno1","mac":"0c:c4:7a:00:00:fa","vid":100,"fabric":"fabric-0","links":{"id":1967,"ip":"192.168.100.55","mode":"auto","subnet":"
192.168.100.0/24"}}

   Note that the new static IP address here will be *in addition* to the
existing automatic IP address on the subnet.

   Creating a VLAN using the API is a little less friendly. You'll need the
unique "id" fields for both the VLAN and the interface. For example, this
would create a VLAN:

$ maas $PROFILE interfaces create-vlan $SYSTEM_ID parent=$INTERFACE_ID
vlan=$VLAN_ID
...

   In the above example, the $INTERFACE_ID would be 138. Keep in mind that
the $VLAN_ID in this example is not the "vid" field; it's the "id" field.
(It would be nice if MAAS accepted the VID here, since we already know the
fabric, if we know the fabric that the parent interface is in.) You could
get a compact listing of fabrics and their VLANs by doing something like
the following:

$ maas $PROFILE fabrics read \
    | jq '.[] | {id:.id, fabric_name:.name, vlans:.vlans[] | {id:.id,
name:.name, vid:.vid}}' --compact-output

   Hope this helps.

Regards,
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/maas-devel/attachments/20170615/45cbf496/attachment.html>


More information about the Maas-devel mailing list