updates for confignics to support configib

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14949 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
billwajda 2013-01-22 19:03:07 +00:00
parent 0eccaea186
commit 825f8d742b

View File

@ -14,12 +14,54 @@
use strict;
use Socket;
# Only two args are supported for confignics:
# "-s" to allow the install nic to be configured. If not set
# then the install nic will not be configured.
# "--ibaports=x" to specify the number of ports for an ib adapter.
# This value will set in an environment variable
# prior to calling configib.
my $ibaports = 1; # default to one port per ib adapter.
my $cfg_inst_nic = '';
my $arg ='';
while ($arg = shift(@ARGV)) {
if ( $arg eq "-s" ) {
$cfg_inst_nic = 1;
} elsif ( $arg =~ /--ibaports=(\d)$/) {
$ibaports = $1;
}
}
my $ibnics = '';
my $nicips = $ENV{NICIPS};
my $niccustomscripts = $ENV{NICCUSTOMSCRIPTS};
my $nictypes = $ENV{NICTYPES};
my $installnic = $ENV{INSTALLNIC};
my $xcatpostdir = "/xcatpost";
my %cust_script_nics = (); # hash to save nics specified in niccustomscripts
system("logger -t xcat -p local4.info 'confignics: CUSTOMSCRIPTS: $niccustomscripts '");
my $type = '';
my $nic = '';
my $MAC = $ENV{MACADDRESS};
my $inst_nic = '';
# determine which ethernet nic is the installnic.
if ($installnic =~ /(e(n|th)d+)$/ ) {
$inst_nic = $1;
} elsif ($installnic eq "mac") {
# determine nic from mac. Get all NICs and their mac addresses from ifconfig
# and compare that with MACADDR.
my @ifcfg_info = split(/\n/,`ifconfig -a | grep HWaddr | awk '{print \$1,\$5;}'`);
foreach my $nic_mac (@ifcfg_info) {
my @nicmac = split(/ /,$nic_mac);
if (uc($nicmac[1]) eq uc($MAC)) {
$inst_nic = $nicmac[0];
last;
}
}
} else { # INSTALLNIC not set or is not known
system("logger -t xcat -p local4.info 'confignics: install nic $inst_nic not known '");
}
# niccustomscripts specifies which NICS need to be configured.
# and which script to use to configure it.
@ -30,6 +72,7 @@ system("logger -t xcat -p local4.info 'confignics: CUSTOMSCRIPTS: $niccustomscri
# the do the same for eth2.
if ( defined $niccustomscripts && length $niccustomscripts > 0 ) {
system("logger -t xcat -p local4.info 'confignics: processing custom scripts: $niccustomscripts '");
foreach my $customscript (split(/,/,$niccustomscripts)) {
@ -40,26 +83,92 @@ if ( defined $niccustomscripts && length $niccustomscripts > 0 ) {
@script = split(/:/,$customscript);
}
$cust_script_nics{$script[0]} = 1;
runcmd("$xcatpostdir/$script[1]");
system("logger -t xcat -p local4.info 'confignics: executed custom script: $script[1] '");
}
} else {
my @s = split(/ /,$script[1]);
# first determine nic from nicips and get the nictype. Invoke configeth or configiba based on nictype.
# i.e. $nictypes = "eth1:ethernet,eth2:ethernet"
foreach my $nic_type (split(/,/,$nictypes)) {
my @nic_and_type = ();
if ( $nic_type =~ /!/ ) {
@nic_and_type = split(/!/,$nic_type);
} else {
@nic_and_type = split(/:/,$nic_type);
}
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] '");
# if installnic then verify that "-s" flag was passed in.
if (($inst_nic ne $script[0]) || (($inst_nic eq $script[0]) && $cfg_inst_nic)) {
runcmd("$script[1]");
system("logger -t xcat -p local4.info 'confignics: executed custom script: $script[1] '");
}
}
}
# Get nic from nicips. If nic is in cust_script_nics hash then ignore this nic.
# otherwise, get nictype if set or determine type from nic name, eth* or en*
# implies ethernet, ib* implies infiniband.
#
# configib prefers to have ib adapters configured in one call for performance
# reasons. So add ib nics to a list and call configib outside the loop.
foreach my $nic_ips (split(/,/,$nicips)) {
$type = '';
my $type_found = 0;
$nic = '';
my @nic_and_ips = ();
if ( $nic_ips =~ /!/ ) {
@nic_and_ips = split(/!/,$nic_ips);
} else {
@nic_and_ips = split(/:/,$nic_ips);
}
$nic = $nic_and_ips[0];
# do not configure if nic is in the customscript hash
if ($cust_script_nics{$nic_and_ips[0]} == 1 ) {
system("logger -t xcat -p local4.info 'confignics: nic $nic_and_ips[0] already configured through custom script '");
}
else {
# Find matching type for this nic
foreach my $nic_type (split(/,/,$nictypes)) {
my @nic_and_type = ();
if ( $nic_type =~ /!/ ) {
@nic_and_type = split(/!/,$nic_type);
} else {
@nic_and_type = split(/:/,$nic_type);
}
if ($nic_and_type[0] eq $nic ) {
$type = $nic_and_type[1];
# verify type is "ethernet" or "infiniband"
if ($type =~ /ethernet|infiniband/i ) {
$type_found = 1;
}
last;
}
}
# if no matching nic type then derive nic type from nic
if ( !$type_found ) {
if ( $nic =~ /(eth|en)\d+/i ) {
$type = "ethernet";
} elsif ($nic =~ /ib\d+/i ) {
$type = "infiniband";
}
}
if ("ethernet" eq lc($type)) {
# Ensure to only configure the install nic if the "-s" flag was set.
if (($inst_nic ne $nic) || (($inst_nic eq $nic) && $cfg_inst_nic)) {
runcmd("configeth $nic");
system("logger -t xcat -p local4.info 'confignics: executed script: configeth $nic '");
}
else {
system("logger -t xcat -p local4.info 'confignics: Not configuring install nic $nic '");
}
} elsif ("infiniband" eq lc($type)) {
if ($ibnics) {
$ibnics = $ibnics . "," . $nic;
} else {
$ibnics = $nic;
}
} else {
system("logger -t xcat -p local4.info 'confignics: unknown type $type for NIC: $nic '");
}
}
}
# Call configib now to configure all ib adapters in one call.
if ($ibnics) {
runcmd("NIC_IBNICS=$ibnics NIC_IBAPORTS=$ibaports configib");
system("logger -t xcat -p local4.info 'confignics: executed script: configib for nics $ibnics '");
}
exit 0;
sub runcmd {
@ -70,8 +179,9 @@ sub runcmd {
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;
print $errout;
exit $rc;
}
print join("\n",@output),"\n";
}