defect 3969: support return multiple ips for networkUtils->my_ip_facing()

This commit is contained in:
daniceexi 2014-12-23 06:58:14 -05:00
parent 5ff9396c01
commit 77d46e97cc
2 changed files with 21 additions and 7 deletions

View File

@ -1098,7 +1098,8 @@ sub my_if_netmap
Error:
none
Example:
xCAT::NetworkUtils->my_ip_facing
my $ip = xCAT::NetworkUtils->my_ip_facing($peerip)
my @ip = xCAT::NetworkUtils->my_ip_facing($peerip) # return multiple
Comments:
none
=cut
@ -1116,6 +1117,8 @@ sub my_ip_facing
unless ($peernumber) { return undef; }
my $noden = unpack("N", inet_aton($peer));
my @nets = split /\n/, `/sbin/ip addr`;
my @ips;
foreach (@nets)
{
my @elems = split /\s+/;
@ -1128,10 +1131,19 @@ sub my_ip_facing
my $curn = unpack("N", inet_aton($curnet));
if (($noden & $curmask) == ($curn & $curmask))
{
return $curnet;
push @ips, $curnet;
}
}
return undef;
if (@ips) {
if (wantarray) {
return @ips;
} else {
return $ips[0];
}
} else {
return undef;
}
}
#-------------------------------------------------------------------------------

View File

@ -355,13 +355,15 @@ sub process_request {
if ($net and $net->{nameservers})
{
my $valid = 0;
my $myip = xCAT::NetworkUtils->my_ip_facing($net->{net});
my @myips = xCAT::NetworkUtils->my_ip_facing($net->{net});
foreach (split /,/, $net->{nameservers})
{
chomp $_;
if (($_ eq $myip) || ($_ eq '<xcatmaster>') || ($_ eq $sitens))
{
$valid += 1;
foreach my $myip (@myips) {
if (($_ eq $myip) || ($_ eq '<xcatmaster>') || ($_ eq $sitens))
{
$valid += 1;
}
}
}
unless ($valid > 0)