MAAS tags (snap/2.7/CLI)

2.7 2.8 2.9
Snap CLI ~ UI CLI ~ UI CLI ~ UI
Packages CLI ~ UI CLI ~ UI CLI ~ UI

Tags are a convenient way to assign descriptive words to machines, interfaces, and storage devices. Using MAAS tags, you can easily select machines that meet certain criteria, helping you to remember that you’ve defined or reserved certain machines for certain functions.

Tag names can include any combination of letters, numbers, dashes (-) and underscores (_), and be a maximum of 256 characters in length.

Nine questions you may have:

  1. How do I get started with the MAAS CLI?
  2. How do I create tags?
  3. How do I do tag creation and auto-assignment?
  4. How do I delete a tag?
  5. How do I list all tags?
  6. How do I list nodes/machines labelled with a tag?
  7. How do I handle Juju integration?
  8. How do I effect manual tag assignment?
  9. How do I effect hybrid tag assignment?

Tag creation

maas $PROFILE tags create name=$TAG_NAME

Tag creation and auto-assignment

When you supply a definition during a tag’s creation, MAAS automatically applies the tag o all the nodes that satisfy the definition:

maas $PROFILE tags create name=$TAG_NAME \
    comment='$TAG_COMMENT' definition='$TAG_DEFINITION'

For example,

maas $PROFILE tags create name='gpu' \
    comment='GPU with clock speed >1GHz for running CUDA type operations.' \
    definition='//node[@id="display"]/'clock units="Hz"' > 1000000000'

We recommend that each tag have a short name and a comment that adequately describes it. You should make sure to create both of these because they will help you identify and use the tag later.

maas $PROFILE interface add-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

To delete a tag from a network interface:

maas $PROFILE interface remove-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

<a href="#heading–tags-for-network-interfaces

It’s also possible to assign tags to specific network interfaces. You can use these tags when searching for machines within the web UI and when allocating machines from the API.

Network interface tags can only be assigned when a machine is in either a ‘Ready’ or a ‘Broken’ state.

To add a tag to a network interface, use the following command:

maas $PROFILE interface add-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

To delete a tag from a network interface:

maas $PROFILE interface remove-tag $SYSTEM_ID $INTERFACE_ID tag=$TAG_STRING

Delete a tag

maas $PROFILE tag delete $TAG_NAME

List all tags

To list all tags present on the region controller:

maas $PROFILE tags read

List nodes/machines labelled with a tag

To list what nodes (or machines) a tag applies to:

maas $PROFILE tag nodes $TAG_NAME
maas $PROFILE tag machines $TAG_NAME

Juju integration

Although you can use a tag in the web UI (as a node search filter), you realise most of the benefit when you’re deploying applications with Juju.

For example, to use the ‘gpu’ tag to deploy a (hypothetical) service called ‘cuda’:

juju deploy --constraints tags=gpu cuda

You can also use multiple tags in addition to the normal Juju constraints:

juju deploy --constraints "mem=1024 tags=gpu,intel" cuda

Manual tag assignment

It is possible to assign tags to nodes manually by simply omitting the definition and applying the tag to a node by referencing its system id:

maas $PROFILE tags create name=$TAG_NAME comment='$TAG_COMMENT'
maas $PROFILE tag update-nodes $TAG_NAME add=$SYSTEM_ID

To remove a tag:

maas $PROFILE tag update-nodes $TAG_NAME remove=$SYSTEM_ID

In the same operation, a tag can be added to some nodes and removed from others:

maas $PROFILE tag update-nodes $TAG_NAME \
    add=$SYSTEM_ID_1 add=$SYSTEM_ID_2 remove=$SYSTEM_ID_3

Hybrid tag assignment

You can also create a tag with a definition (thereby map to certain nodes), remove the definition (but retain the mapping), and then add the tag manually to specific nodes. This action is useful for hardware which is conceptually similar but does not all satisfy a single tag definition. Here are the commands you would use to do this:

maas $PROFILE tags create name=$TAG_NAME \
    comment='$TAG_COMMENT' definition='$TAG_DEFINITION'
maas $PROFILE tag update $TAG_NAME definition=''
maas $PROFILE tag update-nodes $TAG_NAME add=$SYSTEM_ID