[libvirt] [PATCH] virsh: introduce name-uuid for list command

From: Chen Hanxiao <chenhanxiao@gmail.com> This patch will show both name and UUID of domain: Id Name State UUID --------------------------------------------------------------------------------------- 3 f23 running 918f1dd6-b19f-412b-ba17-d113bad89af8 Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-domain-monitor.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0a93949..32e4ea4 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1793,6 +1793,10 @@ static const vshCmdOptDef opts_list[] = { .type = VSH_OT_BOOL, .help = N_("show domain title") }, + {.name = "name-uuid", + .type = VSH_OT_BOOL, + .help = N_("show domain name and uuid") + }, {.name = NULL} }; @@ -1807,6 +1811,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) bool optTable = vshCommandOptBool(cmd, "table"); bool optUUID = vshCommandOptBool(cmd, "uuid"); bool optName = vshCommandOptBool(cmd, "name"); + bool optNameUuid = vshCommandOptBool(cmd, "name-uuid"); size_t i; char *title; char uuid[VIR_UUID_STRING_BUFLEN]; @@ -1844,10 +1849,10 @@ cmdList(vshControl *ctl, const vshCmd *cmd) FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF); FILTER("state-other", VIR_CONNECT_LIST_DOMAINS_OTHER); - if (optTable + optName + optUUID > 1) { + if (optTable + optName + optUUID + optNameUuid > 1) { vshError(ctl, "%s", - _("Only one argument from --table, --name and --uuid " - "may be specified.")); + _("Only one argument from --table, --name, --uuid " + "and --name-uuid may be specified.")); return false; } @@ -1864,6 +1869,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd) _("Id"), _("Name"), _("State"), _("Title"), "-----------------------------------------" "-----------------------------------------"); + else if (optNameUuid) + vshPrintExtra(ctl, " %-5s %-30s %-10s %-36s\n%s\n", + _("Id"), _("Name"), _("State"), _("UUID"), + "-----------------------------------------" + "-----------------------------------------" + "----"); else vshPrintExtra(ctl, " %-5s %-30s %s\n%s\n", _("Id"), _("Name"), _("State"), @@ -1901,6 +1912,16 @@ cmdList(vshControl *ctl, const vshCmd *cmd) title); VIR_FREE(title); + } else if (optNameUuid) { + if (virDomainGetUUIDString(dom, uuid) < 0) { + vshError(ctl, "%s", _("Failed to get domain's UUID")); + goto cleanup; + } + vshPrint(ctl, " %-5s %-30s %-10s %-36s\n", id_buf, + virDomainGetName(dom), + state == -2 ? _("saved") + : virshDomainStateToString(state), + uuid); } else { vshPrint(ctl, " %-5s %-30s %s\n", id_buf, virDomainGetName(dom), -- 1.8.3.1

On Wed, Jun 15, 2016 at 05:36:05PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will show both name and UUID of domain:
Id Name State UUID --------------------------------------------------------------------------------------- 3 f23 running 918f1dd6-b19f-412b-ba17-d113bad89af8
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-domain-monitor.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0a93949..32e4ea4 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1844,10 +1849,10 @@ cmdList(vshControl *ctl, const vshCmd *cmd) FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF); FILTER("state-other", VIR_CONNECT_LIST_DOMAINS_OTHER);
- if (optTable + optName + optUUID > 1) { + if (optTable + optName + optUUID + optNameUuid > 1) { vshError(ctl, "%s", - _("Only one argument from --table, --name and --uuid " - "may be specified.")); + _("Only one argument from --table, --name, --uuid " + "and --name-uuid may be specified."));
Allowing both --name and --uuid for the same functionality would be nicer, is there a reason why we can't do that? Jan
return false; }

At 2016-06-15 18:12:33, "Ján Tomko" <jtomko@redhat.com> wrote:
On Wed, Jun 15, 2016 at 05:36:05PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will show both name and UUID of domain:
Id Name State UUID --------------------------------------------------------------------------------------- 3 f23 running 918f1dd6-b19f-412b-ba17-d113bad89af8
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-domain-monitor.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0a93949..32e4ea4 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1844,10 +1849,10 @@ cmdList(vshControl *ctl, const vshCmd *cmd) FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF); FILTER("state-other", VIR_CONNECT_LIST_DOMAINS_OTHER);
- if (optTable + optName + optUUID > 1) { + if (optTable + optName + optUUID + optNameUuid > 1) { vshError(ctl, "%s", - _("Only one argument from --table, --name and --uuid " - "may be specified.")); + _("Only one argument from --table, --name, --uuid " + "and --name-uuid may be specified."));
Allowing both --name and --uuid for the same functionality would be nicer, is there a reason why we can't do that?
--uuid show UUIDs without title. Guessing it's used for scripts? Regards, - Chen
Jan
return false; }
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

At 2016-06-15 17:36:05, "Chen Hanxiao" <chen_han_xiao@126.com> wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will show both name and UUID of domain:
Id Name State UUID --------------------------------------------------------------------------------------- 3 f23 running 918f1dd6-b19f-412b-ba17-d113bad89af8
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> ---
ping? Regards, - Chen

On Mon, Jun 20, 2016 at 19:22:45 +0800, Chen Hanxiao wrote:
At 2016-06-15 17:36:05, "Chen Hanxiao" <chen_han_xiao@126.com> wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will show both name and UUID of domain:
Id Name State UUID --------------------------------------------------------------------------------------- 3 f23 running 918f1dd6-b19f-412b-ba17-d113bad89af8
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> ---
ping?
Jan already provided a review. I agree with his view. Allowing both --name --uuid is better than the new argument.

At 2016-06-20 21:38:42, "Peter Krempa" <pkrempa@redhat.com> wrote:
On Mon, Jun 20, 2016 at 19:22:45 +0800, Chen Hanxiao wrote:
At 2016-06-15 17:36:05, "Chen Hanxiao" <chen_han_xiao@126.com> wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will show both name and UUID of domain:
Id Name State UUID --------------------------------------------------------------------------------------- 3 f23 running 918f1dd6-b19f-412b-ba17-d113bad89af8
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> ---
ping?
Jan already provided a review. I agree with his view. Allowing both --name --uuid is better than the new argument.
Hi, My only concern is that why we forbid --uuid with --name at the same time at the begining. If we let them come together, does that bring some backcompat issues? Regards, - Chen

On 06/20/2016 10:51 AM, Chen Hanxiao wrote:
At 2016-06-20 21:38:42, "Peter Krempa" <pkrempa@redhat.com> wrote:
On Mon, Jun 20, 2016 at 19:22:45 +0800, Chen Hanxiao wrote:
At 2016-06-15 17:36:05, "Chen Hanxiao" <chen_han_xiao@126.com> wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will show both name and UUID of domain:
Id Name State UUID --------------------------------------------------------------------------------------- 3 f23 running 918f1dd6-b19f-412b-ba17-d113bad89af8
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> ---
ping?
Jan already provided a review. I agree with his view. Allowing both --name --uuid is better than the new argument.
Hi,
My only concern is that why we forbid --uuid with --name at the same time at the begining. If we let them come together, does that bring some backcompat issues?
you can research the history rather easily using gitk... I suggest looking at commit id '419e5fb3' which implemented the --uuid and --name switches and the commit message gives you more details. In addition to what's already been posted - you're adding UUID but making it an exclusive of optTitle, but I see no check for that. What if someone wanted both? Another way to "think" about this is that "by default" there are 3 items displayed. Historically, if someone uses --uuid, then only uuid's are displayed. Likewise, if someone uses --name, then only name's are displayed. Over time, we allowed --title to mean default (or optTable in the code) plus title. So now you're proposing to allow displaying the UUID. Since it's not a "default" output, you can choose where/how to place it. Of course your proposal can bring out various opinions - my would probably keep Name and UUID closer together. UUID is at least "sized" so that helps with columnar output. Perhaps using the VSH_EXCLUSIVE* macros may help you devise a way to print out perhaps what someone wants. I don't think it would be difficult to allow the default, but then allow someone to supply other column names as switches to allow an "ordered" display of data (eg, virsh --id --name, displays id and name. virsh --name --uuid --state displays name, uuid, and state). John
participants (4)
-
Chen Hanxiao
-
John Ferlan
-
Ján Tomko
-
Peter Krempa