Commit 02d57fab authored by Daniel P. Berrangé's avatar Daniel P. Berrangé

Remove use of Data::Dumper from example programs

Using Data::Dumper in examples does not help devs understand the data
structures that the Perl APIs are returning. Change to explicit field
accesses to illustrate it better
Reviewed-by: 's avatarJohn Ferlan <jferlan@redhat.com>
Signed-off-by: 's avatarDaniel P. Berrangé <berrange@redhat.com>
parent 60865b63
......@@ -3,6 +3,7 @@ Revision history for perl module Sys::Virt
4.1.0 2018-00-00
- Add VIR_ERR_DEVICE_MISSING constants
- Remove use of Data::Dumper from example programs
4.0.0 2018-01-23
......
#!/usr/bin/perl
use Sys::Virt;
use Data::Dumper;
my $c = Sys::Virt->new(uri => "qemu:///system",
readonly => 1);
......@@ -9,5 +8,9 @@ my $c = Sys::Virt->new(uri => "qemu:///system",
$n = $c->get_network_by_name("default");
foreach my $lease ($n->get_dhcp_leases()) {
print Dumper($lease);
print "Interface ", $lease->{iface}, "\n";
print " MAC: ", $lease->{mac}, "\n";
print " IP: ", $lease->{ipaddr}, "\n";
print " Host: ", $lease->{hostname}, "\n" if $lease->{hostname};
print "\n";
}
#!/usr/bin/perl
use strict;
use warnings;
......@@ -15,7 +14,6 @@ my $dom = $c->get_domain_by_name(shift @ARGV);
my @fs = $dom->get_fs_info();
use Data::Dumper;
print Dumper($fs[0]);
print Dumper($fs[1]);
foreach my $fs (@fs) {
printf "%s (%s) at %s\n", $fs->{name}, $fs->{fstype}, $fs->{mountpoint};
}
#!/usr/bin/perl
use strict;
use warnings;
......@@ -13,9 +12,14 @@ my $c = Sys::Virt->new(uri => $uri);
my $dom = $c->get_domain_by_name(shift @ARGV);
my @fs = $dom->get_interface_addresses(
my @nics = $dom->get_interface_addresses(
Sys::Virt::Domain::INTERFACE_ADDRESSES_SRC_LEASE);
use Data::Dumper;
print Dumper(@fs);
foreach my $nic (@nics) {
print "Interface ", $nic->{name}, "\n";
print " MAC: ", $nic->{hwaddr}, "\n";
foreach my $addr (@{$nic->{addrs}}) {
print " IP: ", $addr->{addr}, "\n";
}
print "\n";
}
......@@ -20,10 +20,7 @@ my @stats = $c->get_all_domain_stats(Sys::Virt::Domain::STATS_STATE,
\@doms,
Sys::Virt::Domain::GET_ALL_STATS_ENFORCE_STATS);
use Data::Dumper;
print Dumper(\@stats);
for (my $i = 0 ; $i <= $#stats ; $i++) {
print $stats[$i]->{'dom'}->get_name(), ": ", $stats[$i]->{'data'}->{'state.state'}, "\n";
foreach my $stats (@stats) {
print "Guest ", $stats->{'dom'}->get_name(), "\n";
print " State: ", $stats->{'data'}->{'state.state'}, "\n";
}
......@@ -13,13 +13,25 @@ my $info = $hv->get_node_info();
my @models = $hv->get_cpu_model_names($info->{model});
print join ("\n", sort{ lc $a cmp lc $b } @models), "\n";
my @info = $hv->get_node_free_pages([2048], 0, 0);
use Data::Dumper;
print Dumper(\@info);
print "Available CPU model names:\n";
print join ("\n", map { " " . $_ } sort{ lc $a cmp lc $b } @models), "\n";
my @pagesizes = (
4, 2048, 1048576
);
my @info = $hv->get_node_free_pages(\@pagesizes, 0, 0);
print "Free pages per NUMA node:\n";
foreach my $info (@info) {
print " Node: ", $info->{cell}, "\n";
print " Free: ";
for (my $i = 0; $i <= $#pagesizes; $i++) {
my $pagesize = $pagesizes[$i];
printf "%d @ %d KB, ", $info->{pages}->{$pagesize}, $pagesize;
}
print "\n";
}
my $xml = $hv->get_domain_capabilities(undef, "x86_64", undef, "kvm");
print $xml;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment