[libvirt] [PATCH 5/5] virsh: allow to print hostname in domain listings
Peter Krempa
pkrempa at redhat.com
Tue Jul 10 21:06:01 UTC 2012
On 07/10/12 22:46, Guido Günther wrote:
> ---
> tools/virsh.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 591a1ce..2c0446c 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -1292,6 +1292,7 @@ static const vshCmdOptDef opts_list[] = {
> {"managed-save", VSH_OT_BOOL, 0,
> N_("mark inactive domains with managed save state")},
> {"title", VSH_OT_BOOL, 0, N_("show short domain description")},
> + {"hostname", VSH_OT_BOOL, 0, N_("show domain hostname")},
> {NULL, 0, 0, NULL}
> };
>
> @@ -1307,8 +1308,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> bool optTable = vshCommandOptBool(cmd, "table");
> bool optUUID = vshCommandOptBool(cmd, "uuid");
> bool optName = vshCommandOptBool(cmd, "name");
> + bool optHostname = vshCommandOptBool(cmd, "hostname");
> int i;
> - char *title;
> + char *title, *hostname;
> char uuid[VIR_UUID_STRING_BUFLEN];
> int state;
> bool ret = false;
> @@ -1366,6 +1368,11 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> _("Id"), _("Name"), _("State"), _("Title"),
> "-----------------------------------------"
> "-----------------------------------------");
> + else if (optHostname)
> + vshPrintExtra(ctl, " %-5s %-30s %-10s %-20s\n%s\n",
> + _("Id"), _("Name"), _("State"), _("Hostname"),
> + "-----------------------------------------"
> + "-----------------------------------------");
> else
> vshPrintExtra(ctl, " %-5s %-30s %s\n%s\n",
> _("Id"), _("Name"), _("State"),
> @@ -1397,6 +1404,15 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
> title);
>
> VIR_FREE(title);
> + } else if (optHostname) {
> + if (!(hostname = virDomainGetHostname (dom, 0)))
> + goto cleanup;
> +
> + vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf,
> + virDomainGetName(dom),
> + state == -2 ? _("saved") : _(vshDomainStateToString(state)),
> + hostname);
> + VIR_FREE(hostname);
> } else {
> vshPrint(ctl, " %-5s %-30s %s\n", id_buf,
> virDomainGetName(dom),
>
This approach has a problem: If you specify "list --title --hostname"
you'll get just the title. When I was adding the Title option I figured
that this situation would happen sooner or later. I thought about a
universal table printer that could dynamicaly print desired columns, but
that seemed a bit of overkill at that time.
A quick option would be to make those option mutually exclusive, but
that's not elegant.
Also this patch misses adding docs for the new flag.
Peter
More information about the libvir-list
mailing list