fix nodeimport generate brocadcast ip or gateway ip

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.8@16676 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
creativezj 2013-06-19 02:39:52 +00:00
parent e2d8a38928
commit 594facc9a0
2 changed files with 29 additions and 2 deletions

View File

@ -2254,6 +2254,26 @@ sub int_to_ip
#-------------------------------------------------------------------------------
=head3 getBroadcast
Description : Get the broadcast ips
Arguments : ipstr - the IPv4 string ip.
netmask - the subnet mask of network
Returns : bcipint - the IPv4 string of broadcast ip.
=cut
#-------------------------------------------------------------------------------
sub getBroadcast
{
my ($class, $ipstr, $netmask) = @_;
my $ipint = xCAT::NetworkUtils->ip_to_int($ipstr);
my $maskint = xCAT::NetworkUtils->ip_to_int($netmask);
my $tmp = sprintf("%d", ~$maskint);
my $bcnum = sprintf("%d", ($ipint | $tmp) & hex('0x00000000FFFFFFFF'));
return xCAT::NetworkUtils->int_to_ip($bcnum);
}
#-------------------------------------------------------------------------------
=head3 get_allips_in_range
Description : Get all IPs in a IP range, return in a list.
Arguments : $startip - start IP address

View File

@ -52,14 +52,21 @@ sub get_allocable_staticips_innet
my $netentry = ($networkstab->getAllAttribsWhere("netname = '$netname'", 'ALL'))[0];
my ($startip, $endip) = split('-', $netentry->{'staticrange'});
my $incremental = $netentry->{'staticrangeincrement'};
my $netmask = $netentry->{'mask'};
my $gateway = $netentry->{'gateway'};
my $validipsref;
if ($incremental and $startip and $endip){
$validipsref = xCAT::NetworkUtils->get_allips_in_range($startip, $endip, $incremental);
}
my $broadcastip = xCAT::NetworkUtils->getBroadcast($startip, $netmask);
foreach (@$validipsref){
if (! exists($iphash{$_})){
push @allocableips, $_;
#Remove ip which is broadcast ip, exclude ip, ips ended with 0, gateway ip
if (exists($iphash{$_}) or $_ eq $broadcastip or $_ eq $gateway
or $_ =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(0)$/){
next;
}
push @allocableips, $_;
}
return \@allocableips;
}