[libvirt] [PATCH v2] Allow 10 chars for domain IDs & 30 chars for names in virsh list

From: "Daniel P. Berrange" <berrange@redhat.com> Domain IDs are at least 16 bits for most hypervisors, theoretically event 32-bits. 3 characters is clearly too small an alignment. Increase alignment to 10 characters to allow 32-bit domain IDs to display cleanly. Commonly seen with LXC where domain IDs are the process IDs by default. Also increase the 'name' field from 20 to 30 characters to cope with longer guest names which are quite common In v2: - Increase size to 10 chars - Left align ID values - Also increase name field to 30 - Increase number of '-' to compensate --- tools/virsh.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index f4c0063..9da906e 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -944,8 +944,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) qsort(&names[0], maxname, sizeof(char*), namesorter); } } - vshPrintExtra(ctl, "%3s %-20s %s\n", _("Id"), _("Name"), _("State")); - vshPrintExtra(ctl, "----------------------------------\n"); + vshPrintExtra(ctl, " %-10s %-30s %s\n", _("Id"), _("Name"), _("State")); + vshPrintExtra(ctl, "----------------------------------------------------\n"); for (i = 0; i < maxid; i++) { virDomainPtr dom = virDomainLookupByID(ctl->conn, ids[i]); @@ -954,7 +954,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) if (!dom) continue; - vshPrint(ctl, "%3d %-20s %s\n", + vshPrint(ctl, " %-10d %-30s %s\n", virDomainGetID(dom), virDomainGetName(dom), _(vshDomainStateToString(vshDomainState(ctl, dom, NULL)))); @@ -974,7 +974,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) virDomainHasManagedSaveImage(dom, 0) > 0) state = -2; - vshPrint(ctl, "%3s %-20s %s\n", + vshPrint(ctl, " %-10s %-30s %s\n", "-", names[i], state == -2 ? _("saved") : _(vshDomainStateToString(state))); -- 1.7.7.5

From: "Daniel P. Berrange"<berrange@redhat.com>
Domain IDs are at least 16 bits for most hypervisors, theoretically event 32-bits. 3 characters is clearly too small an alignment. Increase alignment to 10 characters to allow 32-bit domain IDs to display cleanly. Commonly seen with LXC where domain IDs are the process IDs by default. Also increase the 'name' field from 20 to 30 characters to cope with longer guest names which are quite common
In v2:
- Increase size to 10 chars - Left align ID values - Also increase name field to 30 - Increase number of '-' to compensate
--- I think that 10 characters is a lot of space wasted in most of cases :/. What about calculating the alignment dynamicaly? I'm adding code to the
On 01/12/2012 01:19 PM, Daniel P. Berrange wrote: list command, so I could add that as a part of my patch. Peter

On 01/12/2012 05:49 AM, Peter Krempa wrote:
From: "Daniel P. Berrange"<berrange@redhat.com>
Domain IDs are at least 16 bits for most hypervisors, theoretically event 32-bits. 3 characters is clearly too small an alignment. Increase alignment to 10 characters to allow 32-bit domain IDs to display cleanly. Commonly seen with LXC where domain IDs are the process IDs by default. Also increase the 'name' field from 20 to 30 characters to cope with longer guest names which are quite common
In v2:
- Increase size to 10 chars - Left align ID values - Also increase name field to 30 - Increase number of '-' to compensate
--- I think that 10 characters is a lot of space wasted in most of cases :/. What about calculating the alignment dynamicaly? I'm adding code to the
On 01/12/2012 01:19 PM, Daniel P. Berrange wrote: list command, so I could add that as a part of my patch.
A generic helper function for dynamically sizing columns would indeed be nice, but I think that can be a follow up. It would require callers to allocate a char*** - an array rows to be formatted, where each row is represented by an array of columns. I'm okay with Daniel's patch going in now, as it is a strict improvement, even if we make further improvements down the road. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Jan 12, 2012 at 08:20:02AM -0700, Eric Blake wrote:
On 01/12/2012 05:49 AM, Peter Krempa wrote:
From: "Daniel P. Berrange"<berrange@redhat.com>
Domain IDs are at least 16 bits for most hypervisors, theoretically event 32-bits. 3 characters is clearly too small an alignment. Increase alignment to 10 characters to allow 32-bit domain IDs to display cleanly. Commonly seen with LXC where domain IDs are the process IDs by default. Also increase the 'name' field from 20 to 30 characters to cope with longer guest names which are quite common
In v2:
- Increase size to 10 chars - Left align ID values - Also increase name field to 30 - Increase number of '-' to compensate
--- I think that 10 characters is a lot of space wasted in most of cases :/. What about calculating the alignment dynamicaly? I'm adding code to the
On 01/12/2012 01:19 PM, Daniel P. Berrange wrote: list command, so I could add that as a part of my patch.
A generic helper function for dynamically sizing columns would indeed be nice, but I think that can be a follow up. It would require callers to allocate a char*** - an array rows to be formatted, where each row is represented by an array of columns.
I'm okay with Daniel's patch going in now, as it is a strict improvement, even if we make further improvements down the road.
I will reduce the 'id' column back down to '5' for now, since there is not an immediate critical need to cope with the full 32bits. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Peter Krempa