Default `lxc list` output can be very wide - a few possible improvement ideas?

Just an observation - not sure if many people find this a niggle, but I often have IPv6 privacy addresses configured on containers, and these end up generating very wide output with the default lxd list formatting: e.g. to give the first line of output on the host I’m currently administering:

+------------------+---------+------------------------+-----------------------------------------------+-----------+-----------+
|       NAME       |  STATE  |          IPV4          |                      IPV6                     |   TYPE    | SNAPSHOTS |
+------------------+---------+------------------------+-----------------------------------------------+-----------+-----------+
| apt-proxy        | RUNNING | 192.168.145.182 (eth1) | 2a12:17a1:1:a421:6ad0:b231:abc3:df7f (ethPub) | CONTAINER | 0         |
+------------------+---------+------------------------+-----------------------------------------------+-----------+-----------+

I had a few ideas that might be useful to shrink the output…

I was wondering if it might be better to default to combining IPv4 and IPv6 addresses into a single column (e.g. by adding another column key which combines both):

+------------------+---------+-----------------------------------------------+-----------+-----------+
|       NAME       |  STATE  |                       IP                      |   TYPE    | SNAPSHOTS |
+------------------+---------+-----------------------------------------------+-----------+-----------+
| apt-proxy        | RUNNING | 192.168.145.182 (eth1)                        | CONTAINER | 0         |
|                  |         | 2a12:17a1:1:a421:6ad0:b231:abc3:df7f (ethPub) |           |           |
+------------------+---------+-----------------------------------------------+-----------+-----------+

Looking at other possible easy wins to reduce the width, perhaps the column heading for SNAPSHOTS could be smaller in the default (lxd list without custom format options) output, e.g.:

+------------------+---------+-----------------------------------------------+-----------+-------+
|       NAME       |  STATE  |                       IP                      |   TYPE    | SNAPS |
+------------------+---------+-----------------------------------------------+-----------+-------+
| apt-proxy        | RUNNING | 192.168.145.182 (eth1)                        | CONTAINER | 0     |
|                  |         | 2a12:17a1:1:a421:6ad0:b231:abc3:df7f (ethPub) |           |       |
+------------------+---------+-----------------------------------------------+-----------+-------+

Or perhaps the column could be omitted entirely if all containers have 0 snapshots:

+------------------+---------+-----------------------------------------------+-----------+
|       NAME       |  STATE  |                       IP                      |   TYPE    | 
+------------------+---------+-----------------------------------------------+-----------+
| apt-proxy        | RUNNING | 192.168.145.182 (eth1)                        | CONTAINER | 
|                  |         | 2a12:17a1:1:a421:6ad0:b231:abc3:df7f (ethPub) |           |       
+------------------+---------+-----------------------------------------------+-----------+

Similarly perhaps TYPE could be automatically omitted if all containers are of the same type (e.g. if all are containers):

+------------------+---------+-----------------------------------------------+
|       NAME       |  STATE  |                       IP                      |   
+------------------+---------+-----------------------------------------------+
| apt-proxy        | RUNNING | 192.168.145.182 (eth1)                        | 
|                  |         | 2a12:17a1:1:a421:6ad0:b231:abc3:df7f (ethPub) |           
+------------------+---------+-----------------------------------------------+

… the last example is 78 characters wide - which is a 38% width saving over the current output.

Perhaps some of this combining or hiding of columns could also be made automatic based on terminal width?

A lot of people rely on parsing this output unfortunately so we’ve usually been refraining from changing its default output.

There are however a lot of optional columns (lxc list --help) and you can customize the output using lxc list -c ns (or whatever flag) and even persist it locally with lxc alias add list "list -c ns"

Yeah, I saw that, but it would be nice of the default output was a bit more friendly.

Would a possibility be to check if stdout isatty() and revert to the “traditional” output if it isn’t?

Otherwise maybe a compat setting, or variable could have the same effect.

Using a tty check tends to be extremely confusing to users as they would run lxc list, look at what’s in there, then pipe it to grep or something and it suddenly wouldn’t work because the output is now different.

1 Like

Good point . But there may be a middle ground, like a --human/-H flag or setting which explicitly does not guarantee the current output formatting, and would allow some of the suggested tweaks. That setting could print a warning to stderr if output is not a tty.

Another option might be to do a tty check, and then add a stderr warning like the following if stdout is not a tty:

Warning the default format of "lxc list" may change after release X.Y. Consider modifying scripts to use the "--compatibility", or "--format" flags.

This is the policy adopted by apt, which prints such a stderr warning:

tim@custard:~$ apt list > /dev/null        

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

This would allow the default to change, and improve the experience of most users, whilst minimising breakage for those that have scripted the default lxc list output.