Re: [tck PATCH v2 2/4] new NetworkHelper function get_network_ip()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 01, 2018 at 09:49:58PM -0500, Laine Stump wrote:
> 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 <laine@xxxxxxxxx>
> ---
> 
> 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/NetworkHelpers.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);

This isn't part of base perl, so you'll need to list it in Build.PL and
the RPM spec file.

>  use strict;
>  use utf8;
>  
> @@ -9,6 +10,27 @@ sub get_first_macaddress {
>      return $mac;
>  }
>  
> +sub get_network_ip {
> +    my $conn = shift;
> +    my $netname = shift;
> +    diag "getting ip for network $netname";
> +    my $net = $conn->get_network_by_name($netname);
> +    my $net_ip = xpath($net, "string(/network/ip[1]/\@address");
> +    my $net_mask = xpath($net, "string(/network/ip[1]/\@netmask");
> +    my $net_prefix = xpath($net, "string(/network/ip[1]/\@prefix");
> +    my $ip;
> +
> +    if ($net_mask) {
> +        $ip = NetAddr::IP->new($net_ip, $net_mask);
> +    } elsif ($net_prefix) {
> +        $ip = NetAddr::IP->new("$net_ip/$net_mask");
> +    } else {
> +        $ip = NetAddr::IP->new("$net_ip");
> +    }
> +    return $ip;
> +}
> +
> +
>  sub get_ip_from_leases{
>      my $conn = shift;
>      my $netname = shift;
> -- 
> 2.14.3
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux