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.\
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 |
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.
$ 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.
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.
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:
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