How to use storage tags (snap/3.0/CLI)

2.9 3.0 3.1
DEB CLI ~ UI CLI ~ UI CLI ~ UI
SNAP CLI ~ UI CLI ~ UI CLI ~ UI

This article explains:

How to discover the ID of your block device

Block devices do not exist apart from the physical or virtual machines to which they are attached. Finding the ID of the block device that interests you requires starting with a particular machine, in a command form that looks like this:

maas $PROFILE block-devices read $SYSTEM_ID \
| jq -r '(["system_id","block_device_id","path","avail_size"]
|(.,map(length*"-"))),(.[]|[.system_id,.id,.path,.available_size])
| @tsv' | column -t

For example:

maas admin block-devices read qk4b3g \
| jq -r '(["system_id","block_device_id","path","avail_size"]
|(.,map(length*"-"))),(.[]|[.system_id,.id,.path,.available_size])
| @tsv' | column -t

This example would produce output that looks something like this:

system_id  block_device_id  path                    avail_size
---------  ---------------  ----                    ----------
qk4b3g     10               /dev/disk/by-dname/sda  0

The path component is printed to help you confirm that you are choosing the right block device, when there are several present. The avail-size column will tell you whether you can operate on that block device at all: If the available size is “0,” for example, you can’t set a block device tag on any part of that drive. Instead, you’d want to see something like this:

system_id  block_device_id  path                    avail_size
---------  ---------------  ----                    ----------
xn8taa     8                /dev/disk/by-dname/sda  1996488704

How to assign tags to a block device

You can only assign tags to a block device that is available. You can find out whether the block device is available at all when you discover its ID.

To assign an existing tag to a block device, you would type a command formulated like this:

maas $PROFILE block-device add-tag $SYSTEM_ID $BLOCK_DEVICE_ID tag=$TAG_NAME

If you’re not sure about the ID of your block device, you can look it up.

For example:

maas admin block-device add-tag xn8taa 8 tag=farquar

If this command succeeds, it will display Success, followed by a JSON sequence describing the new state of the block device.

Note that if you try to add a tag to a block device that is not available, that is, to a block device that is in use, you will get a result like this:

Not Found

How to remove tags from a block device

You can only remove tags from a block device that is available. You can find out whether the block device is available at all when you discover its ID.

To remove an assigned tag from a block device, you would type a command formulated like this:

maas $PROFILE block-device remove-tag $SYSTEM_ID $BLOCK_DEVICE_ID tag=$TAG_NAME

If you’re not sure about the ID of your block device, you can look it up.

For example:

maas admin block-device remove-tag xn8taa 8 tag=farquar

If this command succeeds, it will display Success, followed by a JSON sequence describing the new state of the block device.

Note that if you try to remove a tag from a block device that is not available, that is, from a block device that is in use, you will get a result like this:

Not Found

How to list tags for all block devices

To list tags for all block devices associated with a physical or virtual machine, you can use a command of this form:

maas $PROFILE block-devices read $SYSTEM_ID | jq -r '(["id","tags"]|(.,map(length*"-"))),(.[]|[.id,.tags[]]) | @tsv' | column -t

For example:

maas admin block-devices read xn8taa | jq -r '(["id","tags"]|(.,map(length*"-"))),(.[]|[.id,.tags[]]) | @tsv' | column -t

This command would produce output similar to this:

id  tags
--  ----
8   hello  ssd  trinkoplinko

How to view tags for one block device

To view tags for one specific block device, you can enter a command like this:

maas $PROFILE block-device read $SYSTEM_ID $BLOCK_DEVICE_ID | jq -r '(["id","tags"]|(.,map(length*"-"))),([.id,.tags[]]) | @tsv' | column -t

If you’re not sure about the ID of your block device, you can look it up.

For example:

maas admin block-device read xn8taa 8 | jq -r '(["id","tags"]|(.,map(length*"-"))),([.id,.tags[]]) | @tsv' | column -t

This command would produce output similar to this:

id  tags
--  ----
8   hello  ssd  trinkoplinko
9   20gig  ssd
10  250Gs  ssd

How to discover the ID of your partition

Partitions do not exist apart from the block devices on which they reside. Finding the ID of the partition that interests you requires starting with a particular machine and block device, similar to this command:

maas $PROFILE partitions read $SYSTEM_ID $BLOCK_DEVICE_ID \
| jq -r '(["system_id","block_dev_id","part_id","path"]
|(.,map(length*"-"))),(.[]|[.system_id,.device_id,.id,.path])
|@tsv' | column -t

For example:

maas admin partitions read xn8taa 8 \
| jq -r '(["system_id","block_dev_id","part_id","path"]
|(.,map(length*"-"))),(.[]|[.system_id,.device_id,.id,.path])
|@tsv' | column -t

This example would produce output that looks something like this:

system_id  block_dev_id  part_id  path
---------  ------------  -------  ----
xn8taa     8             67       /dev/disk/by-dname/sda-part1

The path component is printed to help you confirm that you are choosing the right partition, when there are several present.

How to assign tags to a partition

You can only assign tags to a partition that is available. To assign an existing tag to a partition, you would type a command formulated like this:

maas $PROFILE partition add-tag $SYSTEM_ID $BLOCK_DEVICE_ID $PARTITION_ID tag=$TAG_NAME

If you’re not sure about the ID of your partition, you can look it up.

For example:

maas admin partition add-tag xn8taa 8 67 tag=farquar

If this command succeeds, it will display Success, followed by a JSON sequence describing the new state of the partition.

Note that if you try to add a tag to a partition that is not available, that is, to a partition that is in use, you will get a result like this:

Not Found

How to remove tags from a partition

You can only remove tags from a partition that is available. To remove a existing tag from a partition, you would type a command formulated like this:

maas $PROFILE partition remove-tag $SYSTEM_ID $BLOCK_DEVICE_ID $PARTITION_ID tag=$TAG_NAME

If you’re not sure about the ID of your partition, you can look it up.

For example:

maas admin partition remove-tag xn8taa 8 67 tag=farquar

If this command succeeds, it will display Success, followed by a JSON sequence describing the new state of the partition.

Note that if you try to remove a tag from a partition that is not available, that is, from a partition that is in use, you will get a result like this:

Not Found

On the other hand, if you try to remove a tag that is not assigned to the partition you’ve chosen, MAAS will simply return Success, followed by a JSON sequence describing the current state of the partition.

How to list tags for all partitions

To list tags for all partitions of a particular block device, use a command like this one:

maas $PROFILE partitions read $SYSTEM_ID $BLOCK_DEVICE_ID \
| jq -r '(["id","tags"]
|(.,map(length*"-"))),(.[]|[.id,.tags[]])
| @tsv' | column -t

For example:

maas admin partitions read xn8taa 8 \
| jq -r '(["id","tags"]
|(.,map(length*"-"))),(.[]|[.id,.tags[]])
| @tsv' | column -t

A command like this should return output similar to the following:

id  tags
--  ----
54  farquar swap opendisk
67  foobar  farquar
97  foobar

How to view tags for one partition

To view tags for one partition, enter a command similar to this:

maas $PROFILE partition read $SYSTEM_ID $BLOCK_DEVICE_ID $PARTITION_ID | jq -r '(["id","tags"]|(.,map(length*"-"))),([.id,.tags[]]) | @tsv' | column -t

If you’re not sure about the ID of your partition, you can look it up.

For example:

maas admin partition read xn8taa 8 67 | jq -r '(["id","tags"]|(.,map(length*"-"))),([.id,.tags[]]) | @tsv' | column -t

This command should produce output similar to this:

id  tags
--  ----
67  foobar  farquar

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.