From nobody Mon Apr 29 20:25:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517940642306622.1907284892428; Tue, 6 Feb 2018 10:10:42 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC8A310F3D7; Tue, 6 Feb 2018 18:10:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB27C17C0F; Tue, 6 Feb 2018 18:10:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5EB3B4A46C; Tue, 6 Feb 2018 18:10:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w16IAVPJ028537 for ; Tue, 6 Feb 2018 13:10:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1BFA22D35C; Tue, 6 Feb 2018 18:10:31 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4126260A9D; Tue, 6 Feb 2018 18:10:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 6 Feb 2018 18:10:22 +0000 Message-Id: <20180206181022.4209-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH perl v2] Remove use of Data::Dumper from example programs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 06 Feb 2018 18:10:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: John Ferlan --- examples/dhcp-leases.pl | 7 +++++-- examples/dom-fsinfo.pl | 8 +++----- examples/dom-ifinfo.pl | 14 +++++++++----- examples/dom-stats.pl | 9 +++------ examples/node-info.pl | 26 +++++++++++++++++++------- 5 files changed, 39 insertions(+), 25 deletions(-) diff --git a/examples/dhcp-leases.pl b/examples/dhcp-leases.pl index 84a81ef..a2202d9 100644 --- a/examples/dhcp-leases.pl +++ b/examples/dhcp-leases.pl @@ -1,7 +1,6 @@ #!/usr/bin/perl =20 use Sys::Virt; -use Data::Dumper; =20 my $c =3D Sys::Virt->new(uri =3D> "qemu:///system", readonly =3D> 1); @@ -9,5 +8,9 @@ my $c =3D Sys::Virt->new(uri =3D> "qemu:///system", $n =3D $c->get_network_by_name("default"); =20 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"; } diff --git a/examples/dom-fsinfo.pl b/examples/dom-fsinfo.pl index 7763f78..46c64e9 100644 --- a/examples/dom-fsinfo.pl +++ b/examples/dom-fsinfo.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl =20 - use strict; use warnings; =20 @@ -15,7 +14,6 @@ my $dom =3D $c->get_domain_by_name(shift @ARGV); =20 my @fs =3D $dom->get_fs_info(); =20 -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= }; +} diff --git a/examples/dom-ifinfo.pl b/examples/dom-ifinfo.pl index e10579b..66eb157 100644 --- a/examples/dom-ifinfo.pl +++ b/examples/dom-ifinfo.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl =20 - use strict; use warnings; =20 @@ -13,9 +12,14 @@ my $c =3D Sys::Virt->new(uri =3D> $uri); =20 my $dom =3D $c->get_domain_by_name(shift @ARGV); =20 -my @fs =3D $dom->get_interface_addresses( +my @nics =3D $dom->get_interface_addresses( Sys::Virt::Domain::INTERFACE_ADDRESSES_SRC_LEASE); =20 -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"; +} diff --git a/examples/dom-stats.pl b/examples/dom-stats.pl index 13d8fb7..1da0089 100644 --- a/examples/dom-stats.pl +++ b/examples/dom-stats.pl @@ -20,10 +20,7 @@ my @stats =3D $c->get_all_domain_stats(Sys::Virt::Domain= ::STATS_STATE, \@doms, Sys::Virt::Domain::GET_ALL_STATS_ENFORCE_STATS); =20 -use Data::Dumper; - -print Dumper(\@stats); - -for (my $i =3D 0 ; $i <=3D $#stats ; $i++) { - print $stats[$i]->{'dom'}->get_name(), ": ", $stats[$i]->{'data'}->{'s= tate.state'}, "\n"; +foreach my $stats (@stats) { + print "Guest ", $stats->{'dom'}->get_name(), "\n"; + print " State: ", $stats->{'data'}->{'state.state'}, "\n"; } diff --git a/examples/node-info.pl b/examples/node-info.pl index 89bc9ba..9655ab4 100644 --- a/examples/node-info.pl +++ b/examples/node-info.pl @@ -13,13 +13,25 @@ my $info =3D $hv->get_node_info(); =20 my @models =3D $hv->get_cpu_model_names($info->{model}); =20 -print join ("\n", sort{ lc $a cmp lc $b } @models), "\n"; - -my @info =3D $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 =3D ( + 4, 2048, 1048576 + ); + +my @info =3D $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 =3D 0; $i <=3D $#pagesizes; $i++) { + my $pagesize =3D $pagesizes[$i]; + printf "%d @ %d KB, ", $info->{pages}->{$pagesize}, $pagesize; + } + print "\n"; +} =20 my $xml =3D $hv->get_domain_capabilities(undef, "x86_64", undef, "kvm"); print $xml; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list