From nobody Thu May 15 04:10:15 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 1519959025667425.8527697060422; Thu, 1 Mar 2018 18:50:25 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1EF1B5D68A; Fri, 2 Mar 2018 02:50:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B33CA6A052; Fri, 2 Mar 2018 02:50:23 +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 59AA518033F2; Fri, 2 Mar 2018 02:50:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w222oAMM016119 for ; Thu, 1 Mar 2018 21:50:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5FB159C072; Fri, 2 Mar 2018 02:50:10 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-175.phx2.redhat.com [10.3.117.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBA409C079 for ; Fri, 2 Mar 2018 02:50:09 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Thu, 1 Mar 2018 21:49:58 -0500 Message-Id: <20180302025000.26919-3-laine@laine.org> In-Reply-To: <20180302025000.26919-1-laine@laine.org> References: <20180302025000.26919-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [tck PATCH v2 2/4] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 02 Mar 2018 02:50:24 +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 --- Change from V1: return a NetAddr::IP object instead of a string. lib/Sys/Virt/TCK/NetworkHelpers.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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