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

Laine Stump laine at laine.org
Mon Mar 5 15:10:36 UTC 2018


On 03/05/2018 04:31 AM, Daniel P. Berrangé wrote:
> 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 at laine.org>
>> ---
>>
>> 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.

I originally assumed that, but remembered seeing "something somewhere"
about implicit dependencies and decided to try it out by not listing it
in the specfile - on both Fedora and RHEL7 the dependency was properly
pulled in and it was installed.

This leads to one of three possibilities:

1) implicit dependencies are figured out properly by yum and dnf (at
least for RHEL7, don't know about RHEL6).

2) (1), but it's just coincidentally happening and not guaranteed.

3) I wasn't paying attention when I tested, and what I say isn't
actually true.


I don't have any problem putting in the explicit Requires though. Can I
assumed a Reviewed-by with that in place?

>
>>  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 at redhat.com
>> https://www.redhat.com/mailman/listinfo/libvir-list
> Regards,
> Daniel





More information about the libvir-list mailing list