2008-04-24 13:04:01 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
# Sample xCAT post script for configuring eth1 based on eth0 settings and
|
2011-10-31 19:53:30 +00:00
|
|
|
# some conventions.
|
|
|
|
# This scripts works for both diskfull installs, diskless boots on AIX or Linux.
|
2011-11-01 20:26:01 +00:00
|
|
|
# To use, change the settings of the following variables at the top of this script:
|
|
|
|
# $nic_num - set this to the interface number, e.g. 1 for eth1 or en1
|
|
|
|
# $netmask - the netmask that should be used when ifconfig'ing this NIC
|
2008-04-24 13:04:01 +00:00
|
|
|
|
2011-11-01 20:26:01 +00:00
|
|
|
use strict;
|
2008-04-24 13:04:01 +00:00
|
|
|
use Socket;
|
|
|
|
|
2011-11-01 20:26:01 +00:00
|
|
|
# Set these 2 variables appropriately for your cluster
|
|
|
|
my $nic_num = 1;
|
|
|
|
my $netmask = '255.255.255.0';
|
|
|
|
|
2009-03-29 18:39:34 +00:00
|
|
|
my $nic;
|
|
|
|
if ($^O =~ /^aix/i) {
|
2011-11-01 20:26:01 +00:00
|
|
|
$nic = "en$nic_num";
|
2009-03-29 18:39:34 +00:00
|
|
|
} else {
|
2011-11-01 20:26:01 +00:00
|
|
|
$nic = "eth$nic_num";
|
2009-03-29 18:39:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 20:26:01 +00:00
|
|
|
# Usually do not have to set this...
|
|
|
|
my $gateway;
|
|
|
|
#$gateway = '1.2.3.254';
|
|
|
|
|
|
|
|
# Take primary node name, add "-eth1" for linux and "-en1" for AIX and
|
|
|
|
# then reverse resolve to get what ip should be
|
2010-05-10 08:05:31 +00:00
|
|
|
sub getipaddr()
|
|
|
|
{
|
|
|
|
my ($iporhost) = @_;
|
|
|
|
|
|
|
|
my $socket6support = eval { require Socket6 };
|
|
|
|
|
|
|
|
if (($iporhost =~ /\d+\.\d+\.\d+\.\d+/) || ($iporhost =~ /:/))
|
|
|
|
{
|
|
|
|
#pass in an ip and only want an ip??
|
|
|
|
return $iporhost;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($socket6support) # the getaddrinfo and getnameinfo supports both IPv4 and IPv6
|
|
|
|
{
|
|
|
|
my ($family, $socket, $protocol, $ip, $name) = Socket6::getaddrinfo($iporhost,0);
|
|
|
|
if ($ip)
|
|
|
|
{
|
|
|
|
return (Socket6::getnameinfo($ip, Socket6::NI_NUMERICHOST()))[0];
|
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return inet_ntoa(inet_aton($iporhost))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-31 10:20:53 +00:00
|
|
|
my $host = `echo $ENV{NODE} |sed "s/-hf[0-9]//g"`;
|
|
|
|
chomp($host);
|
|
|
|
my $hostname = "$host-$nic";
|
2010-05-10 08:05:31 +00:00
|
|
|
my $ip = &getipaddr($hostname);
|
2012-05-15 03:48:00 +00:00
|
|
|
if (!$ip) { system("logger -t xcat -p local4.err 'configeth: cannot resolve $hostname.'"); exit 1; }
|
2008-04-24 13:04:01 +00:00
|
|
|
|
2009-03-29 18:39:34 +00:00
|
|
|
if ($^O =~ /^aix/i) {
|
2010-05-10 08:05:31 +00:00
|
|
|
if ($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
|
2011-10-31 10:20:53 +00:00
|
|
|
runcmd("chdev -l 'en$nic_num' -a netaddr=$ip -a netmask=$netmask -a state='up'");
|
2010-05-10 08:05:31 +00:00
|
|
|
} else { #ipv6
|
2011-10-31 10:20:53 +00:00
|
|
|
runcmd("autoconf6 -6i en$nic_num");
|
2010-05-10 08:05:31 +00:00
|
|
|
}
|
2009-03-29 18:39:34 +00:00
|
|
|
}
|
2009-02-12 14:14:05 +00:00
|
|
|
elsif (($ENV{OSVER} && ($ENV{OSVER} =~ /sles|suse/i)) || (-f "/etc/SuSE-release")) {
|
|
|
|
# Write the info to the ifcfg file
|
|
|
|
my $dir = "/etc/sysconfig/network";
|
2012-05-15 03:48:00 +00:00
|
|
|
if (!open(FILE, ">$dir/ifcfg-$nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); exit 1; }
|
2009-02-12 14:14:05 +00:00
|
|
|
# Not sure what is really REQUIRED from below -- copied the eth file from
|
|
|
|
# the system
|
|
|
|
print FILE "BOOTPROTO=\'static\'\n";
|
|
|
|
print FILE "BROADCAST=\'\'\n";
|
|
|
|
print FILE "ETHTOOL_OPTIONS=\'\'\n";
|
|
|
|
print FILE "IPADDR=\'".$ip."\'\n";
|
|
|
|
print FILE "MTU=\'\'\n";
|
|
|
|
print FILE "NAME=\'\'\n";
|
|
|
|
print FILE "NETMASK=\'".$netmask."\'\n";
|
|
|
|
print FILE "NETWORK=\'\'\n";
|
|
|
|
print FILE "REMOTE_IPADDR=\'\'\n";
|
|
|
|
print FILE "STARTMODE=\'onboot\'\n";
|
|
|
|
print FILE "UNIQUE=\'\'\n";
|
|
|
|
print FILE "USERCONTROL=\'no\'\n";
|
|
|
|
print FILE "_nm_name=\'static-0\'\n";
|
|
|
|
|
|
|
|
close FILE;
|
|
|
|
runcmd("ifup $nic");
|
|
|
|
|
|
|
|
my $nic = 'eth0';
|
|
|
|
# make file for eth0, too
|
|
|
|
if (! -f "$dir/ifcfg-$nic") {
|
|
|
|
my $hostname = "$ENV{NODE}";
|
2010-05-10 08:05:31 +00:00
|
|
|
my $ip = &getipaddr($hostname);
|
2012-05-15 03:48:00 +00:00
|
|
|
if (!$ip) { system("logger -t xcat -p local4.err 'configeth: cannot resolve $hostname.'"); exit 1; }
|
2009-02-12 14:14:05 +00:00
|
|
|
|
|
|
|
# Write the info to the ifcfg file
|
|
|
|
my $dir = "/etc/sysconfig/network";
|
2012-05-15 03:48:00 +00:00
|
|
|
if (!open(FILE, ">$dir/ifcfg-$nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); exit 1; }
|
2009-02-12 14:14:05 +00:00
|
|
|
# Not sure what is really REQUIRED from below -- copied the eth file from
|
|
|
|
# the system
|
|
|
|
print FILE "BOOTPROTO=\'static\'\n";
|
|
|
|
print FILE "BROADCAST=\'\'\n";
|
|
|
|
print FILE "ETHTOOL_OPTIONS=\'\'\n";
|
|
|
|
print FILE "IPADDR=\'".$ip."\'\n";
|
|
|
|
print FILE "MTU=\'\'\n";
|
|
|
|
print FILE "NAME=\'\'\n";
|
|
|
|
print FILE "NETMASK=\'".$netmask."\'\n";
|
|
|
|
print FILE "NETWORK=\'\'\n";
|
|
|
|
print FILE "REMOTE_IPADDR=\'\'\n";
|
|
|
|
print FILE "STARTMODE=\'onboot\'\n";
|
|
|
|
print FILE "UNIQUE=\'\'\n";
|
|
|
|
print FILE "USERCONTROL=\'no\'\n";
|
|
|
|
print FILE "_nm_name=\'static-0\'\n";
|
|
|
|
|
|
|
|
close FILE;
|
|
|
|
runcmd("ifup $nic");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Write the info to the ifcfg file
|
|
|
|
my $dir = "/etc/sysconfig/network-scripts";
|
2012-05-15 03:48:00 +00:00
|
|
|
if (!open(FILE, ">$dir/ifcfg-$nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); exit 1; }
|
2009-02-12 14:14:05 +00:00
|
|
|
print FILE "DEVICE=$nic\n";
|
|
|
|
print FILE "BOOTPROTO=none\n";
|
|
|
|
print FILE "IPADDR=$ip\n";
|
|
|
|
print FILE "NETMASK=$netmask\n";
|
2011-11-01 20:26:01 +00:00
|
|
|
if (defined($gateway)) { print FILE "GATEWAY=$gateway\n"; }
|
2009-02-12 14:14:05 +00:00
|
|
|
print FILE "ONBOOT=yes\n";
|
|
|
|
close FILE;
|
|
|
|
|
|
|
|
runcmd("$dir/ifup $nic");
|
|
|
|
}
|
2012-05-15 03:48:00 +00:00
|
|
|
system("logger -t xcat -p local4.info 'configeth: successfully configured $nic.'");
|
2008-04-24 13:04:01 +00:00
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
sub runcmd {
|
|
|
|
my $cmd = shift @_;
|
|
|
|
$cmd .= ' 2>&1';
|
|
|
|
my @output = `$cmd`;
|
|
|
|
my $rc = $? >> 8;
|
|
|
|
if ($rc) {
|
2012-05-15 03:48:00 +00:00
|
|
|
system("logger -t xcat -p local4.err 'configeth: command $cmd failed with rc $rc: " . join('',@output) . "'");
|
2011-10-31 19:53:30 +00:00
|
|
|
my $errout= "configeth: command $cmd failed with rc $rc.";
|
|
|
|
echo $errout;
|
2008-04-24 13:04:01 +00:00
|
|
|
exit $rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#$master=$ENV{MASTER};
|
|
|
|
#if ($^O =~ /^aix/i) { }
|
|
|
|
#elsif (($ENV{OSVER} && ($ENV{OSVER} =~ /fedora/i)) || (-f "/etc/fedora-release")) { }
|
|
|
|
#elsif (($ENV{OSVER} && ($ENV{OSVER} =~ /sles|suse/i)) || (-f "/etc/SuSE-release")) { }
|
|
|
|
#$result=`grep "^SYSLOG_DAEMON=" $sysconfig 2>&1`;
|
|
|
|
#`logger -t xcat "Install: syslog setup"`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|