From e41e21b9b5a6e5765a6bf49ef3b3119a514b288d Mon Sep 17 00:00:00 2001 From: immarvin Date: Fri, 23 May 2014 02:56:39 -0700 Subject: [PATCH] correct the getNodeNetworkCfg to get the network gateway --- perl-xCAT/xCAT/NetworkUtils.pm | 96 +++++++++++++++++----------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index c3555833d..7eea170e6 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -1901,50 +1901,6 @@ sub isIpaddr } -#------------------------------------------------------------------------------- -=head3 getSubnetGateway - Description: - Get gateway from the networks table of the specified net. - - Arguments: - net: the net, ie. the "net" field of the networks table - Returns: - Return a string, of the gateway - undef - Failed to get the gateway - Globals: - none - Error: - none - Example: - my $gateway = xCAT::NetworkUtils::getSubnetGateway('192.168.1.0'); - Comments: - none - -=cut -#------------------------------------------------------------------------------- -sub getSubnetGateway -{ - my $netname=shift; - if( $netname =~ /xCAT::NetworkUtils/) - { - $netname=shift; - } - - my $gateway=undef; - my $nettab = xCAT::Table->new("networks"); - unless($nettab) { die "No entry defined in networks"; } - my @nets = $nettab->getAllAttribs('net','gateway'); - foreach(@nets) - { - if("$_->{net}" eq "$netname") - { - $gateway = $_->{gateway}; - last; - } - } - - return $gateway; -} #------------------------------------------------------------------------------- @@ -2002,6 +1958,50 @@ sub getNodeNameservers{ return \%nodenameservers; } +#------------------------------------------------------------------------------- +=head3 getNodeGateway + Description: + Get gateway from the networks table of the node. + + Arguments: + ip: the ip address of the node + Returns: + Return a string, of the gateway + undef - Failed to get the gateway + Globals: + none + Error: + none + Example: + my $gateway = xCAT::NetworkUtils::getNodeGateway('192.168.1.0'); + Comments: + none + +=cut +#------------------------------------------------------------------------------- +sub getNodeGateway +{ + my $ip=shift; + if( $ip =~ /xCAT::NetworkUtils/) + { + $ip=shift; + } + my $gateway=undef; + + my $nettab = xCAT::Table->new("networks"); + if ($nettab) { + my @nets = $nettab->getAllAttribs('net','mask','gateway'); + foreach my $net (@nets) { + if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $ip, $net->{'mask'}, 0)) { + $gateway=$net->{'gateway'}; + } + } + } + + + return $gateway; +} + #------------------------------------------------------------------------------- =head3 getNodeNetworkCfg @@ -2031,8 +2031,8 @@ sub getNodeNetworkCfg if( $node =~ /xCAT::NetworkUtils/) { $node =shift; - } - + } + my $nets = xCAT::NetworkUtils::my_nets(); my $ip = xCAT::NetworkUtils->getipaddr($node); my $mask = undef; @@ -2041,12 +2041,14 @@ sub getNodeNetworkCfg { my $netname; ($netname,$mask) = split /\//, $net; - $gateway=xCAT::NetworkUtils::getSubnetGateway($netname); last if ( xCAT::NetworkUtils::isInSameSubnet( $netname, $ip, $mask, 1)); } + $gateway=xCAT::NetworkUtils::getNodeGateway($ip); return ($ip, $node, $gateway, xCAT::NetworkUtils::formatNetmask($mask,1,0)); } + + #------------------------------------------------------------------------------- =head3 get_hdwr_ip