From 160b3beee193547ac8923489a2693b5c770217b8 Mon Sep 17 00:00:00 2001 From: linggao Date: Fri, 8 Apr 2011 19:56:09 +0000 Subject: [PATCH] setrout postscript git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9257 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/perl/xCAT/Postage.pm | 30 +++++++++++++++++++++++++++- xCAT/postscripts/setroute | 30 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 xCAT/postscripts/setroute diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 742deef77..c4bf69019 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -224,7 +224,7 @@ sub makescript my $noderesent = $noderestab->getNodeAttribs($node, - ['nfsserver', 'installnic', 'primarynic']); + ['nfsserver', 'installnic', 'primarynic','routenames']); if ($noderesent and defined($noderesent->{'nfsserver'})) { push @scriptd, "NFSSERVER=" . $noderesent->{'nfsserver'} . "\n"; @@ -241,6 +241,34 @@ sub makescript push @scriptd, "export PRIMARYNIC\n"; } + #routes + if ($noderesent and defined($noderesent->{'routenames'})) + { + my $rn=$noderesent->{'routenames'}; + my @rn_a=split(',', $rn); + my $routestab = xCAT::Table->new('routes'); + if ((@rn_a > 0) && ($routestab)) { + push @scriptd, "NODEROUTENAMES=$rn\n"; + push @scriptd, "export NODEROUTENAMES\n"; + foreach my $route_name (@rn_a) { + my $routesent = $routestab->getAttribs({routename => $route_name}, 'net', 'mask', 'gateway', 'ifname'); + if ($routesent and defined($routesent->{net}) and defined($routesent->{mask})) { + my $val="ROUTE_$route_name=" . $routesent->{net} . "," . $routesent->{mask}; + $val .= ","; + if (defined($routesent->{gateway})) { + $val .= $routesent->{gateway}; + } + $val .= ","; + if (defined($routesent->{ifname})) { + $val .= $routesent->{ifname}; + } + push @scriptd, "$val\n"; + push @scriptd, "export ROUTE_$route_name\n"; + } + } + } + } + my $os; my $profile; my $arch; diff --git a/xCAT/postscripts/setroute b/xCAT/postscripts/setroute new file mode 100755 index 000000000..256b204e4 --- /dev/null +++ b/xCAT/postscripts/setroute @@ -0,0 +1,30 @@ +#!/bin/sh +# IBM(c) 2011 EPL license http://www.eclipse.org/legal/epl-v10.html + +#------------------------------------------------------------------------------- +#=head1 setroute +#=head2 setrout command adds the routes to the node according to +# what is specified in the xCAT tables. +# The route name for the node is defined in noderes.routenames. +# The route itself is defined in the routes table. +#=cut +#------------------------------------------------------------------------------- + +if [[ -z "$NODEROUTENAMES" ]]; then + exit 0 +fi + +for rn in `echo "$NODEROUTENAMES" | tr "," "\n"` +do + eval route_string=\$ROUTE_$rn + net=`echo $route_string |cut -d',' -f1` + mask=`echo $route_string |cut -d',' -f2` + gw=`echo $route_string |cut -d',' -f3` + ifname=`echo $route_string |cut -d',' -f4` + + cmd="routeop add $net $mask $gw $ifname" + result=`$cmd 2>&1` + echo $result +done + +exit 0