From nobody Thu May 15 00:30:28 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520345896301495.04296328945054; Tue, 6 Mar 2018 06:18:16 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9F3EC0587D7; Tue, 6 Mar 2018 14:18:14 +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 AFE355D6A2; Tue, 6 Mar 2018 14:18:14 +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 754DD4A471; Tue, 6 Mar 2018 14:18:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26EI5di021036 for ; Tue, 6 Mar 2018 09:18:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1176E10B0F3B; Tue, 6 Mar 2018 14:18:05 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-195.phx2.redhat.com [10.3.116.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 873B610B0F3D; Tue, 6 Mar 2018 14:18:04 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Tue, 6 Mar 2018 09:17:52 -0500 Message-Id: <20180306141752.507189-3-laine@laine.org> In-Reply-To: <20180306141752.507189-1-laine@laine.org> References: <20180306141752.507189-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [tck PATCH v3 2/2] new NetworkHelper function get_network_ip() 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 06 Mar 2018 14:18:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This function gets the first IP address for the named virtual network. It is returned as a Net::IP object, so that we will have info about its netmask/prefix and can easily get it broadcast address and perform arithmetic on the address. Signed-off-by: Laine Stump Reviewed-by: Daniel P. Berrang=C3=A9 --- Build.PL | 1 + lib/Sys/Virt/TCK/NetworkHelpers.pm | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Build.PL b/Build.PL index 9593021..bf2d7a9 100644 --- a/Build.PL +++ b/Build.PL @@ -79,6 +79,7 @@ my $b =3D $class->new( 'IO::String' =3D> 0, 'IO::Uncompress::Gunzip' =3D> 0, 'IO::Uncompress::Bunzip2' =3D> 0, + 'NetAddr::IP' =3D> 0, 'TAP::Formatter::HTML' =3D> 0, 'TAP::Formatter::JUnit' =3D> 0, 'TAP::Harness' =3D> 3.11, diff --git a/lib/Sys/Virt/TCK/NetworkHelpers.pm b/lib/Sys/Virt/TCK/NetworkH= elpers.pm index 5f563e5..7bbce62 100644 --- a/lib/Sys/Virt/TCK/NetworkHelpers.pm +++ b/lib/Sys/Virt/TCK/NetworkHelpers.pm @@ -1,4 +1,5 @@ use Sys::Virt::TCK qw(xpath); +use NetAddr::IP qw(:lower); use strict; use utf8; =20 @@ -9,6 +10,27 @@ sub get_first_macaddress { return $mac; } =20 +sub get_network_ip { + my $conn =3D shift; + my $netname =3D shift; + diag "getting ip for network $netname"; + my $net =3D $conn->get_network_by_name($netname); + my $net_ip =3D xpath($net, "string(/network/ip[1]/\@address"); + my $net_mask =3D xpath($net, "string(/network/ip[1]/\@netmask"); + my $net_prefix =3D xpath($net, "string(/network/ip[1]/\@prefix"); + my $ip; + + if ($net_mask) { + $ip =3D NetAddr::IP->new($net_ip, $net_mask); + } elsif ($net_prefix) { + $ip =3D NetAddr::IP->new("$net_ip/$net_mask"); + } else { + $ip =3D NetAddr::IP->new("$net_ip"); + } + return $ip; +} + + sub get_ip_from_leases{ my $conn =3D shift; my $netname =3D shift; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list