[pve-devel] [PATCH qemu-server] fix verbose qm status output

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Jul 26 14:52:00 CEST 2016


applied

On Mon, Jul 18, 2016 at 10:50:31AM +0200, Dominik Csapak wrote:
> 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
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 




More information about the pve-devel mailing list