[pve-devel] [PATCH qemu-server] fix verbose qm status output
Dominik Csapak
d.csapak at proxmox.com
Mon Jul 18 10:50:31 CEST 2016
we did not check if some values were hash refs in
the verbose output.
this patch adds a recursive hash print sub and uses it
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/CLI/qm.pm | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index d0d7a6c..e513f33 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -75,6 +75,32 @@ sub run_vnc_proxy {
exit(0);
}
+sub print_recursive_hash {
+ my ($prefix, $hash, $key) = @_;
+
+ if (ref($hash) eq 'HASH') {
+ if (defined($key)) {
+ print "$prefix$key:\n";
+ }
+ foreach my $itemkey (keys %$hash) {
+ print_recursive_hash("\t$prefix", $hash->{$itemkey}, $itemkey);
+ }
+ } elsif (ref($hash) eq 'ARRAY') {
+ if (defined($key)) {
+ print "$prefix$key:\n";
+ }
+ foreach my $item (@$hash) {
+ print_recursive_hash("\t$prefix", $item);
+ }
+ } elsif (!ref($hash) && defined($hash)) {
+ if (defined($key)) {
+ print "$prefix$key: $hash\n";
+ } else {
+ print "$prefix$hash\n";
+ }
+ }
+}
+
__PACKAGE__->register_method ({
name => 'showcmd',
path => 'showcmd',
@@ -125,8 +151,7 @@ __PACKAGE__->register_method ({
foreach my $k (sort (keys %$stat)) {
next if $k eq 'cpu' || $k eq 'relcpu'; # always 0
my $v = $stat->{$k};
- next if !defined($v);
- print "$k: $v\n";
+ print_recursive_hash("", $v, $k);
}
} else {
my $status = $stat->{qmpstatus} || 'unknown';
--
2.1.4
More information about the pve-devel
mailing list