virsh: allow both --table and --uuid at the same time

This will allow to print full domains info:

   Id   Name   State   UUID
  ---------------------------

Signed-off-by: Nikolai Barybin <nikolai.barybin@virtuozzo.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Nikolai Barybin via Devel
2024-08-14 14:30:02 +03:00
committed by Michal Privoznik
parent b1524a3efc
commit 271940223c
2 changed files with 40 additions and 11 deletions

View File

@@ -1855,10 +1855,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
FILTER("state-other", VIR_CONNECT_LIST_DOMAINS_OTHER);
VSH_EXCLUSIVE_OPTIONS("table", "name");
VSH_EXCLUSIVE_OPTIONS("table", "uuid");
VSH_EXCLUSIVE_OPTIONS("table", "id");
if (!optUUID && !optName && !optID)
if (!optName && !optID)
optTable = true;
if (!(list = virshDomainListCollect(ctl, flags)))
@@ -1866,8 +1865,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
/* print table header in legacy mode */
if (optTable) {
if (optTitle)
if (optTitle && !optUUID)
table = vshTableNew(_("Id"), _("Name"), _("State"), _("Title"), NULL);
else if (optUUID && !optTitle)
table = vshTableNew(_("Id"), _("Name"), _("State"), _("UUID"), NULL);
else if (optUUID && optTitle)
table = vshTableNew(_("Id"), _("Name"), _("State"), _("Title"), _("UUID"), NULL);
else
table = vshTableNew(_("Id"), _("Name"), _("State"), NULL);
@@ -1896,7 +1899,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
virDomainHasManagedSaveImage(dom, 0) > 0)
state = -2;
if (optTitle) {
if (optTitle && !optUUID) {
g_autofree char *title = NULL;
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
@@ -1907,6 +1910,32 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
: virshDomainStateToString(state),
title, NULL) < 0)
goto cleanup;
} else if (optUUID && !optTitle) {
if (virDomainGetUUIDString(dom, uuid) < 0) {
vshError(ctl, "%s", _("Failed to get domain's UUID"));
goto cleanup;
}
if (vshTableRowAppend(table, id_buf,
virDomainGetName(dom),
state == -2 ? _("saved")
: virshDomainStateToString(state),
uuid, NULL) < 0)
goto cleanup;
} else if (optUUID && optTitle) {
g_autofree char *title = NULL;
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
goto cleanup;
if (virDomainGetUUIDString(dom, uuid) < 0) {
vshError(ctl, "%s", _("Failed to get domain's UUID"));
goto cleanup;
}
if (vshTableRowAppend(table, id_buf,
virDomainGetName(dom),
state == -2 ? _("saved")
: virshDomainStateToString(state),
title, uuid, NULL) < 0)
goto cleanup;
} else {
if (vshTableRowAppend(table, id_buf,
virDomainGetName(dom),