BastilleBSD / bastille

Bastille is an open-source system for automating deployment and management of containerized applications on FreeBSD.
https://bastillebsd.org
BSD 3-Clause "New" or "Revised" License
858 stars 139 forks source link

Fix alignment when listing jails with more than one IP address #691

Open vrachnis opened 8 months ago

vrachnis commented 8 months ago

When a VNET jail has more than IP address configured on its primary interface, invoking bastille list -a will now display all addresses vertically aligned. This is to address a misalignment issue where the fields following the ip addresses were no longer in the same line as the jail name.

For instance:

 JID     State  IP Address       Published Ports  Hostname  Release          Path
 foo     Up     10.10.10.10
10.10.10.11   -                foo              14.0-RELEASE-p5  /usr/local/bastille/jails/foo/root
 hello1  Up     10.10.10.13      -                hello1                 14.0-RELEASE-p5  /usr/local/bastille/jails/hello1/root
 hello   Up     10.10.10.12      -                hello                14.0-RELEASE-p5  /usr/local/bastille/jails/hello/root
 test    Up     10.10.10.14      -                test               14.0-RELEASE-p5  /usr/local/bastille/jails/test/root

With this change, all additional IPs for a given jail are aligned vertically, and the fields following the IP (ports, hostname, release, path) are all in the same line as the jail name:

 JID     State  IP Address       Published Ports  Hostname  Release          Path
 foo     Up     10.10.10.10      -                foo              14.0-RELEASE-p5  /usr/local/bastille/jails/foo/root
                10.10.10.11
 hello1  Up     10.10.10.13      -                hello1                 14.0-RELEASE-p5  /usr/local/bastille/jails/hello1/root
 hello   Up     10.10.10.12      -                hello                14.0-RELEASE-p5  /usr/local/bastille/jails/hello/root
 test    Up     10.10.10.14      -                test               14.0-RELEASE-p5  /usr/local/bastille/jails/test/root

Considerations

Grouping of IPs

Initially I attempted to use line-drawing characters to visualize the fact that all addresses belong to the same jail:

 JID     State  IP Address       Published Ports  Hostname  Release          Path
 foo     Up     ┬ 10.10.10.10    -                foo              14.0-RELEASE-p5  /usr/local/bastille/jails/foo/root
                └ 10.10.10.11
 hello1  Up     10.10.10.13      -                hello1                 14.0-RELEASE-p5  /usr/local/bastille/jails/hello1/root
 hello   Up     10.10.10.12      -                hello                14.0-RELEASE-p5  /usr/local/bastille/jails/hello/root
 test    Up     10.10.10.14      -                test               14.0-RELEASE-p5  /usr/local/bastille/jails/test/root

While the result was making it clear to the user where the extra line comes from, the implementation became unnecessarily complex. More importantly, it meant that if anyone parses the output of bastille list -a in their script, would have to account for the fact that the "primary" IP address would be in either the third or fourth field of the line.

This highlights the fact that with this, the first and second/third/etc addresses will still be on different fields. The first address will be on field number 3, while the following addresses will be on field number 1. I could potentially modify the output to put some dummy characters in the first two columns, although I'm not sure that I like the result. Let me know if something like the following is preferable.

 JID     State  IP Address       Published Ports  Hostname  Release          Path
 foo     Up     10.10.10.10      -                foo              14.0-RELEASE-p5  /usr/local/bastille/jails/foo/root
 └─────  ─────  10.10.10.11
 hello1  Up     10.10.10.13      -                hello1                 14.0-RELEASE-p5  /usr/local/bastille/jails/hello1/root
 hello   Up     10.10.10.12      -                hello                14.0-RELEASE-p5  /usr/local/bastille/jails/hello/root
 test    Up     10.10.10.14      -                test               14.0-RELEASE-p5  /usr/local/bastille/jails/test/root

Dependencies

No new dependencies were introduced.

yaazkal commented 4 months ago

Thanks, I personally prefer the space instead of the extra characters for the first two columns. Now, does this support printing the published ports corresponding to each IP? does this support different hostname per IP?

Regards