From 5184e7da2b785394b2d658db6b70b2618581c276 Mon Sep 17 00:00:00 2001 From: creativezj Date: Wed, 19 Jun 2013 02:36:44 +0000 Subject: [PATCH] fix nodeimport generate brocadcast ip or gateway ip git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@16675 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/NetworkUtils.pm | 20 ++++++++++++++++++++ perl-xCAT/xCAT/ProfiledNodeUtils.pm | 11 +++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index b0d90ae3f..2923b5228 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -2253,6 +2253,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 diff --git a/perl-xCAT/xCAT/ProfiledNodeUtils.pm b/perl-xCAT/xCAT/ProfiledNodeUtils.pm index 3ce61b9d1..16fd6ae38 100644 --- a/perl-xCAT/xCAT/ProfiledNodeUtils.pm +++ b/perl-xCAT/xCAT/ProfiledNodeUtils.pm @@ -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; }