mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
virsh: cmdNodeMemStats: Rework to vshTable
After recent addition of 'available' field the hardcoded alignments no longer match: $ virsh nodememstats total : 63393452 KiB free : 4046756 KiB available: 35747628 KiB buffers: 2291748 KiB cached : 24086464 KiB To address the issue switch to use dynamically aligned columns via vshTable infrastructure: $ virsh nodememstats total : 63393452 KiB free : 3888776 KiB available: 35640268 KiB buffers : 2291768 KiB cached : 24089916 KiB Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
1 parent
ec0246c491
commit
2c047bb619
1 file changed
+15
-2
+15
-2
@@ -33,6 +33,7 @@
|
||||
#include "virfile.h"
|
||||
#include "virenum.h"
|
||||
#include "virsh-util.h"
|
||||
#include "vsh-table.h"
|
||||
|
||||
/*
|
||||
* "capabilities" command
|
||||
@@ -889,6 +890,8 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
|
||||
int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
|
||||
g_autofree virNodeMemoryStatsPtr params = NULL;
|
||||
virshControl *priv = ctl->privData;
|
||||
g_autoptr(vshTable) table = vshTableNew("field", ":", "value", NULL);
|
||||
g_autofree char *tblstr = NULL;
|
||||
|
||||
if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0)
|
||||
return false;
|
||||
@@ -912,8 +915,18 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < nparams; i++)
|
||||
vshPrint(ctl, "%-7s: %20llu KiB\n", params[i].field, params[i].value);
|
||||
for (i = 0; i < nparams; i++) {
|
||||
g_autofree char *val = g_strdup_printf("%llu KiB", params[i].value);
|
||||
|
||||
vshTableRowAppendFlags(table,
|
||||
VSH_TABLE_CELL_SKIP_LEADING | VSH_TABLE_CELL_SKIP_TRAILING, params[i].field,
|
||||
VSH_TABLE_CELL_SKIP_LEADING, ":",
|
||||
VSH_TABLE_CELL_ALIGN_RIGHT, val,
|
||||
0, NULL);
|
||||
}
|
||||
|
||||
tblstr = vshTablePrintToString(table, false);
|
||||
vshPrint(ctl, "%s", tblstr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user