2013-01-02 19:48:07 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
# confignics postscript for configuring additional ethernet and ib NIC adapters.
|
|
|
|
# This module parses NIC environment variables containing data from the nics table
|
|
|
|
# for the specific node i.e.:
|
|
|
|
# NICNODE - the node name
|
|
|
|
# NICIPS - comma separated list of ips per NIC
|
|
|
|
# NICHOSTNAMESUFFIXES - comma spearated list of hostname suffixes per NIC
|
|
|
|
# NICTYPES - ethernet or infiniband
|
|
|
|
# NICCUSTOMSCRIPTS - script to configure nic, i.e. configeth or configib
|
|
|
|
# NICNETWORKS - network and subnetmask for the adapter.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Socket;
|
|
|
|
|
|
|
|
my $nicips = $ENV{NICIPS};
|
|
|
|
my $niccustomscripts = $ENV{NICCUSTOMSCRIPTS};
|
|
|
|
my $nictypes = $ENV{NICTYPES};
|
|
|
|
my $xcatpostdir = "/xcatpost";
|
2013-01-09 20:25:08 +00:00
|
|
|
my %cust_script_nics = (); # hash to save nics specified in niccustomscripts
|
2013-01-09 18:55:19 +00:00
|
|
|
system("logger -t xcat -p local4.info 'confignics: CUSTOMSCRIPTS: $niccustomscripts '");
|
2013-01-02 19:48:07 +00:00
|
|
|
|
|
|
|
# niccustomscripts specifies which NICS need to be configured.
|
|
|
|
# and which script to use to configure it.
|
|
|
|
# Strip NIC and customscript and then call the custom script with the NIC
|
|
|
|
# it is up to the custom script to verify information passed in NIC env vars.
|
|
|
|
# i.e. if customscript is "eth1:configeth eth1, eth2:configeth2"
|
|
|
|
# then first get eth1 for the nic and "configeth eth1" for the command to run"
|
|
|
|
# the do the same for eth2.
|
|
|
|
|
|
|
|
if ( defined $niccustomscripts && length $niccustomscripts > 0 ) {
|
|
|
|
|
|
|
|
foreach my $customscript (split(/,/,$niccustomscripts)) {
|
|
|
|
|
2013-01-09 20:25:08 +00:00
|
|
|
my @script = ();
|
|
|
|
if ( $customscript =~ /!/ ) {
|
|
|
|
@script = split(/!/,$customscript);
|
|
|
|
} else {
|
|
|
|
@script = split(/:/,$customscript);
|
|
|
|
}
|
2013-01-09 18:55:19 +00:00
|
|
|
$cust_script_nics{$script[0]} = 1;
|
|
|
|
runcmd("$xcatpostdir/$script[1]");
|
|
|
|
system("logger -t xcat -p local4.info 'confignics: executed custom script: $script[1] '");
|
2013-01-02 19:48:07 +00:00
|
|
|
}
|
2013-01-09 18:55:19 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
# first determine nic from nicips and get the nictype. Invoke configeth or configiba based on nictype.
|
2013-01-02 19:48:07 +00:00
|
|
|
# i.e. $nictypes = "eth1:ethernet,eth2:ethernet"
|
|
|
|
foreach my $nic_type (split(/,/,$nictypes)) {
|
2013-01-09 20:25:08 +00:00
|
|
|
my @nic_and_type = ();
|
|
|
|
if ( $nic_type =~ /!/ ) {
|
|
|
|
@nic_and_type = split(/!/,$nic_type);
|
|
|
|
} else {
|
|
|
|
@nic_and_type = split(/:/,$nic_type);
|
|
|
|
}
|
2013-01-09 18:55:19 +00:00
|
|
|
if ("ETHERNET" eq uc($nic_and_type[1])) {
|
|
|
|
runcmd("$xcatpostdir/configeth $nic_and_type[0]");
|
|
|
|
system("logger -t xcat -p local4.info 'confignics: executed script: configeth $nic_and_type[0] '");
|
2013-01-02 19:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
sub runcmd {
|
|
|
|
my $cmd = shift @_;
|
|
|
|
$cmd .= ' 2>&1';
|
|
|
|
my @output = `$cmd`;
|
|
|
|
my $rc = $? >> 8;
|
|
|
|
if ($rc) {
|
|
|
|
system("logger -t xcat -p local4.err 'confignics: command $cmd failed with rc $rc: " . join('',@output) . "'");
|
|
|
|
my $errout= "confignics: command $cmd failed with rc $rc.";
|
|
|
|
# echo $errout;
|
|
|
|
exit $rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|