[libvirt] [PATCH] virsh: pool-list: introduce --uuid

From: Chen Hanxiao <chenhanxiao@gmail.com> This patch will introduce option [--uuid]. If specified, UUID of pools will be printed out. virsh # pool-list --all Name State Autostart ------------------------------------------- default active yes root active yes virsh # pool-list --all --uuid Name State Autostart UUID --------------------------------------------------------------------------------- default active yes 45fdb1f3-402d-44c0-b2c0-a7be61fea6c7 root active yes eb397f25-9a44-459d-80df-330ca8f65ba8 Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-pool.c | 31 ++++++++++++++++++++++++++++--- tools/virsh.pod | 5 +++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 8313be8..a502718 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1060,6 +1060,10 @@ static const vshCmdOptDef opts_pool_list[] = { .type = VSH_OT_BOOL, .help = N_("display extended details for pools") }, + {.name = "uuid", + .type = VSH_OT_BOOL, + .help = N_("display UUID of pools") + }, {.name = NULL} }; @@ -1087,6 +1091,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) const char *type = NULL; bool details = vshCommandOptBool(cmd, "details"); bool inactive, all; + bool uuid = false; char *outputStr = NULL; inactive = vshCommandOptBool(cmd, "inactive"); @@ -1111,6 +1116,9 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) if (vshCommandOptBool(cmd, "transient")) flags |= VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT; + if (vshCommandOptBool(cmd, "uuid")) + uuid = true; + if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) return false; @@ -1298,17 +1306,34 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) /* Output basic info then return if --details option not selected */ if (!details) { /* Output old style header */ - vshPrintExtra(ctl, " %-20s %-10s %-10s\n", _("Name"), _("State"), + vshPrintExtra(ctl, " %-20s %-10s %-10s", _("Name"), _("State"), _("Autostart")); - vshPrintExtra(ctl, "-------------------------------------------\n"); + if (uuid) + vshPrintExtra(ctl, " %-10s\n", _("UUID")); + else + vshPrintExtra(ctl, "\n"); + + vshPrintExtra(ctl, "-------------------------------------------"); + + if (uuid) + vshPrintExtra(ctl, "--------------------------------------\n"); + else + vshPrintExtra(ctl, "\n"); /* Output old style pool info */ for (i = 0; i < list->npools; i++) { const char *name = virStoragePoolGetName(list->pools[i]); - vshPrint(ctl, " %-20s %-10s %-10s\n", + char uuid_str[VIR_UUID_STRING_BUFLEN]; + vshPrint(ctl, " %-20s %-10s %-10s", name, poolInfoTexts[i].state, poolInfoTexts[i].autostart); + if (uuid) { + virStoragePoolGetUUIDString(list->pools[i], uuid_str); + vshPrintExtra(ctl, " %-36s\n", uuid_str); + } else { + vshPrintExtra(ctl, "\n"); + } } /* Cleanup and return */ diff --git a/tools/virsh.pod b/tools/virsh.pod index ef91223..0048c67 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3612,7 +3612,7 @@ Returns basic information about the I<pool> object. =item B<pool-list> [I<--inactive>] [I<--all>] [I<--persistent>] [I<--transient>] [I<--autostart>] [I<--no-autostart>] - [[I<--details>] [<type>] + [[I<--details>] [I<--uuid>] [<type>] List pool objects known to libvirt. By default, only active pools are listed; I<--inactive> lists just the inactive pools, and I<--all> @@ -3621,7 +3621,8 @@ lists all pools. In addition, there are several sets of filtering flags. I<--persistent> is to list the persistent pools, I<--transient> is to list the transient pools. I<--autostart> lists the autostarting pools, I<--no-autostart> lists the pools -with autostarting disabled. +with autostarting disabled. If I<--uuid> is specified the UUID of the named +pools will be printed out. You may also want to list pools with specified types using I<type>, the pool types must be separated by comma, e.g. --type dir,disk. The valid pool -- 2.7.4

On Thu, Jan 05, 2017 at 11:56:21AM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will introduce option [--uuid]. If specified, UUID of pools will be printed out.
virsh # pool-list --all Name State Autostart ------------------------------------------- default active yes root active yes
virsh # pool-list --all --uuid Name State Autostart UUID --------------------------------------------------------------------------------- default active yes 45fdb1f3-402d-44c0-b2c0-a7be61fea6c7 root active yes eb397f25-9a44-459d-80df-330ca8f65ba8
The whole point of '--uuid' and '--name' options for the existing list commands is to improve shell scripting with virsh, i.e. avoid having to parse the format of the table in order to extract some info and/or to call <prefix>uuid command in a loop for every entry in the table. With your proposal one would still have to parse the table contents which is in contrast in what I've just mentioned. Also, this would introduce some inconsistency with how we currently treat those options with other commands. So this patch will have to be reworked and while at it, you could also introduce the '--name' option along with '--uuid'. Erik

At 2017-01-05 17:18:14, "Erik Skultety" <eskultet@redhat.com> wrote:
On Thu, Jan 05, 2017 at 11:56:21AM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will introduce option [--uuid]. If specified, UUID of pools will be printed out.
virsh # pool-list --all Name State Autostart ------------------------------------------- default active yes root active yes
virsh # pool-list --all --uuid Name State Autostart UUID --------------------------------------------------------------------------------- default active yes 45fdb1f3-402d-44c0-b2c0-a7be61fea6c7 root active yes eb397f25-9a44-459d-80df-330ca8f65ba8
The whole point of '--uuid' and '--name' options for the existing list commands is to improve shell scripting with virsh, i.e. avoid having to parse the format of the table in order to extract some info and/or to call <prefix>uuid command in a loop for every entry in the table. With your proposal one would still have to parse the table contents which is in contrast in what I've just mentioned. Also, this would introduce some inconsistency with how we currently treat those options with other commands. So this patch will have to be reworked and while at it, you could also introduce the '--name' option along with '--uuid'.
As what we did in the other virsh command, such as 'list`, We could did as: 1) virsh # pool-list --name default root 2) virsh # pool-list --all --uuid 45fdb1f3-402d-44c0-b2c0-a7be61fea6c7 eb397f25-9a44-459d-80df-330ca8f65ba8 3) virsh # pool-list --all --uuid --name Name State Autostart UUID --------------------------------------------------------------------------------- default active yes 45fdb1f3-402d-44c0-b2c0-a7be61fea6c7 root active yes eb397f25-9a44-459d-80df-330ca8f65ba8 v2 will come soon. Regards, - Chen
participants (2)
-
Chen Hanxiao
-
Erik Skultety