[libvirt] [PATCH v2 0/3] virsh: pool-list: introduce option --name and --uuid

virsh # pool-list --name default root virsh # pool-list --uuid 76bd3b4d-2d23-4741-b6de-7377fa4320a1 f97964af-a3df-44ff-8664-886729035c09 virsh # pool-list --uuid --name 76bd3b4d-2d23-4741-b6de-7377fa4320a1 default f97964af-a3df-44ff-8664-886729035c09 root v2: do something like 'virsh list` Chen Hanxiao (3): virsh: pool-list: introduce --uuid for printing pool's UUID only virsh: pool-list: introduce --name for printing pool's name only virsh: pool-list: allow both --uuid and --name in one cmd tools/virsh-pool.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- tools/virsh.pod | 9 +++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) -- 2.5.5

From: Chen Hanxiao <chenhanxiao@gmail.com> This patch will introduce option --uuid. If specified, only UUID of pools will be printed out. Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-pool.c | 20 ++++++++++++++++++++ tools/virsh.pod | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 8313be8..5cf8ce4 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_("list UUID of active pools only") + }, {.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,9 +1116,14 @@ 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; + VSH_EXCLUSIVE_OPTIONS("details", "uuid"); + if (type) { int poolType = -1; char **poolTypes = NULL; @@ -1297,6 +1307,16 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) /* Output basic info then return if --details option not selected */ if (!details) { + if (uuid) { + for (i = 0; i < list->npools; i++) { + char uuid_str[VIR_UUID_STRING_BUFLEN]; + virStoragePoolGetUUIDString(list->pools[i], uuid_str); + vshPrint(ctl, "%-36s\n", uuid_str); + } + ret = true; + goto cleanup; + } + /* Output old style header */ vshPrintExtra(ctl, " %-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart")); diff --git a/tools/virsh.pod b/tools/virsh.pod index ef91223..0a1ad84 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,7 @@ 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 only pool's UUIDs are printed. 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.5.5

From: Chen Hanxiao <chenhanxiao@gmail.com> This patch will introduce option --name. If specified, only name of pools will be printed out. Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-pool.c | 22 ++++++++++++++++++++-- tools/virsh.pod | 4 +++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 5cf8ce4..da43199 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1064,6 +1064,10 @@ static const vshCmdOptDef opts_pool_list[] = { .type = VSH_OT_BOOL, .help = N_("list UUID of active pools only") }, + {.name = "name", + .type = VSH_OT_BOOL, + .help = N_("list name of active pools only") + }, {.name = NULL} }; @@ -1092,6 +1096,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) bool details = vshCommandOptBool(cmd, "details"); bool inactive, all; bool uuid = false; + bool name = false; char *outputStr = NULL; inactive = vshCommandOptBool(cmd, "inactive"); @@ -1119,10 +1124,14 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) if (vshCommandOptBool(cmd, "uuid")) uuid = true; + if (vshCommandOptBool(cmd, "name")) + name = true; + if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) return false; VSH_EXCLUSIVE_OPTIONS("details", "uuid"); + VSH_EXCLUSIVE_OPTIONS("details", "name"); if (type) { int poolType = -1; @@ -1317,6 +1326,15 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) goto cleanup; } + if (name) { + for (i = 0; i < list->npools; i++) { + const char *name_str = virStoragePoolGetName(list->pools[i]); + vshPrint(ctl, "%-20s\n", name_str); + } + ret = true; + goto cleanup; + } + /* Output old style header */ vshPrintExtra(ctl, " %-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart")); @@ -1324,9 +1342,9 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) /* Output old style pool info */ for (i = 0; i < list->npools; i++) { - const char *name = virStoragePoolGetName(list->pools[i]); + const char *name_str = virStoragePoolGetName(list->pools[i]); vshPrint(ctl, " %-20s %-10s %-10s\n", - name, + name_str, poolInfoTexts[i].state, poolInfoTexts[i].autostart); } diff --git a/tools/virsh.pod b/tools/virsh.pod index 0a1ad84..463762a 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3612,7 +3612,8 @@ 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>] [I<--uuid>] [<type>] + [[I<--details>] [I<--uuid>] + [I<--name>] [<type>] List pool objects known to libvirt. By default, only active pools are listed; I<--inactive> lists just the inactive pools, and I<--all> @@ -3622,6 +3623,7 @@ 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. If I<--uuid> is specified only pool's UUIDs are printed. +If I<--name> is specified only pool's names are printed. 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.5.5

From: Chen Hanxiao <chenhanxiao@gmail.com> This patch will allow --uuid and --name in one cmd. The pool's UUID and name will be printed side by side. Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-pool.c | 8 +++++++- tools/virsh.pod | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index da43199..ebe1f68 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1320,7 +1320,13 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) for (i = 0; i < list->npools; i++) { char uuid_str[VIR_UUID_STRING_BUFLEN]; virStoragePoolGetUUIDString(list->pools[i], uuid_str); - vshPrint(ctl, "%-36s\n", uuid_str); + if (!name) { + vshPrint(ctl, "%-36s\n", uuid_str); + } else { + const char *name_str = + virStoragePoolGetName(list->pools[i]); + vshPrint(ctl, "%-36s %-10s\n", uuid_str, name_str); + } } ret = true; goto cleanup; diff --git a/tools/virsh.pod b/tools/virsh.pod index 463762a..553115e 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3623,7 +3623,10 @@ 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. If I<--uuid> is specified only pool's UUIDs are printed. -If I<--name> is specified only pool's names are printed. +If I<--name> is specified only pool's names are printed. If both I<--name> +and I<--uuid> are specified, pool's UUID and names are printed side by side +without any header. Options I<--uuid> and I<--name> are mutually exclusive +if option I<--details> is specified. 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.5.5

On 01/06/2017 09:42 AM, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch will allow --uuid and --name in one cmd. The pool's UUID and name will be printed side by side.
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> --- tools/virsh-pool.c | 8 +++++++- tools/virsh.pod | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index da43199..ebe1f68 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1320,7 +1320,13 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) for (i = 0; i < list->npools; i++) { char uuid_str[VIR_UUID_STRING_BUFLEN]; virStoragePoolGetUUIDString(list->pools[i], uuid_str); - vshPrint(ctl, "%-36s\n", uuid_str); + if (!name) { + vshPrint(ctl, "%-36s\n", uuid_str); + } else { + const char *name_str = + virStoragePoolGetName(list->pools[i]); + vshPrint(ctl, "%-36s %-10s\n", uuid_str, name_str); + }
Rather than two separate loops - it should just be one loop and rather than -10s for name, I kept with the -20s. See the hunk below which I squashed in before pushing the series. I've also added a news.xml entry for this Thanks! John
} ret = true; goto cleanup; diff --git a/tools/virsh.pod b/tools/virsh.pod index 463762a..553115e 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3623,7 +3623,10 @@ 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. If I<--uuid> is specified only pool's UUIDs are printed. -If I<--name> is specified only pool's names are printed. +If I<--name> is specified only pool's names are printed. If both I<--name> +and I<--uuid> are specified, pool's UUID and names are printed side by side +without any header. Options I<--uuid> and I<--name> are mutually exclusive +if option I<--details> is specified.
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
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 85124e8..7a74ba0 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1316,31 +1316,23 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) /* Output basic info then return if --details option not selected */ if (!details) { - if (uuid) { + if (uuid || name) { for (i = 0; i < list->npools; i++) { - char uuid_str[VIR_UUID_STRING_BUFLEN]; - virStoragePoolGetUUIDString(list->pools[i], uuid_str); - if (!name) { - vshPrint(ctl, "%-36s\n", uuid_str); - } else { + if (uuid) { + char uuid_str[VIR_UUID_STRING_BUFLEN]; + virStoragePoolGetUUIDString(list->pools[i], uuid_str); + vshPrint(ctl, "%-36s%c", uuid_str, name ? ' ': '\n'); + } + if (name) { const char *name_str = virStoragePoolGetName(list->pools[i]); - vshPrint(ctl, "%-36s %-10s\n", uuid_str, name_str); + vshPrint(ctl, "%-20s\n", name_str); } } ret = true; goto cleanup; } - if (name) { - for (i = 0; i < list->npools; i++) { - const char *name_str = virStoragePoolGetName(list->pools[i]); - vshPrint(ctl, "%-20s\n", name_str); - } - ret = true; - goto cleanup; - } - /* Output old style header */ vshPrintExtra(ctl, " %-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart"));
participants (2)
-
Chen Hanxiao
-
John Ferlan