From 3ddce5fb90df4dac45d982ecd042f068ac7e907f Mon Sep 17 00:00:00 2001 From: bp-sawyers Date: Mon, 29 Jul 2013 15:36:37 +0000 Subject: [PATCH 01/11] Update bld script for different git branches git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.8@17035 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- buildcore.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/buildcore.sh b/buildcore.sh index c374d91c4..0a2db354b 100755 --- a/buildcore.sh +++ b/buildcore.sh @@ -18,8 +18,8 @@ # - Run this script from the local svn repository you just created. It will create the other # directories that are needed. -# Usage: buildcore.sh BRANCH= [attr=value attr=value ...] -# BRANCH= - the branch within the git repo that should be built. This arg is required for git. +# Usage: buildcore.sh [attr=value attr=value ...] +# Before running buildcore.sh, you must change the local git repo to the branch you want built, using: git checkout # PROMOTE=1 - if the attribute "PROMOTE" is specified, means an official dot release. This does not # actually build xcat, just uploads the most recent snap build to https://sourceforge.net/projects/xcat/files/xcat/ . # If not specified, a snap build is assumed, which uploads to https://sourceforge.net/projects/xcat/files/yum/ @@ -70,10 +70,6 @@ if [ -z "$REL" ]; then D=${curdir%/src/xcat-core} REL=`basename $D` fi -if [ "$REL" = "xcat-core" -a -z "$BRANCH" ]; then # using git but they didnt specify BRANCH - echo "Error: must specify BRANCH= when building a git repository. Exiting...." - exit 1 -fi OSNAME=$(uname) if [ "$OSNAME" != "AIX" ]; then @@ -155,11 +151,10 @@ else #echo "source=$source" fi -# for the git case, set the current branch and also set REL (changing master to devel if necessary) +# for the git case, query the current branch and set REL (changing master to devel if necessary) function setbranch { - git checkout $BRANCH - #REL=`git rev-parse --abbrev-ref HEAD` - REL=$BRANCH + #git checkout $BRANCH + REL=`git rev-parse --abbrev-ref HEAD` if [ "$REL" = "master" ]; then REL="devel" fi From 4bd8a0e02005761e63324af4589799a1c361c06a Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 29 Jul 2013 13:56:39 -0400 Subject: [PATCH 02/11] Update version to the next release --- Version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Version b/Version index 1817afea4..9f8d8a916 100644 --- a/Version +++ b/Version @@ -1 +1 @@ -2.8.2 +2.8.3 From d3bf022de78e3ffc2d28cac8a79982bec10fa11d Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 29 Jul 2013 13:56:39 -0400 Subject: [PATCH 03/11] Update version to the next release --- Version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Version b/Version index 1817afea4..9f8d8a916 100644 --- a/Version +++ b/Version @@ -1 +1 @@ -2.8.2 +2.8.3 From 811a3eda654a8ef22b9e080fcdd47de104c364fa Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 29 Jul 2013 14:07:02 -0400 Subject: [PATCH 04/11] Fix for defect 3717 --- perl-xCAT/xCAT/DSHCLI.pm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/perl-xCAT/xCAT/DSHCLI.pm b/perl-xCAT/xCAT/DSHCLI.pm index adede62a8..ecd6de7c8 100644 --- a/perl-xCAT/xCAT/DSHCLI.pm +++ b/perl-xCAT/xCAT/DSHCLI.pm @@ -1024,7 +1024,7 @@ sub fork_fanout_dsh && (keys(%$targets_active) < $$options{'fanout'})) { my $user_target = shift @$targets_waiting; - # now add export NODE=nodename to the pre-command if not a device; + # now add export NODE=nodename to the pre-command, if not a device; my $exportnode; if (($$options{'devicetype'})) { $exportnode=""; @@ -2345,10 +2345,14 @@ sub config_dsh } } else + { + # if not Mellanox, it does not need a config file + if (!($$options{'devicetype'} =~ /Mellanox/i)) { my $rsp = {}; - $rsp->{error}->[0] = "EMsgMISSING_DEV_CFG"; - xCAT::MsgUtils->message('E', $rsp, $::CALLBACK); + $rsp->{error}->[0] = "The config file: $devicepath is missing"; + xCAT::MsgUtils->message('E', $rsp, $::CALLBACK); + } } } @@ -5782,8 +5786,10 @@ sub bld_and_run_append # that were rsyn'd to at least one node if ($tmpappendfile eq $ps) { my $parm="$appendfile:$filetoappend "; - - $::xdcpappendparms .= $parm; + # check to see if the parameter is already in the list + if (!($::xdcpappendparms =~ /$parm/)) { + $::xdcpappendparms .= $parm; + } $processappend=1; } @@ -5919,8 +5925,10 @@ sub bld_and_run_merge # that were rsyn'd to at least one node if ($tmpmergefile eq $ps) { my $parm="$mergefile:$filetomerge "; - - $::xdcpmergeparms .= $parm; + # check to see if the parameter is already in the list + if (!($::xdcpmergeparms =~ /$parm/)) { + $::xdcpmergeparms .= $parm; + } $processmerge=1; } From f52348bc1af2ff804e6bf11cdc5d44e2f19fa3c6 Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 29 Jul 2013 13:56:39 -0400 Subject: [PATCH 05/11] Update version to the next release --- Version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Version b/Version index 1817afea4..9f8d8a916 100644 --- a/Version +++ b/Version @@ -1 +1 @@ -2.8.2 +2.8.3 From 016a94742824cf1c4eb06c9a6a2ec6913c45a60d Mon Sep 17 00:00:00 2001 From: daniceexi Date: Wed, 31 Jul 2013 07:05:18 -0400 Subject: [PATCH 06/11] Change the insert_dd function for handling the initrd hacking. --- xCAT-server/lib/xcat/plugins/anaconda.pm | 43 ++++++++++----- xCAT-server/lib/xcat/plugins/geninitrd.pm | 4 ++ xCAT-server/lib/xcat/plugins/sles.pm | 67 +++++++++++++---------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index e836eed19..524c8bbad 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -2512,19 +2512,26 @@ sub insert_dd { } elsif ( grep (/LZMA compressed data/, @format)) { $initrdfmt = "lzma"; } else { - my $rsp; - push @{$rsp->{data}}, "Could not handle the format of the initrd."; - xCAT::MsgUtils->message("E", $rsp, $callback); - return (); + # check whether it can be handled by xz + $cmd = "xz -t $img"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) { + my $rsp; + push @{$rsp->{data}}, "Could not handle the format of the initrd."; + xCAT::MsgUtils->message("E", $rsp, $callback); + return (); + } else { + $initrdfmt = "lzma"; + } } if ($initrdfmt eq "gzip") { $cmd = "gunzip -c $img > $dd_dir/initrd"; } elsif ($initrdfmt eq "lzma") { - if (! -x "/usr/bin/lzma") { + if (! -x "/usr/bin/xz") { my $rsp; - push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not lzma command."; + push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not xz command."; xCAT::MsgUtils->message("E", $rsp, $callback); return (); } @@ -2698,7 +2705,7 @@ sub insert_dd { xCAT::Utils->runcmd($cmd, -1); if ($::RUNCMD_RC != 0) { my $rsp; - push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the depdency for the drivers in the initrd."; + push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the drivers depdency for $kernelver in the initrd."; xCAT::MsgUtils->message("I", $rsp, $callback); } } @@ -3004,7 +3011,7 @@ sub insert_dd { if ($initrdfmt eq "gzip") { $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|gzip -9 -c - > $dd_dir/initrd.img"; } elsif ($initrdfmt eq "lzma") { - $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|lzma -C crc32 -9 > $dd_dir/initrd.img"; + $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|xz --format=lzma -C crc32 -9 > $dd_dir/initrd.img"; } xCAT::Utils->runcmd($cmd, -1); @@ -3072,13 +3079,23 @@ sub insert_dd { my $rsp; if (@dd_list) { - push @{$rsp->{data}}, "Inserted the driver update disk:".join(',',@inserted_dd)."."; + push @{$rsp->{data}}, "The driver update disk:".join(',',@inserted_dd)." have been injected to initrd."; } - if (@driver_list) { - push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages."; - } elsif (@rpm_list && ($Injectalldriver || @driver_list)) { - push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list))."."; + # remove the duplicated names + my %dnhash; + foreach (@rpm_drivers) { + $dnhash{$_} = 1; } + @rpm_drivers = keys %dnhash; + + if (@rpm_list) { + if (@driver_list) { + push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd."; + } elsif ($Injectalldriver) { + push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd."; + } + } + xCAT::MsgUtils->message("I", $rsp, $callback); return @inserted_dd; diff --git a/xCAT-server/lib/xcat/plugins/geninitrd.pm b/xCAT-server/lib/xcat/plugins/geninitrd.pm index ec13e052a..a364a6210 100644 --- a/xCAT-server/lib/xcat/plugins/geninitrd.pm +++ b/xCAT-server/lib/xcat/plugins/geninitrd.pm @@ -7,6 +7,7 @@ BEGIN use strict; use lib "$::XCATROOT/lib/perl"; +use File::Path; use File::Copy; use xCAT::MsgUtils; use xCAT::TableUtils; @@ -127,6 +128,9 @@ sub geninitrd { $tftpdir = $t_entry; } my $tftppath = "$tftpdir/xcat/osimage/$osimage"; + unless (-d $tftppath) { + mkpath $tftppath; + } if ($arch =~ /x86/) { if ($osvers =~ /(^ol[0-9].*)|(centos.*)|(rh.*)|(fedora.*)|(SL.*)/) { $kernelpath = "$tftppath/vmlinuz"; diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index 75d31229b..b2e9cf4c1 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -1802,9 +1802,9 @@ sub insert_dd () { } # get the new kernel if it exists in the update distro - my @new_kernels = <$dd_dir/rpm/boot/vmlinuz*>; + my @new_kernels = <$dd_dir/rpm/boot/vmlinu*>; foreach my $new_kernel (@new_kernels) { - if (-r $new_kernel && $new_kernel =~ /\/vmlinuz-(.*(x86_64|ppc64))$/) { + if (-r $new_kernel && $new_kernel =~ /\/vmlinu[zx]-(.*(x86_64|ppc64|default))$/) { $new_kernel_ver = $1; $cmd = "/bin/mv -f $new_kernel $dd_dir/rpm/newkernel"; xCAT::Utils->runcmd($cmd, -1); @@ -1928,34 +1928,32 @@ sub insert_dd () { } } } # end of loading drivers from rpm packages - } - # Create the dir for driver update disk - mkpath("$dd_dir/initrd_img/cus_driverdisk"); + # Create the dir for driver update disk + mkpath("$dd_dir/initrd_img/cus_driverdisk"); - # insert the driver update disk into the cus_driverdisk dir - foreach my $dd (@dd_list) { - copy($dd, "$dd_dir/initrd_img/cus_driverdisk"); - } + # insert the driver update disk into the cus_driverdisk dir + foreach my $dd (@dd_list) { + copy($dd, "$dd_dir/initrd_img/cus_driverdisk"); + } - # Repack the initrd - # In order to avoid the runcmd add the '2>&1' at end of the cpio - # cmd, the echo cmd is added at the end - $cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo"; - xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC != 0) { - my $rsp; - push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd."; - xCAT::MsgUtils->message("E", $rsp, $callback); - return (); - } + # Repack the initrd + # In order to avoid the runcmd add the '2>&1' at end of the cpio + # cmd, the echo cmd is added at the end + $cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) { + my $rsp; + push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd."; + xCAT::MsgUtils->message("E", $rsp, $callback); + return (); + } - # zip the initrd - #move ("$dd_dir/initrd.new", "$dd_dir/initrd"); - $cmd = "gzip -f $dd_dir/initrd"; - xCAT::Utils->runcmd($cmd, -1); + # zip the initrd + #move ("$dd_dir/initrd.new", "$dd_dir/initrd"); + $cmd = "gzip -f $dd_dir/initrd"; + xCAT::Utils->runcmd($cmd, -1); - if ($arch =~/ppc/ || (@rpm_list && ($Injectalldriver || @driver_list))) { if ($arch =~/ppc/) { if (-r "$dd_dir/rpm/newkernel") { # if there's new kernel from update distro, then use it @@ -1999,12 +1997,21 @@ sub insert_dd () { my $rsp; if (@dd_list) { - push @{$rsp->{data}}, "Inserted the driver update disk:".join(',', sort(@dd_list))."."; + push @{$rsp->{data}}, "The driver update disk:".join(',',@dd_list)." have been injected to initrd."; } - if (@driver_list) { - push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages."; - } elsif (@rpm_list && ($Injectalldriver || @driver_list)) { - push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list))."."; + # remove the duplicated names + my %dnhash; + foreach (@rpm_drivers) { + $dnhash{$_} = 1; + } + @rpm_drivers = keys %dnhash; + + if (@rpm_list) { + if (@driver_list) { + push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd."; + } elsif ($Injectalldriver) { + push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd."; + } } xCAT::MsgUtils->message("I", $rsp, $callback); From dab5a33b3f5b40b2ad2c09c9023371d9a59ca44a Mon Sep 17 00:00:00 2001 From: immarvin Date: Thu, 1 Aug 2013 01:23:45 -0700 Subject: [PATCH 07/11] fix defect 3724 makehosts should report error/warning messages when entrys in hosts table are not correct --- xCAT-server/lib/xcat/plugins/hosts.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/hosts.pm b/xCAT-server/lib/xcat/plugins/hosts.pm index c5d34d775..d5e100f5b 100644 --- a/xCAT-server/lib/xcat/plugins/hosts.pm +++ b/xCAT-server/lib/xcat/plugins/hosts.pm @@ -254,6 +254,12 @@ sub add_hosts_content { { addnode $callback, $nodename, $ip, $ref->{hostnames}, $domain; } + else + { + my $rsp; + push @{$rsp->{data}}, "Invalid IP Addr \'$_->{ip}\' for node \'$_->{node}\'."; + xCAT::MsgUtils->message("E", $rsp, $callback); + } if (defined($ref->{otherinterfaces})) { addotherinterfaces $callback, $nodename, $ref->{otherinterfaces}, $domain; From a81d66c1240a5b72634ce1517d39e4cdd2831532 Mon Sep 17 00:00:00 2001 From: linggao Date: Thu, 1 Aug 2013 12:07:30 -0400 Subject: [PATCH 08/11] add tabdump -n for auditlog and eventlog --- xCAT-server/lib/xcat/plugins/tabutils.pm | 120 ++++++++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 36d91dc8b..9cf8b00fc 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -558,6 +558,7 @@ sub tabdump my $OPTW; my $VERSION; my $FILENAME; + my $NUMBERENTRIES; my $tabdump_usage = sub { my $exitcode = shift @_; @@ -565,6 +566,7 @@ sub tabdump push @{$rsp{data}}, "Usage: tabdump [-d] [table]"; push @{$rsp{data}}, " tabdump [table]"; push @{$rsp{data}}, " tabdump [-f ] [table]"; + push @{$rsp{data}}, " tabdump [-n <# of records>] [auditlog | eventlog]"; push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [table]"; push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [-f ] [table]"; push @{$rsp{data}}, " tabdump [-?|-h|--help]"; @@ -578,10 +580,14 @@ sub tabdump if ($args) { @ARGV = @{$args}; } + Getopt::Long::Configure("posix_default"); + Getopt::Long::Configure("no_gnu_compat"); + Getopt::Long::Configure("bundling"); if (!GetOptions( 'h|?|help' => \$HELP, 'v|version' => \$VERSION, + 'n|lines=i' => \$NUMBERENTRIES, 'd' => \$DESC, 'f=s' => \$FILENAME, 'w=s@' => \$OPTW, @@ -601,8 +607,23 @@ sub tabdump if ($HELP) { $tabdump_usage->(0); return; } + if (($NUMBERENTRIES) && ($DESC)) { + $cb->({error => "You cannot use the -n and -d flag together. ",errorcode=>1}); + return 1; + } + + if (($NUMBERENTRIES) && ($OPTW)) { + $cb->({error => "You cannot use the -n and -w flag together. ",errorcode=>1}); + return 1; + } + if (($NUMBERENTRIES) && ($FILENAME)) { + $cb->({error => "You cannot use the -n and -f flag together. ",errorcode=>1}); + return 1; + } + if (scalar(@ARGV)>1) { $tabdump_usage->(1); return; } + my %rsp; # If no arguments given, we display a list of the tables if (!scalar(@ARGV)) { @@ -626,9 +647,18 @@ sub tabdump } # get the table name $table = $ARGV[0]; + + # if -n can only be the auditlog or eventlog + if ($NUMBERENTRIES) { + if (!( $table =~ /^auditlog/ ) && (!($table =~ /^eventlog/))){ + $cb->({error => "$table table is not supported in tabdump -n. You may only use this option on the auditlog or the eventlog.",errorcode=>1}); + return 1; + } + } + # do not allow teal tables if ( $table =~ /^x_teal/ ) { - $cb->({error => "$table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1}); + $cb->({error => "$table table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1}); return 1; } if ($DESC) { # only show the attribute descriptions, not the values @@ -665,6 +695,15 @@ sub tabdump $cb->({error => "No such table: $table",errorcode=>1}); return 1; } + # + # if tabdump -n auditlog|eventlog + # + if (defined $NUMBERENTRIES ) { + my $rc=tabdump_numberentries($table,$cb,$NUMBERENTRIES); + return $rc; + } + + my $recs; my @ents; my @attrarray; @@ -717,6 +756,81 @@ sub tabdump } } } +# +# display input number of records for the table requested tabdump -n +# +sub tabdump_numberentries { + my $table = shift; + my $cb = shift; + my $numberentries = shift; # either number of records to display + my $attrrecid="recid"; + + my $VERBOSE = shift; + my $rc=0; + my $tab = xCAT::Table->new($table); + unless ($tab) { + $cb->({error => "Unable to open $table",errorcode=>4}); + return 1; + } + my $DBname = xCAT::Utils->get_DBName; + my @attribs = ($attrrecid); + my @ents=$tab->getAllAttribs(@attribs); + if (@ents) { # anything to process + # find smallest and largest recid, note table is not ordered by recid after + # a while + my $smallrid; + my $largerid; + foreach my $rid (@ents) { + if (!(defined $smallrid)) { + $smallrid=$rid; + } + if (!(defined $largerid)) { + $largerid=$rid; + } + if ($rid->{$attrrecid} < $smallrid->{$attrrecid}) { + $smallrid=$rid; + } + if ($rid->{$attrrecid} > $largerid->{$attrrecid}) { + $largerid=$rid; + } + } + my $RECID; + #determine recid to show all records after + $RECID= $largerid->{$attrrecid} - $numberentries ; + $rc=tabdump_recid($table,$cb,$RECID, $attrrecid); + } else { + my %rsp; + push @{$rsp{data}}, "Nothing to display from $table."; + $rsp{errorcode} = $rc; + $cb->(\%rsp); + } + return $rc; +} +# Display requested recored +# if rec id does not exist error +sub tabdump_recid { + my $table = shift; + my $cb = shift; + my $recid = shift; + my $rc=0; + # check which database so can build the correct Where clause + my $tab = xCAT::Table->new($table); + unless ($tab) { + $cb->({error => "Unable to open $table",errorcode=>4}); + return 1; + } + my $DBname = xCAT::Utils->get_DBName; + my @recs; + my $attrrecid="recid"; + # display the output + if ($DBname =~ /^DB2/) { + @recs=$tab->getAllAttribsWhere("\"$attrrecid\">$recid", 'ALL'); + } else { + @recs=$tab->getAllAttribsWhere("$attrrecid>$recid", 'ALL'); + } + output_table($table,$cb,$tab,\@recs); + return $rc; +} # Display information from the daemon. # sub lsxcatd @@ -853,7 +967,7 @@ sub tabprune push @{$rsp{data}}, " tabprune [-V] -d <# of days>"; push @{$rsp{data}}, " tabprune [-h|--help]"; push @{$rsp{data}}, " tabprune [-v|--version]"; - push @{$rsp{data}}, " tables supported:eventlog,auditlog,isnm_perf,isnm_perf_sum"; + push @{$rsp{data}}, " tables supported:eventlog,auditlog"; push @{$rsp{data}}, " -d option only supported for eventlog,auditlog"; if ($exitcode) { $rsp{errorcode} = $exitcode; } $cb->(\%rsp); @@ -952,7 +1066,7 @@ sub tabprune if (($table eq "eventlog") || ($table eq "auditlog")) { $attrrecid="recid"; } else { - if ($table eq "isnm_perf") { # if ISNM + if ($table eq "isnm_perf") { # if ISNM These tables are really not supported in 2.8 or later $attrrecid="perfid"; } else { $attrrecid="period"; # isnm_perf_sum table From 4a91bb39ccdf569edc57555dd2dc3a2f2d93900f Mon Sep 17 00:00:00 2001 From: linggao Date: Thu, 1 Aug 2013 12:17:05 -0400 Subject: [PATCH 09/11] document tabdump -n --- xCAT-client/pods/man8/tabdump.8.pod | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/xCAT-client/pods/man8/tabdump.8.pod b/xCAT-client/pods/man8/tabdump.8.pod index bcac4eed1..63b39e26f 100644 --- a/xCAT-client/pods/man8/tabdump.8.pod +++ b/xCAT-client/pods/man8/tabdump.8.pod @@ -10,6 +10,8 @@ B [I] B [I<-f> I] [I
] +B [I<-n> I<# of records>] [I] + B [I<-w> I==I] [B<-w> I=~I] ...] [I
] B [I<-w> I==I] [B<-w> I=~I] ...] [I<-f> I] [I
] @@ -38,6 +40,15 @@ Display usage message. Show descriptions of the tables, instead of the contents of the tables. If a table name is also specified, descriptions of the columns (attributes) of the table will be displayed. Otherwise, a summary of each table will be displayed. +=item B<-n> + +Shows the most recent number of entries as supplied on the -n flag from the auditlog or eventlog table. + +=item B<-f> + +File name or path to file in which to dump the table. Without this the table is dumped +to stdout. Using the -f flag allows the table to be dumped one record at a time. If tables are very large, dumping to stdout can cause problems such as running out of memory. + =item B<-w> I<'attr==val'> B<-w> I<'attr=~val'> ... Use one or multiple -w flags to specify the selection string that can be used to select particular rows of the table. See examples. @@ -54,11 +65,6 @@ Operator descriptions: !~ Select nodes where the attribute value matches the SQL NOT LIKE value. -=item B<-f> - -File name or path to file in which to dump the table. Without this the table is dumped -to stdout. Using the -f flag allows the table to be dumped one record at a time. If tables are very large, dumping to stdout can cause problems such as running out of memory. - =back =head1 RETURN VALUE @@ -111,6 +117,12 @@ tabdump -w 'audittime>2011-04-18 11:30:00' auditlog =item * +To display the 10 most recent entries in the auditlog: + +tabdump -n 10 auditlog + +=item * + To see what tables exist in the xCAT database: B From df9fa2b101814ef0f1a7c4b33760c23911db7e60 Mon Sep 17 00:00:00 2001 From: immarvin Date: Thu, 1 Aug 2013 19:26:14 -0700 Subject: [PATCH 10/11] fix defect 3722: replace die with MsgUtils->message and exit --- xCAT-client/bin/rinstall | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/xCAT-client/bin/rinstall b/xCAT-client/bin/rinstall index 13a17910d..8ae0627f9 100755 --- a/xCAT-client/bin/rinstall +++ b/xCAT-client/bin/rinstall @@ -19,9 +19,11 @@ BEGIN use lib "$::XCATROOT/lib/perl"; use File::Basename; use Getopt::Long; +use xCAT::MsgUtils; use xCAT::Table; use xCAT::NodeRange; + sub usage { print basename($0)." usage:\n"; print " ".basename($0)." [-o|--osver] [-p|--profile] [-a|--arch] [-O|--osimage] [-c|--console] \n" @@ -83,7 +85,10 @@ if($OSIMAGE){ &checkoption("[-O|--osimage] $OSIMAGE"); $rc=system("nodeset $noderange osimage=$OSIMAGE"); - if ($rc) { die "nodeset failure" }; + if ($rc) { + xCAT::MsgUtils->message("E","nodeset failure"); + exit 1; + }; }else { @@ -161,7 +166,8 @@ if($OSIMAGE){ } if($rc){ - die "nodeset failure"; + xCAT::MsgUtils->message("E","nodeset failure"); + exit 1; } # call "rsetboot" to set the boot order of the nodehm.mgt=ipmi nodes,for others, assume user has set the correct boot order before "rinstall" @@ -169,7 +175,10 @@ system("rsetboot $noderange net"); # call "rpower" to start the node provision process $rc=system("rpower $noderange boot"); -if ($rc) { die "rpower failure" }; +if ($rc) { + xCAT::MsgUtils->message("E","rpower failure"); + exit 1; +}; if (basename($0) =~ /rinstall/) { @@ -177,7 +186,8 @@ if (basename($0) =~ /rinstall/) { # for rinstall, the -c|--console option can provide the remote console for only 1 node if ($CONSOLE) { if(scalar @allnodes ne 1){ - die "rinstall [-c|--console] will only work if there is only one node in the noderange. See winstall(8) for consoles on multiple systems"; + xCAT::MsgUtils->message("rinstall [-c|--console] will only work if there is only one node in the noderange. See winstall(8) for consoles on multiple systems"); + exit 1; } exec("rcons $noderange"); } From bf183224c7424732ef245e00bb3b0be6df60a96d Mon Sep 17 00:00:00 2001 From: xq2005 Date: Fri, 2 Aug 2013 03:14:45 -0700 Subject: [PATCH 11/11] transfer the confignics and configeth to shell --- xCAT/postscripts/configeth | 1398 ++++++++++++++++------------------- xCAT/postscripts/confignics | 707 +++++------------- xCAT/postscripts/xcatlib.sh | 17 + 3 files changed, 837 insertions(+), 1285 deletions(-) create mode 100644 xCAT/postscripts/xcatlib.sh diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 06d76bb62..22d633c5d 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -1,808 +1,666 @@ -#!/usr/bin/perl -# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#!/bin/bash +str_dir_name=`dirname $0` -# xCAT post script for configuring additional ethernet nics. Information is -# retreieved from nics table. Environment variables are set in the postscript -# The nic (i.e. eth1, en1) is passed as the only argument. -# Environment variables are set in the postscript in the mypostscript.tmpl -# file on the management node: -# -# -# NICNODE - the name of the node minus the NICHOSTNAMESUFFIXES -# NICIPS - the ip address for this nic -# NICTYPES - for configeth - this must be ethernet -# NICCUSTOMSCRIPTS - parsed in confignics to invoke this script if set. (not used here) -# NICNETWORKS - the network this nic is attached to. Must also verify this network is -# set in the networks table. +. $str_dir_name/xcatlib.sh -use strict; -use Socket; -use File::Copy; -use File::Path; - -#process arguments. Currently supported arguments are: -# -c nics_to_configure, -# -u nics_to_unconfigure -# Both arguments are comma separated list of nics, i.e. eth0,eth1,ib0,ib1 -# it is possible that only -u may be specified to unconfigure nics and there will be no -# nics to configure. Likewise, there may be nics to configure but not nics to unconfigure. -my $nics = ''; -my $rm_nics = ''; -my $a; -while ($a = shift(@ARGV)) { - if ($a eq "-c") { - $a = shift(@ARGV); - if (!$a || $a=~/^-/) { - # no arg specified for -c - system("logger -t xcat -p local4.err 'configeth: No argument specified for -c flag'"); - exit 1; - } - else { - $nics = $a; - } - } - elsif ($a eq "-u") { - $a = shift(@ARGV); - if (!$a || $a=~/^-/) { - # no arg specified for -c - system("logger -t xcat -p local4.err 'configeth: No argument specified for -c flag'"); - exit 1; - } - else { - $rm_nics = $a; - } - } +#tranfer the netmask to prefix for ipv4 +function v4mask2prefix(){ + local num_bits=0 + local old_ifs=$IFS + IFS=$'.' + local array_num_temp=($1) + IFS=$old_ifs + for num_dec in ${array_num_temp[@]} + do + case $num_dec in + 255) let num_bits+=8;; + 254) let num_bits+=7;; + 253) let num_bits+=6;; + 248) let num_bits+=5;; + 240) let num_bits+=4;; + 224) let num_bits+=3;; + 192) let num_bits+=2;; + 128) let num_bits+=1;; + 0) ;; + *) echo "Error: $dec is not recognised"; exit 1 + esac + done + echo "$num_bits" } -if ( !$nics && !$rm_nics ) { - system("logger -t xcat -p local4.err 'configeth: incorrect argument specified for -c flag'"); - exit 1; +function configipv4(){ + str_if_name=$1 + str_v4ip=$2 + str_v4net=$3 + str_v4mask=$4 + num_v4num=$5 + + if [ "$str_os_type" = "sles" ];then + str_conf_file="/etc/sysconfig/network/ifcfg-${str_if_name}" + if [ $num_v4num -eq 0 ];then + echo "DEVICE=${str_if_name}" > $str_conf_file + echo "BOOTPROTO=static" >> $str_conf_file + echo "BROADCAST=" >> $str_conf_file + echo "ETHTOOL_OPTIONS=" >> $str_conf_file + echo "IPADDR=${str_v4ip}" >> $str_conf_file + echo "MTU=" >> $str_conf_file + echo "NAME=" >> $str_conf_file + echo "NETMASK=${str_v4mask}" >> $str_conf_file + echo "NETWORK=${str_v4net}" >> $str_conf_file + echo "REMOTE_IPADDR=" >> $str_conf_file + echo "STARTMODE=onboot" >> $str_conf_file + echo "UNIQUE=" >> $str_conf_file + echo "USERCONTROL=no" >> $str_conf_file + echo "_nm_name=static-0" >> $str_conf_file + else + echo "IPADDR_${num_v4num}=${str_v4ip}" >> $str_conf_file + echo "NETMASK_${num_v4num}=${str_v4mask}" >> $str_conf_file + echo "NETWORK_${num_v4num}=${str_v4net}" >> $str_conf_file + echo "LABEL_${num_v4num}=${num_v4num}" >> $str_conf_file + fi + #debian ubuntu + elif [ "$str_os_type" = "debian" ];then + str_conf_file="/etc/network/interfaces.d/${str_if_name}" + if [ $num_v4num -eq 0 ];then + echo "auto ${str_if_name}" > $str_conf_file + echo "iface ${str_if_name} inet static" >> $str_conf_file + else + echo "auto ${str_if_name}:${num_v4num}" >> $str_conf_file + echo "iface ${str_if_name}:${num_v4num} inet static" >> $str_conf_file + fi + echo " address ${str_v4ip}" >> $str_conf_file + echo " netmask ${str_v4mask}" >> $str_conf_file + echo " network ${str_v4net}" >> $str_conf_file + else + # Write the info to the ifcfg file for redhat + str_conf_file="" + if [ $num_v4num -eq 0 ];then + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" + echo "DEVICE=${str_if_name}" > $str_conf_file + else + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}:${num_v4num}" + echo "DEVICE=${str_if_name}:${num_v4num}" > $str_conf_file + fi + + echo "BOOTPROTO=none" >> $str_conf_file + echo "NM_CONTROLLED=no" >> $str_conf_file + echo "IPADDR=${str_v4ip}" >> $str_conf_file + echo "NETMASK=${str_v4mask}" >> $str_conf_file + echo "ONBOOT=yes" >> $str_conf_file + fi } -my $nicips = $ENV{NICIPS}; -my $nicnetworks = $ENV{NICNETWORKS}; -my $nicnode = $ENV{NICNODE}; -my $net_cnt = $ENV{NETWORKS_LINES}; +configipv6(){ + str_if_name=$1 + str_v6ip=$2 + str_v6net=$3 + str_v6prefix=$4 + num_v6num=$5 + num_v4num=$6 + str_v6gateway=$7 -my $cfg_nic_ref_hash = {}; # set from get_install_nic + #remove the prefix length from the subnet + str_v6net=`echo $str_v6net | cut -d"/" -f 1` -my $netmask =''; -my $ipaddr = ''; -my $nic_num = ''; -my $subnet = ''; -my $gateway = ''; # this is only used for ipv6, ipv4 gateway is assigned by dhcp -my $ipv4nic = 0; -my $nic_net = ''; -my $net_name = ''; -my @nic_nets_all = (); # array of all networks for this nic -my @nic_nets4 = (); # array of ipv4 networks for this nic -my @nic_nets6 = (); # array of ipv6 networks for this nic -my @nic_ips_all =(); # array of all ip addresses for this nic -my @nic_ips4 =(); # array of ipv4 addresses for this nic -my @nic_ips6 =(); # array of ipv6 addresses for this nic -my @networks = (); # array of all networks from networks table. - # { network_name, subnet, netmask } + #remove the "/" from mask + str_v6prefix=`echo $str_v6prefix | sed 's/\///'` -system("logger -t xcat -p local4.err 'configeth: NICS: $nics'"); -system("logger -t xcat -p local4.err 'configeth: REMOVE_NICS: $rm_nics'"); -system("logger -t xcat -p local4.err 'configeth: NICNETWORKS: $nicnetworks'"); -system("logger -t xcat -p local4.err 'configeth: NICIPS: $nicips'"); - -# First process nics that need to be removed. -if ($rm_nics) { - my $i; - my @nics_rm = split(/,/, $rm_nics); - for ($i=0; $i < (scalar @nics_rm); $i++) { - if ($^O =~ /^aix/i) { - # Still need to figure out AIX command ifconfig down and remove (chdev ?) interface - # Start by looking at the same command that configures. - } - elsif (($ENV{OSVER} && ($ENV{OSVER} =~ /sles|suse/i)) || (-f "/etc/SuSE-release")) { - # on suse/sles ip aliases go in the same file as the base. Need to remove lines - # specific to the aliases after taking the interface down. - - runcmd("ifdown $nics_rm[$i]"); - - # update or remove config file. - my $dir = "/etc/sysconfig/network"; - # just move nic file to file.old - `mv $dir/ifcfg-$nics_rm[$i] $dir/ifcfg-$nics_rm[$i].old >/dev/null 2>&1`; - - } - elsif ( -f "/etc/debian_version" ){ - runcmd("ifdown --force $nics_rm[$i]"); - if ( -e "/etc/network/interfaces.d/$nics_rm[$i]" ){ - runcmd("rm -f /etc/network/interfaces.d/${nics_rm[$i]}"); - runcmd("rm -f /etc/network/interfaces.d/${nics_rm[$i]}:*"); - } - } - else { - # OS is redhat. - # Note that the ifdown command will fail if the configuration file does not exist - # in the /etc/sysconfig/network-scripts directory. Therefore check that the - # nic config file exists prior to ifdown. Otherwise the nic is already deconfigured. - - my $dir = "/etc/sysconfig/network-scripts"; - if (-e "$dir/ifcfg-$nics_rm[$i]") { - - runcmd("ifdown $nics_rm[$i]"); - - # For now remove all aliased files - i.e. nic_name:1) - my $aliases = "$dir/ifcfg-$nics_rm[$i]:*"; - my @files = glob($aliases); - unlink @files; - - # Remove base config file. - $aliases = "$dir/ifcfg-$nics_rm[$i]"; - @files = glob($aliases); - unlink @files; - } - } - } + if [ "$str_os_type" = "sles" ];then + str_conf_file="/etc/sysconfig/network/ifcfg-${str_if_name}" + if [ $num_v4num -eq 0 -a $num_v6num -eq 0 ];then + echo "DEVICE=$str_if_name" > $str_conf_file + echo "BOOTPROTO=static" >> $str_conf_file + echo "NM_CONTROLLED=no" >> $str_conf_file + echo "STARTMODE=onboot" >> $str_conf_file + fi + echo "LABEL_ipv6${num_v6num}=ipv6$num_v6num" >> $str_conf_file + echo "IPADDR_ipv6${num_v6num}=${str_v6ip}" >> $str_conf_file + echo "PREFIXLEN_ipv6${num_v6num}=${str_v6prefix}" >> $str_conf_file + if [ `echo $str_v6gateway | grep -v 'xcatmaster'` ];then + grep -E "default[:space:]+${str_v6gateway}[:space:]+" /etc/sysconfig/network/routes 2>&1 1>/dev/null + if [ $? -ne 0 ];then + echo "default $str_v6gateway - -" >> /etc/sysconfig/network/routes + fi + fi + elif [ "$str_os_type" = "debian" ];then + #debian or ubuntu + str_conf_file="/etc/network/interfaces.d/${str_if_name}" + if [ $num_v4num -eq 0 -a $num_v6num -eq 0 ];then + echo "auto ${str_if_name}" > $str_conf_file + fi + if [ $num_v6num -eq 0 ];then + echo "pre-up modprobe ipv6" >> $str_conf_file + echo "iface ${str_if_name} inet6 static" >> $str_conf_file + echo " address ${str_v6ip}" >> $str_conf_file + echo " netmask ${str_v6prefix}" >> $str_conf_file + if [ $str_v6gateway ];then + echo " gateway ${str_v6gateway}" >> $str_conf_file + fi + else + echo " post-up /sbin/ifconfig ${str_if_name} inet6 add ${str_v6ip}/${str_v6prefix}" >> $str_conf_file + echo " pre-down /sbin/ifconfig ${str_if_name} inet6 del ${str_v6ip}/${str_v6prefix}" >> $str_conf_file + fi + else + #redhat + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" + if [ $num_v4num -eq 0 -a $num_v6num -eq 0 ];then + echo "DEVICE=$str_if_name" > $str_conf_file + echo "BOOTPROTO=none" >> $str_conf_file + echo "NM_CONTROLLED=no" >> $str_conf_file + echo "ONBOOT=yes" >> $str_conf_file + fi + if [ $num_v6num -eq 0 ];then + echo "IPV6INIT=yes" >> $str_conf_file + echo "IPV6ADDR=${str_v6ip}/${str_v6prefix}" >> $str_conf_file + else + echo "IPV6ADDR_SECONDARIES=${str_v6ip}/${str_v6prefix}" >> $str_conf_file + fi + if [ `echo $str_v6gateway | grep -v 'xcatmaster'` ];then + echo "IPV6_DEFAULTGW=$str_v6gateway" >> $str_conf_file + fi + fi } -# create array of network info. Needed in case where there are -# more than one ip address per nic and shouldn't be many networks. -my $net_info; -my $cnt = 1; - -while ( $cnt <= $net_cnt ) { - $net_info = $ENV{"NETWORKS_LINE$cnt"}; - $net_info =~ /^netname=([^\|]*)\|\|/; - $net_name = $1; - $net_info =~ /net=([^\|]*)\|\|/; - $subnet = $1; - $net_info =~ /mask=([^\|]*)\|\|/; - $netmask = $1; - $net_info =~ /gateway=([^\|]*)\|\|/; - $gateway = $1; - push @{ $networks[$cnt-1] }, ($net_name, $subnet, $netmask, $gateway); - $cnt +=1; +#delete all configuration file(s) on linux +function delete_nic_config_files(){ + str_temp_name=$1 + #delete the configuration files + #delete the configuration history + if [ "$str_os_type" = "debian" ];then + rm -f /etc/network/interfaces.d/$str_temp_name 2>/dev/null + sed -i "/${str_temp_name}/d" /etc/network/xcat_history_important + elif [ "$str_os_type" = "sles" ];then + rm -f /etc/sysconfig/network/ifcfg-${str_temp_name} 2>/dev/null + sed -i "/${str_temp_name}/d" /etc/sysconfig/network/xcat_history_important + else + rm -f /etc/sysconfig/network-scripts/ifcfg-${str_temp_name} 2>/dev/null + rm -f /etc/sysconfig/network-scripts/ifcfg-${str_temp_name}:* 2>/dev/null + sed -i "/${str_temp_name}/d" /etc/sysconfig/network-scripts/xcat_history_important + fi } +function add_ip_temporary(){ + local str_ip_prefix=$1 + local str_temp_name=$2 + local str_ip=`echo $str_ip_prefix | awk -F'_' '{print $1}'` + local str_mask=`echo $str_ip_prefix | awk -F'_' '{print $2}'` -# Start processing of nics to install here. - -my $j; + if [ "$str_os_type" = "aix" ];then + echo $str_ip | grep ":" > /dev/null + #ipv6 + if [ $? -eq 0 ];then + lsattr -El $str_temp_name | grep netaddr6 | awk '{print $2}' | grep ":" + if [ $? -ne 0 ];then + chdev -l $str_temp_name -a netaddr6=$str_ip -a prefixlen=$str_mask + else + chdev -l $str_temp_name -a alias6=${str_ip}/${str_mask} + fi + #ipv4 + else + lsattr -El $str_temp_name | grep netaddr | awk '{print $2}' | grep '\.' + if [ $? -ne 0 ];then + chdev -l $str_temp_name -a netaddr=${str_ip} -a netmask=${str_mask} + else + chdev -l $str_temp_name -a alias4=${str_ip},${str_mask} + fi + fi + else + echo $str_ip | grep ":" > /dev/null + #ipv6 + if [ $? = 0 ];then + lsmod |grep -w 'ipv6' + if [ $? -ne 0 ];then + modprobe ipv6 + fi + ip addr add ${str_ip}/${str_mask} dev $str_temp_name + #ipv4 + else + str_label='' + ip addr show dev $str_temp_name | grep inet | grep "global" | grep -v ':' | grep "${str_temp_name}" + if [ $? -eq 0 ];then + for num_i in {1..1000} + do + ip addr show dev $str_temp_name | grep inet | grep "global" | grep ":${num_i}" + if [ $? -ne 0 ];then + str_label=${str_nic_name}:${num_i} + break + fi + done + else + str_label=$str_nic_name + fi -my @nics_to_install = split(/,/, $nics); -for ($j=0; $j < (scalar @nics_to_install); $j++) { - my $nic = $nics_to_install[$j]; - # reset some variables inside this loop - @nic_ips4 = (); - @nic_ips6 = (); - @nic_nets4 = (); - @nic_nets6 = (); + #the label is ready, add the ip address directly + ip addr add $str_ip/${str_mask} dev $str_nic_name scope global label $str_label + fi + fi +} - #get current ips on this nic - my $str_ret = `ip addr show dev $nic 2>/dev/null | grep inet | grep -v link | grep -v dynamic | awk '{print \$2}'`; - my $bool_config_flag = 0; - my %hash_oldips; - if ($str_ret) { - foreach (split /\n/, $str_ret){ - $hash_oldips{$_} = 1; - } - $bool_config_flag = 1; - } +str_nic_name='' +str_os_type=`uname | tr 'A-Z' 'a-z'` +str_cfg_dir='' +str_temp='' +if [ "$str_os_type" = "linux" ];then + str_temp=`echo $OSVER | grep -E '(sles|suse)'` + if [ -f "/etc/debian_version" ];then + debianpreconf + str_os_type="debian" + str_cfg_dir="/etc/network/" + elif [ -f "/etc/SuSE-release" -o -n "$str_temp" ];then + str_os_type="sles" + str_cfg_dir="/etc/sysconfig/network/" + else + str_os_type="redhat" + str_cfg_dir="/etc/sysconfig/network-scripts/" + fi +fi - # get network or networks for this nic from NICNETWORKS: - # eth0:1_0_0_0-255_255_0_0|network2,eth1:1_1_0_0 - # create array of networks for this nic - foreach my $nic_networks (split(/,/,$nicnetworks)) { - my @net = (); - if ( $nic_networks =~ /!/ ) { - @net = split(/!/,$nic_networks); - } else { - @net = split(/:/,$nic_networks); - } - if ($net[0] eq $nic) { - @nic_nets_all = split(/\|/,$net[1]); - last; - } - } +logger -t xcat -p local4.err "configeth: os type: $str_os_type" +echo "configeth on $NODE: os type: $str_os_type" +if [ "$1" = "-r" ];then + if [ $# -ne 2 ];then + logger -t xcat -p local4.err "configeth: remove nic, but the nic name is missed" + echo "configeth on $NODE: remove nic, but the nic name is missed" + exit 1 + fi + str_nic_name=$2 + logger -t xcat -p local4.err "configeth: remove nic $str_nic_name" + echo "configeth on $NODE: remove nic $str_nic_name" - # Put all ipv4 nets into nic_nets4, - # put all ipv6 nets into nic_nets6. - my $i = 0; - for ($i=0; $i < (scalar @nic_nets_all) ; $i++ ) { - # The network name itself does not indicate ipv4 or ipv6 - # should use the subnet to determine. - # Do not use foreach (@networks), needs to keep the order of nets and ips - my $net = $nic_nets_all[$i]; - foreach my $netinfo (@networks) - { - if ($netinfo->[0] eq $net) - { - if ($netinfo->[1] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) - { - push @nic_nets4, $net; - } elsif ($netinfo->[1] =~ /:/) { - push @nic_nets6, $net; - } else { - system("logger -t xcat -p local4.err 'The subnet $net is not valid.'"); - } - last; - } - } - } - # get all nic ipaddress from $nicips: i.e. eth0:1.0.0.1|2.0.0.1,eth1:1.1.1.1 - # Then get all ips for this specific nic, i.e. eth0. - foreach my $ips (split(/,/,$nicips)) { - my @ip = (); - if ( $ips =~ /!/ ) { - @ip = split(/!/,$ips); - } else { - @ip = split(/:/,$ips); - } - if ($ip[0] eq $nic ) { - @nic_ips_all = split(/\|/,$ip[1]); - } - } + if [ "$str_os_type" = "aix" ];then + old_ifs=$IFS + IFS=$'\n' + str_temp=`lsattr -El $str_nic_name | grep alias4 | awk '{print $2}'` + array_alias4_temp=($str_temp) + IFS=$old_ifs + for str_ip_alias4 in $str_temp + do + #the alias format should be ipaddr,netmask + echo $str_ip_alias4 | grep -E , + if [ $? -eq 0 ];then + chdev -l $str_nic_name -a delalias4=$str_ip_alias4 + fi + done + str_temp=`lsattr -El $str_nic_name | grep alias6 | awk '{print $2}'` + old_ifs=$IFS + IFS=$'\n' + array_alias6_temp=($str_temp) + IFS=$old_ifs + for str_ip_alias6 in ${array_alias6_temp[@]} + do + echo $str_ip_alias6 | grep -E / + if [ $? -eq 0 ];then + chdev -l $str_nic_name -a delalias6=$str_ip_alias6 + fi + done + logger -t xcat -p local4.err "configeth run command: chdev -l $str_nic_name -a netaddr='' -a netmask='' -a netaddr6='' -a prefixlen='' -a state=down" + echo "configeth on $NODE run command: chdev -l $str_nic_name -a netaddr='' -a netmask='' -a netaddr6='' -a prefixlen='' -a state=down" + chdev -l $str_nic_name -a netaddr='' -a netmask='' -a netaddr6='' -a prefixlen='' -a state=down + else + #shut down the nic if it is on + ip link show $str_nic_name | grep -i ',up' + if [ $? -eq 0 ];then + if [ "$str_os_type" = "debian" ];then + ifdown --force $str_nic_name + else + ifdown $str_nic_name + fi + fi - # Put all ipv4 addresses in @nic_ips4, - # put all ipv6 addresses in @nic_ips6. - # Do not use forach, needs to keep the order of networks and ips - for ($i=0; $i < (scalar @nic_ips_all) ; $i++ ) { - my $ip = $nic_ips_all[$i]; - # ipv4 address - if ($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) { - push @nic_ips4, $ip; - } elsif ($ip =~ /:/) { # ipv6 - push @nic_ips6, $ip; - } else { - system("logger -t xcat -p local4.err 'configeth: The ip address $ip is not valid.'"); - } - } + #delete the configuration files + delete_nic_config_files $str_nic_name + fi + exit 0 +fi - for ($i=0; $i < (scalar @nic_ips4) ; $i++ ) { +#main prcess +#1. get all ip,netmask,subnet,gateway for the nic +#2. get current configurations +#3. delete the undefined ips +#4. add the new defined ips +#5. no modification, return directly +#3. on linux modify the configuration files +if [ $# -ne 3 ];then + logger -t xcat -p local4.err "configeth: paramters error currently is $@" + echo "configeth on $NODE: paramters error currently is $@" + exit 1 +fi +str_nic_name=$1 +old_ifs=$IFS +IFS=$'|' +array_nic_ips=($2) +array_nic_networks=($3) +IFS=$old_ifs - # ipv6 configuration needs to know if this nic as ipv4 configured - $ipv4nic = 1; +if [ "$str_os_type" = "aix" ];then + str_temp=`lsattr -El $str_nic_name` +else + str_temp=`ip addr show dev $str_nic_name` +fi - # Time to create the interfaces. - # loop through the nic networks, find the matching networks to get the - # subnet and netmask and then create the appropriate ifcfg file for linux - # or invoke correct AIX command. - my $specific_nic = $nic; - if ($i > 0) { - $specific_nic = $nic . ":" . ($i); - } +logger -t xcat -p local4.err "configeth: old configuration: $str_temp" +echo "configeth on $NODE: old configuration: $str_temp" - $cnt = 0; - $subnet = ""; - $netmask = ""; - $net_name = ""; - while ( $cnt < $net_cnt ) { - if ( $networks[$cnt][0] eq $nic_nets4[$i] ) { - - $subnet = $networks[$cnt][1]; - $netmask = $networks[$cnt][2]; - $cnt = $net_cnt; # found match - get out. - } - else { - $cnt++; - } - } +#parse the networks tables contains +declare -a array_ip_mask +declare -a array_ip_status +declare -a array_nic_network_config +declare -a array_nic_subnet +declare -a array_nic_netmask +declare -a array_nic_gateway - # check that there is a subnet and netmask set - if ( !(length($subnet) > 0) || !(length($netmask) > 0) ) { - system("logger -t xcat -p local4.err 'configeth: network subnet or netmask not set.'"); - exit 1; - } +str_ip_mask_pair='' +num_index=1 +while [ $num_index -le $NETWORKS_LINES ];do + eval str_temp=\$NETWORKS_LINE$num_index + str_temp_name=`echo $str_temp | awk -F'netname=' '{print $2}' | awk -F'|' '{print $1}'` + num_i=0 + while [ $num_i -lt ${#array_nic_ips[*]} ] + do + if [ "$str_temp_name" = "${array_nic_networks[$num_i]}" ];then + array_nic_network_config[$num_i]=$str_temp + break + fi + num_i=$((num_i+1)) + done + num_index=$((num_index+1)) +done - if ($bool_config_flag) { - my $num_masklength = 32; - if ($netmask =~ /\d+\.\d+\.\d+\.\d+/){ - my $maskn = unpack("N", inet_aton($netmask)); - my $bin = unpack ("B32", pack("N", $maskn)); - my @dup = ( $bin =~ /(1{1})0*/g); - $num_masklength = scalar ( @dup ); - } - else { - $num_masklength = $netmask - } +logger -t xcat -p local4.err "configeth: new configuration" +echo "configeth on $NODE: new configuration" +num_index=0 +str_ipv6_gateway='' +while [ $num_index -lt ${#array_nic_ips[*]} ];do + #get the ip address and network name + str_ip=${array_nic_ips[$num_index]} + str_netname=${array_nic_networks[$num_index]} + if [ ! $str_netname ];then + logger -t xcat -p local4.err "configeth: Network name is not defined on $str_nic_name for $str_ip." + echo "configeth on $NODE: Network name is not defined on $str_nic_name for $str_ip." + num_index=$((num_index+1)) + continue + fi - my $str_ipmask = $nic_ips4[$i] . "/" . $num_masklength; - if ($hash_oldips{$str_ipmask}) { - delete $hash_oldips{$str_ipmask}; - } - } - #should delete the old alias configure ( like ifcfg-eth0:1 )before new configure - #only do this operation on redaht/sl/centos - if ( -f "/etc/sysconfig/network-scripts/ifcfg-$nic:1" ){ - `rm -f /etc/sysconfig/network-scripts/ifcfg-$nic:*`; - } + #find out the network definition + str_line=${array_nic_network_config[$num_index]} + if [ ! $str_line ];then + logger -t xcat -p local4.err "configeth: Network object $str_netname is not defined." + echo "configeth on $NODE: Network object $str_netname is not defined." + num_index=$((num_index+1)) + continue + fi - if ($^O =~ /^aix/i) { - if ($i == 0) { - if ($nic_ips4[$i] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) { - runcmd("chdev -l '$nic' -a netaddr=$nic_ips4[$i] -a netmask=$netmask -a state='up'"); - # } else { #ipv6 - # runcmd("autoconf6 -6i en$nic_num"); - } - } else { - if ($nic_ips4[$i] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) { - runcmd("chdev -l '$nic' -a alias4=$nic_ips4[$i],$netmask"); - # } else { #ipv6 - # runcmd("autoconf6 -6i en$nic_num"); - } - } - } - elsif (($ENV{OSVER} && ($ENV{OSVER} =~ /sles|suse/i)) || (-f "/etc/SuSE-release")) { - # Write the info to the ifcfg file - my $dir = "/etc/sysconfig/network"; + #fetch the subnet and netmask in networks definition + str_subnet=`echo $str_line | awk -F'net=' '{print $2}' | awk -F'|' '{print $1}'` + str_netmask=`echo $str_line | awk -F'mask=' '{print $2}' | awk -F'|' '{print $1}'` + str_gateway=`echo $str_line | awk -F'gateway=' '{print $2}' | awk -F'|' '{print $1}'` + + if [ ! $str_subnet -o ! $str_netmask ];then + logger -t xcat -p local4.err "configeth: subnet or netmask is not defined in network object $str_netname." + echo "configeth on $NODE: subnet or netmask is not defined in network object $str_netname." + num_index=$((num_index+1)) + continue + fi - if ($i == 0 ) { - if (!open(FILE, ">$dir/ifcfg-$nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); exit 1; } - # Not sure what is really REQUIRED from below -- copied the eth file from - # the system - print FILE "DEVICE=\'$nic\'\n"; - print FILE "BOOTPROTO=\'static\'\n"; - print FILE "NM_CONTROLLED=\'no\'\n"; - print FILE "BROADCAST=\'\'\n"; - print FILE "ETHTOOL_OPTIONS=\'\'\n"; - print FILE "IPADDR=\'".$nic_ips4[$i]."\'\n"; - print FILE "MTU=\'\'\n"; - print FILE "NAME=\'\'\n"; - print FILE "NETMASK=\'".$netmask."\'\n"; - print FILE "NETWORK=\'".$subnet."\'\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"; - - } else { - # on suse/sles the ip alias info goes into the same file as the base ip info. - # open ifconfig-eth file and append additional info. - if (!open(FILE, ">>$dir/ifcfg-$nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic for appending ip alias info'"); exit 1; } + array_nic_subnet[$num_index]=$str_subnet + array_nic_netmask[$num_index]=$str_netmask + array_nic_gateway[$num_index]=$str_gateway + if [ -n "$str_gateway" ];then + str_ipv6_gateway=$str_gateway + fi + logger -t xcat -p local4.err "configeth: $str_ip, $str_subnet, $str_netmask, $str_gateway" + echo " $str_ip, $str_subnet, $str_netmask, $str_gateway" + #on linux, call sub rutine to define ipv4 or ipv6 address for the persitent configuration + if [ `echo $str_ip | grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}$'` ];then + if [ "$str_os_type" = "aix" ];then + hashset hash_new_config "${str_ip}_${str_netmask}" "new" + str_ip_mask_pair=$str_ip_mask_pair"${str_ip}_${str_netmask} " + else + str_prefix=$(v4mask2prefix $str_netmask) + hashset hash_new_config "${str_ip}_${str_prefix}" "new" + str_ip_mask_pair=$str_ip_mask_pair"${str_ip}_${str_prefix} " + fi + elif [ `echo $str_ip | grep -E ":"` ];then + num_ipv6_index=$((num_ipv6_index+1)) + hashset hash_new_config "${str_ip}_${str_netmask}" "new" + str_ip_mask_pair=$str_ip_mask_pair"${str_ip}_${str_netmask} " + else + logger -t xcat -p local4.err "configeth: the ipaddress( $str_ip ) for $str_nic_name is invalid." + echo "configeth on $NODE: the ipaddress( $str_ip ) for $str_nic_name is invalid." + fi + num_index=$((num_index+1)) +done - print FILE "IPADDR_$i=\'".$nic_ips4[$i]."\'\n"; - print FILE "NETMASK_$i=\'".$netmask."\'\n"; - print FILE "NETWORK_$i=\'".$subnet."\'\n"; - print FILE "LABEL_$i=\'".$i."\'\n"; - } - close FILE; - runcmd("ifup $nic"); - } - elsif ( -f "/etc/debian_version" ) { - preParse_Debian(); - if ($i == 0) { - if (!open(FILE, ">/etc/network/interfaces.d/$nic")){ - system("logger -t xcat -p local4.err 'configeth: cannot open /etc/network/interfaces.d/$nic for appending ip alias info'"); - exit 1; - } +str_ip_mask_pair=`echo "$str_ip_mask_pair" | sed -e 's/ $//'` + +str_old_conf='' +if [ "$str_os_type" = "aix" ];then + #check the netaddr + str_history=`lsattr -El $str_nic_name | grep netaddr | awk '{print $2}' | grep '\.'` + if [ $? -eq 0 ];then + str_temp=`lsattr -El $str_nic_name | grep netmask | awk '{print $2}'` + str_old_ip=${str_history}"_"${str_temp} + str_ip_status=$(hashget hash_new_config $str_old_ip) + if [ -n "$str_ip_status" ];then + hashset hash_new_config $str_old_ip "old" + else + chdev -l $str_nic_name -a netaddr='' -a netmask='' + logger -t xcat -p local4.err "configeth: delete undefined ip address $str_old_ip" + echo "configeth on $NODE: delete undefined ip address $str_old_ip" + fi + fi + + #check the netaddr6 + str_history=`lsattr -El $str_nic_name | grep netaddr6 | awk '{print $2}' | grep ':'` + if [ $? -eq 0 ];then + str_temp=`lsattr -El $str_nic_name | grep prefixlen | awk '{print $2}'` + str_old_ip=${str_history}"_"${str_temp} + str_ip_status=$(hashget hash_new_config $str_old_ip) + if [ -n "$str_ip_status" ];then + hashset hash_new_config $str_old_ip "old" + else + chdev -l $str_nic_name -a netaddr6='' -a prefixlen='' + logger -t xcat -p local4.err "configeth: delete undefined ipv6 address $str_old_ip" + echo "configeth on $NODE: delete undefined ipv6 address $str_old_ip" + fi + fi + + #check the ipv4 alias + str_history=`lsattr -El $str_nic_name | grep alias4 | awk '{print $2}' | grep '\.'` + if [ $? -eq 0 ];then + old_ifs=$IFS + IFS=$'\n' + array_alias4_temp=($str_history) + IFS=$old_ifs + for str_temp in ${array_alias4_temp[@]} + do + str_old_ip=`echo $str_temp | tr ',' '_'` + str_ip_staus=$(hashget hash_new_config $str_old_ip) + if [ -n "$str_ip_staus" ];then + hashset hash_new_config $str_old_ip "old" + else + chdev -l $str_nic_name -a delalias4=$str_temp - print FILE "auto $nic\n"; - print FILE "iface $nic inet static\n"; - print FILE " address $nic_ips4[$i]\n"; - print FILE " netmask $netmask\n"; - print FILE " network $subnet\n"; - } - else { - if (!open(FILE, ">>/etc/network/interfaces.d/$nic")){ - system("logger -t xcat -p local4.err 'configeth: cannot open /etc/network/interfaces.d/$nic for appending ip alias info'"); - exit 1; - } + fi + done + fi - print FILE "auto $nic:$i\n"; - print FILE "iface $nic:$i inet static\n"; - print FILE " address $nic_ips4[$i]\n"; - print FILE " netmask $netmask\n"; - print FILE " network $subnet\n"; - } - close FILE; - } - else { - # Write the info to the ifcfg file for redhat - my $dir = "/etc/sysconfig/network-scripts"; - if (!open(FILE, ">$dir/ifcfg-$specific_nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$specific_nic.'"); exit 1; } - print FILE "DEVICE=$specific_nic\n"; - print FILE "BOOTPROTO=none\n"; - print FILE "NM_CONTROLLED=no\n"; - print FILE "IPADDR=$nic_ips4[$i]\n"; - print FILE "NETMASK=$netmask\n"; - #if (defined($gateway)) { print FILE "GATEWAY=$gateway\n"; } - print FILE "ONBOOT=yes\n"; - close FILE; + #check the ipv6 alias + str_history=`lsattr -El $str_nic_name | grep alias6 | awk '{print $2}' | grep '\.'` + if [ $? -eq 0 ];then + old_ifs=$IFS + IFS=$'\n' + array_alias6_temp=($str_history) + IFS=$old_ifs + for str_temp in ${array_alias6_temp[@]} + do + str_old_ip=`$str_temp | tr '/' '_'` + str_ip_staus=$(hashget hash_new_config $str_old_ip) + if [ -n "$str_ip_staus" ];then + hashset hash_new_config $str_old_ip "old" + else + chdev -l $str_nic_name -a delalias6=$str_temp + fi + done + fi - runcmd("$dir/ifup $specific_nic"); - } - # system("logger -t xcat -p local4.info 'configeth: successfully configured $specific_nic.'"); - } + #add the new configured ip address + old_ifs=$IFS + IFS=$' ' + array_ip_mask_temp=($str_ip_mask_pair) + IFS=$old_ifs + for str_new_ip in ${array_ip_mask_temp[@]} + do + str_ip_status=$(hashget hash_new_config $str_new_ip) + if [ "$str_ip_status" = "new" ];then + logger -t xcat -p local4.err "configeth: add $str_new_ip for $str_nic_name temporary." + echo "configeth on $NODE: add $str_new_ip for $str_nic_name temporary." + add_ip_temporary $str_new_ip $str_nic_name + fi + done + + #change the nic status to up + chdev -l $str_nic_name -a state=up +else + str_history='' + bool_restart_flag=0 + bool_modify_flag=0 + str_nic_status='down' + str_his_file=${str_cfg_dir}xcat_history_important + str_history=`ip addr show dev $str_nic_name | grep inet | grep -iv dynamic | grep -iv link | awk '{print $2}'` + old_ifs=$IFS + IFS=$'\n' + array_ip_old_temp=($str_history) + IFS=$old_ifs + ip link show dev $str_nic_name | grep -i ,up + if [ $? -eq 0 ];then + str_nic_status='up' + if [ -f "${str_his_file}" ];then + cat ${str_his_file} | grep $str_nic_name + if [ $? -eq 0 ];then + str_nic_status='up' + for str_old_ip in ${array_ip_old_temp[@]} + do + str_old_ip=`echo $str_old_ip | tr '/' '_'` + str_ip_staus=$(hashget hash_new_config $str_old_ip) + if [ -n "$str_ip_staus" ];then + hashset hash_new_config $str_old_ip "old" + else + bool_modify_flag=1 + logger -t xcat -p local4.err "configeth: delete $str_old_ip for $str_nic_name temporary." + echo "configeth on $NODE: delete $str_old_ip for $str_nic_name temporary." + str_old_ip=`echo $str_old_ip | tr '_' '/'` + ip addr del $str_old_ip dev $str_nic_name + fi + done + else + bool_restart_flag=1 + bool_modify_flag=1 + fi + else + bool_restart_flag=1 + bool_modify_flag=1 + fi + else + bool_restart_flag=1 + bool_modify_flag=1 + fi - # ipv6 configuration - # ipv6 address does not use the nic alias like eth0:1, - # should use the main nic like eth0 - my $configured = 0; - for ($i=0; $i < (scalar @nic_ips6) ; $i++ ) - { - # Get the network information: netname, subnet, netmask - my $found = 0; - my $subnet; - my $prefixlen; - my $ipv6gateway; - my $ip6addr = $nic_ips6[$i]; - my $net = $nic_nets6[$i]; - foreach my $netinfo (@networks) - { - if ($netinfo->[0] eq $net) - { - $found = 1; - $subnet = $netinfo->[1]; - $prefixlen = $netinfo->[2]; - $ipv6gateway = $netinfo->[3]; - } - # Remove the postfix like /64 from subnet - if ($subnet && ($subnet =~ /\//)) { - $subnet =~ s/\/.*$//; - } + if [ $bool_restart_flag = 0 ];then + #add the new defined ip + old_ifs=$IFS + IFS=$' ' + array_ip_mask_temp=($str_ip_mask_pair) + IFS=$old_ifs + for str_new_ip in ${array_ip_mask_temp[@]} + do + str_ip_status=$(hashget hash_new_config $str_new_ip) + if [ "$str_ip_status" = "new" ];then + bool_modify_flag=1 + if [ $bool_restart_flag -eq 0 ];then + logger -t xcat -p local4.err "configeth: add $str_new_ip for $str_nic_name temporary." + echo "configeth on $NODE: add $str_new_ip for $str_nic_name temporary." + add_ip_temporary $str_new_ip $str_nic_name + fi + fi + done + fi + #configure the ipv6 default route + if [ $bool_restart_flag -eq 0 -a -n "$str_ipv6_gateway" ];then + ip -6 route | grep default | grep $str_ipv6_gateway + if [ $? -ne 0 ];then + logger -t xcat -p local4.err "configeth: the default ipv6 route changes to $str_ipv6_gateway." + echo "configeth on $NODE: the default ipv6 route changes to $str_ipv6_gateway." + ip -6 route del default + ip -6 route add default $str_ipv6_gateway dev $str_dev_name + fi + fi - # Remove the "/" from prefixlen - if ($prefixlen && ($prefixlen =~ /^\//)) - { - $prefixlen =~ s/^\///; - } - } - if ($found == 0) - { - system("logger -t xcat -p local4.err 'configeth: Could not find network entry for ip address $ip6addr'"); - next; - } + #modify the configuration files + if [ $bool_modify_flag -eq 1 ];then + if [ $bool_restart_flag -eq 1 ];then + if [ "$str_nic_status" = "up" ];then + if [ "$str_os_type" = "debian" ];then + ifdown --force $str_nic_name > /dev/null + else + ifdown $str_nic_name > /dev/null + fi + fi + #delete all old ip address + for str_old_ip in ${array_ip_old_temp[@]} + do + ip addr del $str_old_ip dev $str_nic_name + done + fi + logger -t xcat -p local4.err "configeth: $str_nic_name changed, modify the configuration files" + echo "configeth on $NODE: $str_nic_name changed, modify the configuration files" + num_ipv4_index=0 + num_ipv6_index=0 + num_index=0 + cat $str_his_file | grep $str_nic_name + if [ $? -ne 0 ];then + echo "${str_nic_name}" >> $str_his_file + fi + #delete the old alias configuration files on redhat + if [ "$str_os_type" = "redhat" ];then + rm -f /etc/sysconfig/network-scripts/ifcfg-${str_nic_name}:* 2>/dev/null + fi + while [ $num_index -lt ${#array_nic_ips[*]} ];do + str_ip=${array_nic_ips[$num_index]} + str_subnet=${array_nic_subnet[$num_index]} + str_netmask=${array_nic_netmask[$num_index]} + str_gateway=${array_nic_gateway[$num_index]} + if [ ! $str_subnet -o ! $str_netmask ];then + num_index=$((num_index+1)) + continue + fi - if ($bool_config_flag) { - my $str_ipmask = $ip6addr . '/' . $prefixlen; - if ($hash_oldips{$str_ipmask}){ - delete $hash_oldips{$str_ipmask}; - } - } + if [ `echo $str_ip | grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}$'` ];then + configipv4 $str_nic_name $str_ip $str_subnet $str_netmask $num_ipv4_index + num_ipv4_index=$((num_ipv4_index+1)) + elif [ `echo $str_ip | grep -E ":"` ];then + configipv6 $str_nic_name $str_ip $str_subnet $str_netmask $num_ipv6_index $num_ipv4_index $str_gateway + num_ipv6_index=$((num_ipv6_index+1)) + else + num_index=$((num_index+1)) + continue + fi + num_index=$((num_index+1)) + done + else + logger -t xcat -p local4.err "configeth: $str_nic_name no changed, return directly." + echo "configeth on $NODE: $str_nic_name no changed, return directly." + fi - if ($^O =~ /^aix/i) { - if (!$configured) - { - runcmd("chdev -l en0 -a netaddr6=$ip6addr -a prefixlen=$prefixlen -a state=up"); - $configured = 1; - } else { - runcmd("chdev -l en0 -a alias6=$ip6addr/$prefixlen"); - } - } elsif (($ENV{OSVER} && ($ENV{OSVER} =~ /sles|suse/i)) || (-f "/etc/SuSE-release")) { - my $dir = "/etc/sysconfig/network"; - # If there are only ipv6 addresses on this nic, - # needs to flush the ifcfg-$nic file when configuring the first ipv6 addr, - # to avoid duplicate entries when run confignics/configeth multiple times. - if (!$ipv4nic && !$configured) - { - if (!open(FILE, ">$dir/ifcfg-$nic")) { - system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); - exit 1; - } - print FILE "DEVICE=$nic\n"; - print FILE "BOOTPROTO=static\n"; - print FILE "NM_CONTROLLED=no\n"; - print FILE "STARTMODE=onboot\n"; - } else { - if (!open(FILE, ">>$dir/ifcfg-$nic")) { - system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); - exit 1; - } - } - # Use the label=ipv6$i in ifcfg-ethx file, like ipv60, ipv61 - print FILE "LABEL_ipv6$i=ipv6$i\n"; - print FILE "IPADDR_ipv6$i=$ip6addr\n"; - print FILE "PREFIXLEN_ipv6$i=$prefixlen\n"; - close FILE; - if ($ipv6gateway && $ipv6gateway !~ /xcatmaster/) { - # Do not add duplicate entries - `grep -E "default\\s+$ipv6gateway\\s+" /etc/sysconfig/network/routes 2>&1 1>/dev/null`; - if ($? != 0) { - `echo "default $ipv6gateway - -" >> /etc/sysconfig/network/routes`; - } - } - runcmd("ifup $nic"); - } - elsif ( -f "/etc/debian_version" ){ - if (!$ipv4nic && !$configured){ - if (!open(FILE, ">/etc/network/interfaces.d/$nic")) { - system("logger -t xcat -p local4.err 'configeth: cannot open /etc/network/interface.d/$nic.'"); - exit 1; - } - print FILE "auto $nic\n"; - } - else { - if (!open(FILE, ">>/etc/network/interfaces.d/$nic")) { - system("logger -t xcat -p local4.err 'configeth: cannot open /etc/network/interface.d/$nic.'"); - exit 1; - } - } - - if (!$configured){ - print FILE "pre-up modprobe ipv6\n"; - print FILE "iface $nic inet6 static\n"; - print FILE " address $ip6addr\n"; - print FILE " netmask $prefixlen\n"; - if ( $ipv6gateway && $ipv6gateway !~ /xcatmaster/ ){ - print FILE " gateway $ipv6gateway\n"; - } - $configured = 1; - } - else { - print FILE " post-up /sbin/ifconfig $nic inet6 add $ip6addr/$prefixlen\n"; - print FILE " pre-down /sbin/ifconfig $nic inet6 del $ip6addr/$prefixlen\n"; - } - close FILE; - } - else { - # Ubuntu TODO - my $dir = "/etc/sysconfig/network-scripts"; - # If there are only ipv6 addresses on this nic, - # needs to flush the ifcfg-$nic file when configuring the first ipv6 addr, - # to avoid duplicate entries when run confignics/configeth multiple times. - if (!$ipv4nic && !$configured) - { - if (!open(FILE, ">$dir/ifcfg-$nic")) { - system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); - exit 1; - } - print FILE "DEVICE=$nic\n"; - print FILE "BOOTPROTO=none\n"; - print FILE "NM_CONTROLLED=no\n"; - print FILE "ONBOOT=yes\n"; - } else { - if (!open(FILE, ">>$dir/ifcfg-$nic")) { - system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'"); - exit 1; - } - } - if (!$configured) { - print FILE "IPV6INIT=yes\n"; - print FILE "IPV6ADDR=$ip6addr/$prefixlen\n"; - $configured = 1; - } else { - print FILE "IPV6ADDR_SECONDARIES=$ip6addr/$prefixlen\n"; - } - if ($ipv6gateway && $ipv6gateway !~ /xcatmaster/) { - print FILE "IPV6_DEFAULTGW=$ipv6gateway\n"; - } - close FILE; - runcmd("$dir/ifup-ipv6 $nic"); - } - } + #restart the nic + if [ $bool_restart_flag -eq 1 ];then + if [ "$str_os_type" = "debian" ];then + ifup -a -i /etc/network/interfaces.d/$str_nic_name + else + ifup $str_nic_name + fi + fi +fi - #still contains old ips, should ifdown the nic and then ifup - if ($^O =~ /linux/i){ - my $ret = `ip addr show dev $nic | grep $nic | grep -i ,up`; - if ($ret) { - my $num_oldnums = scalar(keys %hash_oldips); - #need delete the ip address or first time configure - if ( -f "/etc/debian_version"){ - `ifdown --forece $nic;ifup $nic`; - } - elsif (($num_oldnums > 0) || ($bool_config_flag == 0) ){ - `ifdown $nic;ifup $nic`; - } - else { - `ifup $nic`; - } - } - else { - `ifup $nic`; - } - } -} -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 'configeth: command $cmd failed with rc $rc: " . join('',@output) . "'"); - my $errout= "configeth: command $cmd failed with rc $rc."; - `echo $errout`; - exit $rc; - } -} - - - -sub get_current_nics { - my @ip_addr_array = `ip addr show`; - - my $nic_name; - my $nic_type; - my $nic_state; - my $nic_slave; - my $nic_mac; - my $bridgednics; - my $a_len = scalar(@ip_addr_array); - - my %nics; - - my $i = 0; - while ( $i < scalar(@ip_addr_array)) { - #print "array index $i: @ip_addr_array[$i]\n"; - # check if line starts with "number: text:" - # if so then it is the start of a nic stanza which looks like: - # 3: eth1: mtu 1500 qdisc mq state UP qlen 1000 - # link/ether 5c:f3:fc:a8:bb:93 brd ff:ff:ff:ff:ff:ff - # inet 9.114.34.232/24 brd 9.114.34.255 scope global eth1 - # inet6 fd55:faaf:e1ab:336:5ef3:fcff:fea8:bb93/64 scope global dynamic - # valid_lft 2591627sec preferred_lft 604427sec - # inet6 fd56::214:5eff:fe15:849b/64 scope global - # valid_lft forever preferred_lft forever - # inet6 fe80::5ef3:fcff:fea8:bb93/64 scope link - # valid_lft forever preferred_lft forever - - if ( $ip_addr_array[$i] =~ /^(\d+): / ) { - # get nic name - $ip_addr_array[$i] =~ /^\d+: ([^:].*):/; - $nic_name = $1; - - # get state of nic either "UP" if different, such as DOWN, not configured - # then assume state is DOWN. - if ($ip_addr_array[$i] =~ /,UP/ ) { - $nic_state = "UP"; - } - else { - $nic_state = "DOWN"; - } - - # Check if this nic is part of a bridge or bonded interface. If bonded on - # redhat then "SLAVE" or "MASTER" will be in the first line of stanza - # inside <>. - # - # A bridged interface is a little different. The command, "brctl show", is used - # to show information about bridged interfaces. The subroutine get_bridged_nics() - # writes out $bridgednics which is a comma separated strings of bridged nics. - # If $nic_name matches a bridgednic then set nic_slave=1 for now to lump them - # with bonded nics for now since we will not unconfigure bridged or bonded nics. - # - $nic_slave = 0; # default to 0 - if ($ip_addr_array[$i] =~ /SLAVE/ ) { - $nic_slave = 1; - } - if ($ip_addr_array[$i] =~ /MASTER/ ) { - $nic_slave = 1; - } - if ($nic_name =~ /$bridgednics/) { - $nic_slave = 1; - } - - # example output shows type is "link/ether" for ethernet or - # "link/infiniband" for ib. Look ahead to next line for this. - $ip_addr_array[$i+1] =~ /^\s+link\/([a-z]+) /; - $nic_type = $1; - - $i++; - - # CHECK: it looks like there could be a usb nic ethernet adapter. Need to investigate - # if more needs to be done for that such as it is handled differently. - # If value is not "ether" or "infiniband" then continue on to next stanza - if ($nic_type ne "ether" && $nic_type ne "infiniband") { - next; - } - - my @line = split(' ', $ip_addr_array[$i]); - $nic_mac = $line[1]; - - # move on to next line and loop through all lines for additional information or - # and until the line is the start of a new stanza. - # This is where things get dicey and may need enhancements: - # inet 70.0.0.182/24 brd 70.0.0.255 scope global eth5 - # indicates an ipv4 address with a netmask of /24, a broadcast address, - # scope global nicname (eth5). If this was an aliased ip then nicname would be eth5:1 or such. - # inet6 fd55:faaf:e1ab:336:3640:b5ff:fe89:66c4/64 scope global dynamic - # it appears that valid ips have "scope global" - - $i++; - # print "NIC: $nic_name, TYPE: $nic_type, MAC: $nic_mac SLAVE: $nic_slave, STATE: $nic_state \n"; - $nics{$nic_name} = {}; - $nics{$nic_name}->{state} = $nic_state; - $nics{$nic_name}->{mac} = $nic_mac; - $nics{$nic_name}->{slave} = $nic_slave; - $nics{$nic_name}->{type} = $nic_type; - $nics{$nic_name}->{ips} = []; - - while ($i < scalar(@ip_addr_array) && !($ip_addr_array[$i] =~ /^(\d+): / ) ) { - # $ip_proto - is either inet or inet6 - # $ip_mask is "ipaddr or ipv6addr"/netmask and possibly "brd broadcastip" - # $scope has the scope (global, link, site, host) if global or site then - # only data after scope is the nic "label", i.e. eth0, eth5:1. - # note that "tentative" may appear but is not a label. - # On RH for an ip alias with same netmask/subnet then line will be: - # inet 11.0.0.80/16 brd 11.0.255.255 scope global secondary eth2:1 - - my ($ip_proto, $ip_mask, $scope) = - $ip_addr_array[$i]=~/\s+(inet|inet6)\s+(.+)\s+scope\s+(.+)$/; - - if ( $ip_proto =~ /inet/ ) { # line contains inet or inet6. Process info - my ($nic_ip_mask, $junk) = split(' ', $ip_mask); - my ($nic_ip, $nic_mask) = split('\/', $nic_ip_mask); - my ($sc, $label, $more_label) = split(' ', $scope); - if ( $sc ne "link" ) { # this is a valid one to keep - - if ($label eq "secondary") { - $label = $more_label; - } - #print "\tPROTO: $ip_proto, IP: $nic_ip, MASK: $nic_mask, SCOPE: $sc, LABEL:$label\n"; - push @{$nics{$nic_name}->{ips}},{ip => $nic_ip, netmask => $nic_mask, label => $label }; - } - } - $i++; - } - next; # next nic stanza or end of file. - } - $i++; - } - return \%nics; -} - -#before modify the configuration on ubuntu/debian, should preparse the interface file -#By default, All nics configuration are saved into /etc/network/interfaces, it is difficult for xcat to configure nic -#So only use source /etc/network/interfaces.d/* in "/etc/network/interfaces" -#create files under /etc/network/interfaces.d/ for each nic, then it is similar with the readhat and sles -sub preParse_Debian{ - my $configfile; - - open(FH, "<", "/etc/network/interfaces"); - my @lines = ; - close(FH); - - if ($lines[0] =~ /XCAT_CONFIG/i){ - return; - } - - unless ( -e "/etc/network/interfaces.bak" ){ - copy ("/etc/network/interfaces", "/etc/network/interfaces.bak"); - } - - unless ( -d "/etc/network/interfaces.d" ){ - mkpath( "/etc/network/interfaces.d" ); - } - - open(FH, ">", "/etc/network/interfaces"); - print FH "#XCAT_CONFIG\n"; - print FH "source /etc/network/interfaces.d/* \n"; - close(FH); - - foreach my $line ( @lines ){ - if ( $line =~ /^\s*$/){ - next; - } - - if ( $line =~ /^#.*/ ){ - next; - } - - my @attr = split /\s+/, $line; - if ( $attr[0] =~ /auto|allow-hotplug/){ - my $i = 1; - while ( $i < @attr ){ - open(SFH, ">", "/etc/network/interfaces.d/$attr[$i]"); - print SFH "$attr[0] $attr[$i]\n"; - close(SFH); - print FH "source /etc/network/interfaces.d/$attr[$i] \n"; - $i = $i + 1; - } - } - elsif ($attr[0] =~ /mapping|iface/){ - $configfile = "/etc/network/interfaces.d/$attr[1]"; - open(SFH, ">>", $configfile); - unless ( -e $configfile){ - print SFH "auto $attr[1] \n"; - } - print SFH $line; - close(SFH); - } - else{ - open(SFH, ">>", $configfile); - print SFH $line; - close(SFH); - } - } - - return; -} +exit 0 diff --git a/xCAT/postscripts/confignics b/xCAT/postscripts/confignics index 764a85b8a..55aa2e749 100755 --- a/xCAT/postscripts/confignics +++ b/xCAT/postscripts/confignics @@ -1,532 +1,209 @@ -#!/usr/bin/perl -# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#!/bin/bash -# 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. +str_dir_name=`dirname $0` +. $str_dir_name/xcatlib.sh -use strict; -use Socket; -use Data::Dumper; - -# Only three 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. -# "-r" unconfigure/remove existing configured nics. This flag will -# compare existing configured nics with nics in the nics table -# if nic doesn't exist in nics table then ifdown and remove -# config file (ifcfg-*) - - -my $ibaports = 1; # default to one port per ib adapter. -my $cfg_inst_nic = ''; -my $rem_eth_nics = ''; # ethernet nics to remove if -r is set -my $rem_ib_nics = ''; # ib nics to remove if -r is set -my $rem_nics = 0; -my $arg =''; -while ($arg = shift(@ARGV)) { - if ( $arg eq "-s" ) { - $cfg_inst_nic = 1; - } elsif ( $arg =~ /--ibaports=(\d)$/) { - $ibaports = $1; - } elsif ( $arg eq "-r" ) { - $rem_nics = 1; - } -} - -my $ibnics = ''; -my $ethnics = ''; -my $bridgednics = ''; -my $nicips = $ENV{NICIPS}; -my $niccustomscripts = $ENV{NICCUSTOMSCRIPTS}; -my $nictypes = $ENV{NICTYPES}; -my $xcatpostdir = "/xcatpost"; -my %cust_script_nics = (); # hash to save nics specified in niccustomscripts -my $type = ''; -my $nic = ''; -my $MAC = $ENV{MACADDRESS}; -my $inst_nic = ''; -my $thisnode = $ENV{NODE}; - -# After discussing with Bruce, getting install nic in following order: -# 1) get NODE env var, resolve to ip and get related nic info, if not found: -# 2) Check if INSTALLNIC is set to specific nic then use that nic, if set to "mac" -# then use mac to get nic. If still not set then: -# 3) check PRIMARYNIC in similar manor as INSTALLNIC. -# If still not found then exit with error. - -my $cfg_nic_ref_hash = {}; # set from get_install_nic -my $nic_to_cfg_ref_hash = {}; # set from env variables in mypostscript - -$cfg_nic_ref_hash = get_current_nics(); - -$inst_nic = get_install_nic(); -$bridgednics = get_bridged_nics(); - - - -# 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 ) { - system("logger -t xcat -p local4.info 'confignics $thisnode: processing custom scripts: $niccustomscripts '"); - - foreach my $customscript (split(/,/,$niccustomscripts)) { - - my @script = (); - if ( $customscript =~ /!/ ) { - @script = split(/!/,$customscript); - } else { - @script = split(/:/,$customscript); - } - $cust_script_nics{$script[0]} = 1; - my @s = split(/ /,$script[1]); - - # 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 $thisnode: 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 $thisnode: nic $nic_and_ips[0] already configured through custom script '"); +#the nics' information contain: +#1. ip address +#2. nic network +#3. nic type +#4. custom scripts +#all of them are saved by different variable +#this function can split the varable for each nic, and svae the information for each nic +#into an hash, the key is nic name, the value are all information, which joined by ',' +function splitconfig(){ + if [ ! "$1" ];then + return + fi + old_ifs=$IFS + IFS=$',' + array_conf_temp=($1) + IFS=$old_ifs + for i in ${array_conf_temp[@]} + do + D= + if [ `echo $i | grep "!"` ];then + D="!" + else + D=":" + fi + key=`echo $i | cut -d"$D" -f 1` + str_temp_value=`echo $i | cut -d"$D" -f 2` - } - 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)) { - if ($ethnics) { - $ethnics = $ethnics . "," . $nic; - } else { - $ethnics = $nic; - } - } - else { - system("logger -t xcat -p local4.info 'confignics $thisnode: 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 $thisnode: unknown type $type for NIC: $nic '"); - } - } + str_temp=$(hashget hash_defined_nics $key) + if [ -n "$str_temp" ];then + str_temp=$str_temp",${str_temp_value}" + else + str_temp="$str_temp_value" + str_all_nics=$str_all_nics"$key " + fi + hashset hash_defined_nics $key $str_temp + done } -# set_nics_to_remove will compare $rem_nics for install nic, and bonded or bridged nics -# and set $rem_nics to only those $nics that should be unconfigured. -if ( $rem_nics ) { - set_nics_to_remove(); -} +bool_cfg_inst_nic=0 +str_inst_nic='' +str_ib_nics='' +str_os_type=`uname | tr 'A-Z' 'a-z'` +bool_remove=0 +num_iba_ports= +str_all_nics='' +for arg in "$@" +do + if [ "$arg" = "-s" ];then + bool_cfg_inst_nic=1 + elif [ "$arg" = "-r" ];then + bool_remove=1 + elif [ "${arg:0:10}" = "--ibaports" ];then + num_iba_ports=${arg#--ibaports=} + fi +done -my $cmd = ''; +logger -t xcat -p local4.info "confignics is called: config install nic:$bool_cfg_inst_nic, remove: $bool_remove, iba ports: $num_iba_ports" +echo "confignics on $NODE: config install nic:$bool_cfg_inst_nic, remove: $bool_remove, iba ports: $num_iba_ports" -# Call configeth now to configure all ethernet adapters in one call. -if ($ethnics) { - $cmd = "configeth -c $ethnics"; -} -if ( $rem_eth_nics) { - if ($cmd) { - $cmd = $cmd . " -u $rem_eth_nics"; - } - else { - $cmd = "configeth -u $rem_eth_nics"; - } -} -if ($cmd) { - runcmd("$cmd"); - system("logger -t xcat -p local4.info 'confignics $thisnode: executed $cmd '"); -} -else { - system("logger -t xcat -p local4.info 'confignics $thisnode : no ethernet nics to configure'"); -} +str_temp='' +if [ ! $INSTALLNIC ];then + str_temp="mac" +else + str_temp=$INSTALLNIC +fi -# 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 $thisnode: executed script: configib for nics $ibnics '"); -} - -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 $thisnode: command $cmd failed with rc $rc: " . join('',@output) . "'"); - my $errout= "confignics $thisnode: command $cmd failed with rc $rc.\n"; - print $errout; - exit $rc; - } - print join("\n",@output),"\n"; -} +if [ "$str_temp" = "mac" ];then + if [ "$str_os_type" = "aix" ];then + old_ifs=$IFS + IFS=$' ' + str_temp=`ifconfig -l` + array_nicnames_temp=($str_temp) + IFS=$old_ifs + for temp_nic in ${array_nicnames_temp[@]} + do + entstat -t $temp_nic | grep -i "$MACADDRESS" + if [ $? -eq 0 ];then + str_inst_nic=$temp_nic + break + fi + done + else + str_inst_nic=`ifconfig -a | grep -i "$MACADDRESS" | awk '{print $1;}'` + fi +elif [ `echo $str_temp | grep -E "e(n|th)[0-9]+"` ];then + str_inst_nic=$str_temp +fi -sub get_current_nics { - my @ip_addr_array = `ip addr show`; - my $nic_name; - my $nic_type; - my $nic_state; - my $nic_slave; - my $nic_mac; - my $a_len = scalar(@ip_addr_array); +splitconfig $NICIPS +splitconfig $NICTYPES +splitconfig $NICNETWORKS +splitconfig $NICCUSTOMSCRIPTS - my %nics; +#get state of nic in "UP" status +#If bonded redhat then "SLAVE" or "MASTER" will be in the first line of stanza +#do not configure the loopback nic +if [ $bool_remove -eq 1 ];then + if [ "$str_os_type" = "aix" ];then + str_temp=`ifconfig -a | grep flags | grep -vi loopback | grep -v SALVE | grep -v MASTER | awk -F: {'print $1'}` + else + str_temp=`ip link show | grep -v link | grep -vi loopback | grep -v SALVE | grep -v MASTER | awk {'print $2'} | sed s/://` + fi + old_ifs=$IFS + IFS=$'\n' + array_nics_temp=($str_temp) + IFS=$old_ifs + for str_temp_nic in ${array_nics_temp[@]} + do + #the nic type should be ethernet + echo $str_temp_nic | grep -E "e(n|th)[0-9]+" + if [ $? -ne 0 ];then + continue + fi + if [ "$str_os_type" != "aix" ];then + brctl show 2>/dev/null | grep $str_temp_nic + #the nic belongs to a bridge, go to next + if [ $? -eq 0 ];then + continue + fi + fi + #the nic is defined this time + str_temp=$(hashget hash_defined_nics $str_temp_nic) + if [ -n "$str_temp" ];then + continue + fi + + if [ "$str_temp_nic" = "$str_inst_nic" -a $bool_cfg_inst_nic -eq 0 ];then + continue + fi + + #ignore the vlan interface + echo $str_temp_nic | grep "\." + if [ $? -eq 0 ];then + continue + fi - my $i = 0; - while ( $i < scalar(@ip_addr_array)) { - #print "array index $i: @ip_addr_array[$i]\n"; - # check if line starts with "number: text:" - # if so then it is the start of a nic stanza which looks like: - # 3: eth1: mtu 1500 qdisc mq state UP qlen 1000 - # link/ether 5c:f3:fc:a8:bb:93 brd ff:ff:ff:ff:ff:ff - # inet 9.114.34.232/24 brd 9.114.34.255 scope global eth1 - # inet6 fd55:faaf:e1ab:336:5ef3:fcff:fea8:bb93/64 scope global dynamic - # valid_lft 2591627sec preferred_lft 604427sec - # inet6 fd56::214:5eff:fe15:849b/64 scope global - # valid_lft forever preferred_lft forever - # inet6 fe80::5ef3:fcff:fea8:bb93/64 scope link - # valid_lft forever preferred_lft forever + logger -t xcat -p local4.info "confignics: remove nic $str_temp_nic" + echo "confignics on $NODE: remove nic $str_temp_nic" + configeth -r $str_temp_nic + done +fi - if ( $ip_addr_array[$i] =~ /^(\d+): / ) { - # get nic name - $ip_addr_array[$i] =~ /^\d+: ([^:].*):/; - $nic_name = $1; +old_ifs=$IFS +IFS=$' ' +array_nics_temp=($str_all_nics) +IFS=$old_ifs +for key in ${array_nics_temp[@]} +do + key=`echo $key | sed 's/^ \+//' | sed 's/ \+$//'` + str_nic_type= + str_value=$(hashget hash_defined_nics $key) + if [ "$key" = "$str_inst_nic" -a $bool_cfg_inst_nic -eq 0 ];then + continue + fi + old_ifs=$IFS + IFS=$',' + array_temp=($str_value) + IFS=$old_ifs - # get state of nic either "UP" if different, such as DOWN, not configured - # then assume state is DOWN. - if ($ip_addr_array[$i] =~ /,UP/ ) { - $nic_state = "UP"; - } - else { - $nic_state = "DOWN"; - } + if [ "${array_temp[3]}" ];then + logger -t xcat -p local4.info "confignics: processing custom scripts: ${array_temp[3]} for interface $key" + echo "confignics on $NODE: processing custom scripts: ${array_temp[3]} for interface $key" + ${array_temp[3]} + else + if [ "${array_temp[1]}" ];then + str_nic_type=`echo ${array_temp[1]} | tr "[A-Z]" "[a-z]"` + else + if [ `echo $key | grep -E '(eth|en)[0-9]+'` ];then + str_nic_type="ethernet" + elif [ `echo $KEY | grep -E 'ib[0-9]+'` ];then + str_nic_type="infiniband" + fi + fi - # Check if this nic is part of a bridge or bonded interface. If bonded on - # redhat then "SLAVE" or "MASTER" will be in the first line of stanza - # inside <>. - # - # A bridged interface is a little different. The command, "brctl show", is used - # to show information about bridged interfaces. The subroutine get_bridged_nics() - # writes out $bridgednics which is a comma separated strings of bridged nics. - # If $nic_name matches a bridgednic then set nic_slave=1 for now to lump them - # with bonded nics for now since we will not unconfigure bridged or bonded nics. - # - $nic_slave = 0; # default to 0 - if ($ip_addr_array[$i] =~ /SLAVE/ ) { - $nic_slave = 1; - } - if ($ip_addr_array[$i] =~ /MASTER/ ) { - $nic_slave = 1; - } - if ($nic_name =~ /$bridgednics/) { - $nic_slave = 1; - } + if [ $str_nic_type = "ethernet" ];then + logger -t xcat -p local4.info "confignics: call 'configeth $key ${array_temp[0]} ${array_temp[2]}'" + echo "confignics on $NODE: call 'configeth $key ${array_temp[0]} ${array_temp[2]}'" + configeth $key ${array_temp[0]} ${array_temp[2]} + elif [ $str_nic_type = "infiniband" ];then + if [ $str_ib_nics ];then + str_ib_nics=$str_ib_nics","$key + else + str_ib_nics=$key + fi + else + logger -t xcat -p local4.info "confignics: unknown type $str_nic_type for NIC: $key" + echo "confignics on $NODE: unknown type $str_nic_type for NIC: $key" + fi + fi +done - # example output shows type is "link/ether" for ethernet or - # "link/infiniband" for ib. Look ahead to next line for this. - $ip_addr_array[$i+1] =~ /^\s+link\/([a-z]+) /; - $nic_type = $1; - - $i++; - - # CHECK: it looks like there could be a usb nic ethernet adapter. Need to investigate - # if more needs to be done for that such as it is handled differently. - # If value is not "ether" or "infiniband" then continue on to next stanza - if ($nic_type ne "ether" && $nic_type ne "infiniband") { - next; - } - - my @line = split(' ', $ip_addr_array[$i]); - $nic_mac = $line[1]; - - # move on to next line and loop through all lines for additional information or - # and until the line is the start of a new stanza. - # This is where things get dicey and may need enhancements: - # inet 70.0.0.182/24 brd 70.0.0.255 scope global eth5 - # indicates an ipv4 address with a netmask of /24, a broadcast address, - # scope global nicname (eth5). If this was an aliased ip then nicname would be eth5:1 or such. - # inet6 fd55:faaf:e1ab:336:3640:b5ff:fe89:66c4/64 scope global dynamic - # it appears that valid ips have "scope global" - - $i++; - # print "NIC: $nic_name, TYPE: $nic_type, MAC: $nic_mac SLAVE: $nic_slave, STATE: $nic_state \n"; - $nics{$nic_name} = {}; - $nics{$nic_name}->{state} = $nic_state; - $nics{$nic_name}->{mac} = $nic_mac; - $nics{$nic_name}->{slave} = $nic_slave; - $nics{$nic_name}->{type} = $nic_type; - $nics{$nic_name}->{ips} = []; - - while ($i < scalar(@ip_addr_array) && !($ip_addr_array[$i] =~ /^(\d+): / ) ) { - # $ip_proto - is either inet or inet6 - # $ip_mask is "ipaddr or ipv6addr"/netmask and possibly "brd broadcastip" - # $scope has the scope (global, link, site, host) if global or site then - # only data after scope is the nic "label", i.e. eth0, eth5:1. - # note that "tentative" may appear but is not a label. - # On RH for an ip alias with same netmask/subnet then line will be: - # inet 11.0.0.80/16 brd 11.0.255.255 scope global secondary eth2:1 - - my ($ip_proto, $ip_mask, $scope) = - $ip_addr_array[$i]=~/\s+(inet|inet6)\s+(.+)\s+scope\s+(.+)$/; - - if ( $ip_proto =~ /inet/ ) { # line contains inet or inet6. Process info - my ($nic_ip_mask, $junk) = split(' ', $ip_mask); - my ($nic_ip, $nic_mask) = split('\/', $nic_ip_mask); - my ($sc, $label, $more_label) = split(' ', $scope); - if ( $sc ne "link" ) { # this is a valid one to keep - - if ($label eq "secondary") { - $label = $more_label; - } - #print "\tPROTO: $ip_proto, IP: $nic_ip, MASK: $nic_mask, SCOPE: $sc, LABEL:$label\n"; - push @{$nics{$nic_name}->{ips}},{ip => $nic_ip, netmask => $nic_mask, label => $label }; - } - } - $i++; - } - next; # next nic stanza or end of file. - } - $i++; - } - return \%nics; -} - -sub get_install_nic { - # get "NODE" from env, resolve to ip and determine which nic it belongs - # to. This should be the "base" nic, i.e. eth0, eth1 - not eth1:1 - # To do: Need to find equivalent methods for an ipv6 address. - - my $node = $ENV{NODE}; - my $installnic = $ENV{INSTALLNIC}; - my $primarynic = $ENV{PRIMARYNIC}; - my $i_p_nic = ''; # variable to hold installnic or primarynic value - my @ip_info; - my $inst_ip; - my @addr_info; - my %hash = $cfg_nic_ref_hash; - - @addr_info = gethostbyname($node); - @ip_info = unpack("C4", $addr_info[4]); # Is this only for ipv4 or does this include ipv6 as well? - $inst_ip = join(".",@ip_info); - - # get ip output, compare ip_addr and determine nic. - - foreach my $k (keys %$cfg_nic_ref_hash) { - my $nic = $cfg_nic_ref_hash->{$k}; - my $ips = $nic->{'ips'}; - if (defined($ips)) { - foreach my $ip_info (@$ips) { - my $ip = $ip_info->{'ip'}; - # print " IP:$ip"; - if ($ip eq $inst_ip) { - return $k; - } - } - } - } - - # install nic not found from configured nics. Try to get install nic from environment - # variables. - if ($installnic) { - $i_p_nic = $installnic; - } - elsif ($primarynic) { - $i_p_nic = $primarynic; - } - - if (!$i_p_nic) { - system("logger -t xcat -p local4.info 'confignics $thisnode: installnic and primarynic are not defined', use 'mac' by default."); - $i_p_nic = "mac"; - } - - if ($i_p_nic =~ /(e(n|th)\d+)$/ ) { - $inst_nic = $1; - } elsif ($i_p_nic 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 $thisnode: install nic $inst_nic not known '"); - } - return; -} - -# subroutine compares configured nic hash with defined nics from nics table. -# If configured nic is not in nics table and it is not the install nic then -# set global variables $rem_eth_nics and $rem_ibnics. -# This subroutine needs to be called after get_current_nics() and after parsing -# custom scripts and nics to be configured. - -sub set_nics_to_remove { - my $do_not_remove; - my %hash = $cfg_nic_ref_hash; - foreach my $nic_key (keys %$cfg_nic_ref_hash) { - my $nic = $cfg_nic_ref_hash->{$nic_key}; - # check if $nic is in $ethnics, $ibnics, $cust_script_nics or is $inst_nic. - # if not then add to appropriate list to be removed. - if ($nic_key eq $inst_nic) { - } - elsif ($ethnics =~ /$nic_key/ ) { - } - elsif ($ibnics =~ /$nic_key/) { - } - elsif ($cust_script_nics{$nic_key}) { - } - else { - # now check if nic is part of bonded or bridged interface. - # - if ( $nic->{slave} ) { - system("logger -t xcat -p local4.info 'confignics $thisnode: Not removing $nic_key. It is part of a bonded or bridged interface. '"); - } - elsif ( $nic_key =~ /@/ ) { - # For a vlan interface on redhat the nic name appears as - # nic.vlan@nic, i.e. eth0.30@eth0 and in this case the label will be - # eth0.30. So verify that there is no "@" in the nic name (should we - # also check that the label contains a "."?) - - my ($label, $base) = split(/@/,$nic_key); - - # need to make sure that $base is not added to nics to be removed. - # add both the label and base to $do_not_remove. - if ($do_not_remove) { - $do_not_remove = $label . "," . $base; - } - else { - $do_not_remove = $do_not_remove . "," . $label . "," . $base; - } - } - else { - # finally have a nic to remove. Determine if it is ib or eth - if ($nic->{type} eq "ether") { - if ( $rem_eth_nics ) { - $rem_eth_nics = $rem_eth_nics . "," . $nic_key; - } - else { - $rem_eth_nics = $nic_key; - } - } - if ($nic->{type} eq "infiniband") { - if ( $rem_ib_nics ) { - $rem_ib_nics = $rem_ib_nics . "," . $nic_key; - } - else { - $rem_ib_nics = $nic_key; - } - } - } - } - } -} - - -# Bridged interfaces do not show differently than ethernet nics in -# the "ip addr show" command. Therefore the command "brctl show" is -# used to get the bridged nics. -# This subroutine will set the global variable $bridgednics. -# brctl show output is similar to: -# bridge name bridge id STP enabled interfaces -# virbr0 8000.5254004a3d54 yes virbr0-nic -# first line is skipped as it is the heading. The values specified by -# bridge name and interfaces show up as nics in the "ip addr show" output. -# Therefore need to put both of these # in the $bridgednics string -# because we don't want to remove either of those interfaces. - -sub get_bridged_nics { - # first, ensure that brctl is installed. If not then just exit since there will be no - # bridged interfaces. - my $i; - if ( -e "/usr/sbin/bcrtl" ) { - my @bridge_out = `brctl show`; - my $lines = scalar(@bridge_out); - for ($i=1; $i < $lines ; $i++) { - - # brctl ouput puts half tabs '\cI' and line feed \cJ' chars in - # the ouput. Need to convert these to spaces then split. - # Get first and last values for nics. - - $bridge_out[$i] =~ s/\cI/ /g; - my @br = split(/ /,$bridge_out[$i]); - if ( $bridgednics ) { - $bridgednics = $bridgednics . "," . $br[0] . "," . $br[-1]; - } - else { - $bridgednics = $br[0] . "," . $br[-1]; - } - } - } -} +if [ -n "$str_ib_nics" ];then + logger -t xcat -p local4.info "confignics: executed script: configib for nics: $str_ib_nics, ports: $num_iba_ports" + echo "confignics on $NODE: executed script: configib for nics: $str_ib_nics, ports: $num_iba_ports" + NIC_IBNICS=$str_ib_nics NIC_IBAPORTS=$num_iba_ports configib +else + if [ $bool_remove -eq 1 ];then + logger -t xcat -p local4.info "confignics: executed script: 'configib -u' to remove all ib nics and configuration files" + echo "confignics on $NODE: executed script: 'configib -r' to remove all ib nics and configuration files" + configib + fi +fi diff --git a/xCAT/postscripts/xcatlib.sh b/xCAT/postscripts/xcatlib.sh new file mode 100644 index 000000000..e5b5da8fd --- /dev/null +++ b/xCAT/postscripts/xcatlib.sh @@ -0,0 +1,17 @@ +function hashencode(){ + local map="$1" + echo `echo $map | sed 's/\./xDOTx/g' | sed 's/:/xCOLONx/g' | sed 's/,/:xCOMMAx/g'` +} + +function hashset(){ + local hashname="hash${1}${2}" + local value=$3 + hashname=$(hashencode $hashname) + eval "${hashname}='${value}'" +} + +function hashget(){ + local hashname="hash${1}${2}" + hashname=$(hashencode $hashname) + eval echo "\$${hashname}" +}