How do I use LXC container comments - or Adding a couple USER Defined fields to LXC List

I am getting pretty good at Greping Lxc list. and coming up with container names.
But My life managing hundred of containers would be so wonderful if I could have just two extra fields in information held with container that I could change. One I would use container staging-versioning and other for last backup date. We use our own programs for this and would otherwise create a separate database to hold this info, and then I could not sort in lxc so easily.

I can see comments here:
lxc list -c ns,user.comment:comment

But no idea how to add them or if there are more of these fields.\

Thanks

It’s not possible to add keys using
lxc config <instance> user.comment="blah"
but you can do it by editing the yaml (lxc config edit instance). Curiously unsetting the key works. Maybe this feature has been thought only for inheriting keys from templates. Or this strange limitation is a good’ole bug. Anyway, you can create any number of user.xxx keys you want.

lxc config edit trusty

config:
  image.architecture: amd64
  image.description: Ubuntu trusty amd64 (20200117_07:42)
  image.os: Ubuntu
  image.release: trusty
  image.serial: "20200117_07:42"
  image.type: squashfs
  user.comment: this is my awesome comment.
  user.orientation: south
  user.speed: fast

lxc list -c ns,user.comment:comment,user.orientation:orientation,user.speed:speed | grep trusty

| trusty | RUNNING | this is my awesome comment. | south | fast |

Hi!

You may consider using a different lxc list output (than table), such as yaml or json.
With yaml, you can get the full list of information available from the container.

lxc list --format yaml

Alternatively, you can install jq, with either one of the two,

sudo apt get install jq

or

sudo snap install jq

and then run

lxc list --format=json | jq .

This jq . will pretty-print, with colors and all, the output. You can then process the JSON data with jq, per Redirecting to jqlang.github.io.

It looks like a feature.

$ lxc config set local:vm4 user.comment="My VM"
Error: cannot set 'local:vm4' to 'user.comment=My VM': unknown key
$ lxc config set local:vm4 user.comment "My VM"
$ 

That is, if you use the old style of setting keys (without the = sign), it works.

Wrote an issue at https://github.com/lxc/lxd/issues/6754

Thanks, I do use jason pretty print for some things. The comment feature is not very well know or used.
I am going to be using it a lot to document the date last backup and purpose of container, and possibly client.

1 Like

Hi. I am late to the party, but I only just saw this and I am doing something similar: Using lxc version 5.0 (stable), it is very possible to set the comment field of a config file from the command line. Example:

Andrew@solo:~$ lxc launch ubuntu:22.04 c1
Creating c1
Starting c1
andrew@solo:~$ lxc config set c1 user.comment=“Happy Holidays to SysAdmins”
andrew@solo:~$ lxc config show c1 #Note, I bold-emphasized the comment line below.
architecture: x86_64
config:
image.architecture: amd64
image.description: ubuntu 22.04 LTS amd64 (release) (20221201)
image.label: release
image.os: ubuntu
image.release: jammy
image.serial: “20221201”
image.type: squashfs
image.version: “22.04”
user.comment: Happy Holidays to SysAdmins
volatile.base_image: 550d2866fa21dc07b5c7a0373e2cdb8ef4f8797cf0821f0a0ae39784751a3cd4
volatile.cloud-init.instance-id: d9405634-8855-4cfd-b62b-e09a1c49299b
volatile.eth0.host_name: vethfb1f523e
volatile.eth0.hwaddr: 00:16:3e:f0:9f:0e
volatile.idmap.base: “0”
volatile.idmap.current: ‘[{“Isuid”:true,“Isgid”:false,“Hostid”:1000000,“Nsid”:0,“Maprange”:1000000000},{“Isuid”:false,“Isgid”:true,“Hostid”:1000000,“Nsid”:0,“Maprange”:1000000000}]’
volatile.idmap.next: ‘[{“Isuid”:true,“Isgid”:false,“Hostid”:1000000,“Nsid”:0,“Maprange”:1000000000},{“Isuid”:false,“Isgid”:true,“Hostid”:1000000,“Nsid”:0,“Maprange”:1000000000}]’
volatile.last_state.idmap: ‘[{“Isuid”:true,“Isgid”:false,“Hostid”:1000000,“Nsid”:0,“Maprange”:1000000000},{“Isuid”:false,“Isgid”:true,“Hostid”:1000000,“Nsid”:0,“Maprange”:1000000000}]’
volatile.last_state.power: RUNNING
volatile.uuid: d5b0ae35-bae2-485a-8d62-925d7a8dad95
devices: {}
ephemeral: false
profiles:

  • default
    stateful: false
    description: “”
    andrew@solo:~$

#Hopefully Tony_Anytime you can use this for your filtering needs for backups and such?

1 Like

linux-vservers had a feature to set something like “tags” on instances. I found this very helpful for integrating with host tooling to do things like:

  • Stop all containers of type “test” and “www”
  • restart all containers of type “mail”
  • start all “start at boot” containers

Multiple tags can be added to each container, so this is helpful because some types of service might match several profiles. eg a web front end to git might match your “www” machines and your “git” profiles

Would be nice to see something like this added to the tooling? (Ideally with support for using it for filtering within start/stop/exec etc). See the “vsomething” command for how this worked on the original

1 Like