From bf183224c7424732ef245e00bb3b0be6df60a96d Mon Sep 17 00:00:00 2001
From: xq2005 <qxuqxu@cn.ibm.com>
Date: Fri, 2 Aug 2013 03:14:45 -0700
Subject: [PATCH 01/26] 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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 = <FH>;
-    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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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}"
+}

From 106dc7874aaf79ca47e8c982125e3e3927b52d91 Mon Sep 17 00:00:00 2001
From: xcat ubuntu build machine <bp@us.ibm.com>
Date: Mon, 5 Aug 2013 03:08:50 +0000
Subject: [PATCH 02/26] changes to build-ubunturepo for git repo

---
 build-ubunturepo | 55 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 41 insertions(+), 14 deletions(-)

diff --git a/build-ubunturepo b/build-ubunturepo
index a9a2a7e92..d133d2af3 100755
--- a/build-ubunturepo
+++ b/build-ubunturepo
@@ -41,6 +41,13 @@ printusage()
 # For the purpose of getting the distribution name
 . /etc/lsb-release
 
+# Process cmd line variable assignments, assigning each attr=val pair to a variable of same name
+for i in $*; do
+        # upper case the variable name
+        varstring=`echo "$i"|cut -d '=' -f 1|tr '[a-z]' '[A-Z]'`=`echo "$i"|cut -d '=' -f 2`
+        export $varstring
+done
+
 # Supported distributions
 dists="maverick natty oneiric precise"
 
@@ -122,9 +129,40 @@ then
 
     ver=`cat Version`
     if [ "$PROMOTE" != 1 ]; then
+        code_change=0
+        update_log=''
         #get the version
-        echo "svn --quiet update Version"
-        svn --quiet up Version
+        if [ "$REL" = "xcat-core" ];then
+            git_flag=1
+            REL=`git rev-parse --abbrev-ref HEAD`
+            if [ "$REL" = "master" ]; then
+                REL="devel"
+            fi
+            if [ -z "$GITUP" ];then
+                update_log=../coregitup
+                echo "git pull > $update_log"
+                git pull > $update_log
+            else
+                update_log=$GITUP
+            fi
+
+            if ! grep -q  'Already up-to-date' $update_log; then
+                code_change=1
+            fi
+        else
+            git_flag=0
+            if [ -z "$SVNUP" ];	then
+                update_log=../coresvnup
+                echo "svn up > $update_log"
+                svn up > $update_log
+            else
+                update_log=$SVNUP
+            fi
+
+            if ! grep -q 'At revision' $update_log;then
+                code_change=1
+            fi
+        fi
         ver=`cat Version`
         short_ver=`cat Version|cut -d. -f 1,2`
         short_short_ver=`cat Version|cut -d. -f 1`
@@ -132,17 +170,6 @@ then
         #TODO: define the core path and tarball name
         tarball_name="core-debs-snap.tar.bz2"
 
-        #update the code from svn
-        svn_up_log="../coresvnup"
-        echo "svn update > $svn_up_log"
-        svn update > $svn_up_log
-
-        #makesure the code change status
-        code_change=0
-        if ! grep -q 'At revision' $svn_up_log;then
-            code_change=1
-        fi
-
         if [ $code_change == 0 -a "$UP" != 1 -a "$BUILDALL" != 1 ]; then
             echo "Nothing new detected"
             exit 0
@@ -167,7 +194,7 @@ then
         for file in `echo $packages`
         do
             file_low=`echo $file | tr '[A-Z]' '[a-z]'`
-            if grep -q $file $svn_up_log || [ "$BUILDALL" == 1 -o "$file" = "perl-xCAT" ]; then
+            if grep -q $file $update_log || [ "$BUILDALL" == 1 -o "$file" = "perl-xCAT" ]; then
                 rm -f ../../debs/${file_low}_*.deb
                 #only for genesis package
                 rm -f ../../debs/${file_low}-amd64_*.deb

From 008e72d316ddf89a94ada4e83902c5bdd6db7012 Mon Sep 17 00:00:00 2001
From: Lei Ai <leiaibj@cn.ibm.com>
Date: Mon, 5 Aug 2013 15:10:16 +0800
Subject: [PATCH 03/26] initialize global variables to avoid Cannot
 re-provision the node which has been removed

---
 xCAT-server/lib/xcat/plugins/profilednodes.pm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm
index 961f05c11..8fff76131 100644
--- a/xCAT-server/lib/xcat/plugins/profilednodes.pm
+++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm
@@ -385,6 +385,7 @@ Usage:
             $allmacs{$macstr} = 0;
         }
     }
+    %allmacsupper = ();
     foreach (keys %allmacs){
             $allmacsupper{uc($_)} = 0;
     }
@@ -1107,6 +1108,7 @@ Usage:
             $allmacs{$macstr} = 0;
         }
     }
+    %allmacsupper = ();
     foreach (keys %allmacs){
         $allmacsupper{uc($_)} = 0;
     }
@@ -1508,6 +1510,7 @@ sub findme{
             $allmacs{$macstr} = 0;
         }
     }
+    %allmacsupper = ();
     foreach (keys %allmacs){
         $allmacsupper{uc($_)} = 0;
     }

From a7e3e9ec2ab051d2de91092777c0906431416b15 Mon Sep 17 00:00:00 2001
From: xq2005 <qxuqxu@cn.ibm.com>
Date: Mon, 5 Aug 2013 01:26:15 -0700
Subject: [PATCH 04/26] load sha.pm on ubuntu instand of sha1.pm

---
 perl-xCAT/xCAT/Utils.pm     | 11 +++++++----
 xCAT-server/debian/postinst | 13 +------------
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm
index 69764b121..9d1da5e9c 100644
--- a/perl-xCAT/xCAT/Utils.pm
+++ b/perl-xCAT/xCAT/Utils.pm
@@ -21,10 +21,13 @@ use File::Path;
 use Socket;
 use strict;
 use Symbol;
-my $sha1support = eval {
-	require Digest::SHA1;
-	1;
-};
+my $sha1support;
+if ( -f "/etc/debian_version" ){
+    $sha1support = eval {require Digest::SHA; 1;};
+}
+else {
+    $sha1support = eval { require Digest::SHA1; 1;};
+}
 use IPC::Open3;
 use IO::Select;
 use xCAT::GlobalDef;
diff --git a/xCAT-server/debian/postinst b/xCAT-server/debian/postinst
index 5988fcf27..b9f5c07f0 100644
--- a/xCAT-server/debian/postinst
+++ b/xCAT-server/debian/postinst
@@ -21,12 +21,7 @@ set -e
 case "$1" in
     configure)
 	. /etc/profile.d/xcat.sh
-    if [ ! -e "/etc/rc0.d/K60xcatd" ];then
-        update-rc.d xcatd start 85 2 3 4 5 . stop 60 0 1 6 .
-        update-rc.d xcatd enable 2
-    else
-	    update-rc.d xcatd enable
-    fi
+        update-rc.d xcatd defaults
 	if [ -f /tmp/xCAT-server_upgrade.tmp ]; then
 	    if [ -f "/proc/cmdline" ]; then   # prevent running it during install into chroot image
 		/etc/init.d/xcatd reload
@@ -36,12 +31,6 @@ case "$1" in
 	ln -sf /opt/xcat/sbin/xcatd /usr/sbin/xcatd
     #SHA1 has been get rid of after Squeeze released. Its functionality is also provided by Digest::SHA (which is in core).
     #but ipmi.pm need SHA1.pm, so create this link
-    shalocate=`find /usr/lib/perl -name "SHA.pm"`
-    shalocate=${shalocate%SHA.pm}
-    cd $shalocate
-    if [ ! -e SHA1.pm ];then
-        ln -s SHA.pm SHA1.pm
-    fi
     cd -
     ;;
 

From ecd518e31e6341c4b7099d2ac71ac57b8b06fe18 Mon Sep 17 00:00:00 2001
From: xq2005 <qxuqxu@cn.ibm.com>
Date: Mon, 5 Aug 2013 01:35:40 -0700
Subject: [PATCH 05/26] import sha.pm on ubuntu instands of sha1.pm

---
 perl-xCAT/xCAT/Utils.pm                      |  8 ++++++-
 xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm | 17 +++++++++----
 xCAT-server/lib/perl/xCAT/IPMI.pm            | 25 ++++++++++++++------
 xCAT-server/lib/xcat/plugins/ipmi.pm         |  1 -
 4 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm
index 9d1da5e9c..24f4bbf99 100644
--- a/perl-xCAT/xCAT/Utils.pm
+++ b/perl-xCAT/xCAT/Utils.pm
@@ -179,7 +179,13 @@ sub genUUID
         return $uuid;
     } elsif ($args{url} and $sha1support) { #generate a UUIDv5 from URL
         #6ba7b810-9dad-11d1-80b4-00c04fd430c8 is the uuid for URL namespace
-        my $sum = Digest::SHA1::sha1('6ba7b810-9dad-11d1-80b4-00c04fd430c8'.$args{url});
+        my $sum = '';
+        if ( -f "/etc/debian_version" ){
+            $sum = Digest::SHA::sha1('6ba7b810-9dad-11d1-80b4-00c04fd430c8'.$args{url});
+        }
+        else{
+            $sum = Digest::SHA1::sha1('6ba7b810-9dad-11d1-80b4-00c04fd430c8'.$args{url});
+        }
         my @data = unpack("C*",$sum);
         splice @data,16;
         $data[6] = $data[6] & 0xf;
diff --git a/xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm b/xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm
index d53239032..5588f2157 100644
--- a/xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm
+++ b/xCAT-buildkit/lib/perl/xCAT/BuildKitUtils.pm
@@ -19,10 +19,19 @@ use File::Path;
 use Socket;
 use strict;
 use Symbol;
-my $sha1support = eval {
-	require Digest::SHA1;
-	1;
-};
+if ( -f "/etc/debian_version" ) {
+    $sha1support = eval {
+        require Digest::SHA;
+        1;
+    };
+}
+else {
+
+    $sha1support = eval {
+        require Digest::SHA1;
+        1;
+    };
+}
 use IPC::Open3;
 use IO::Select;
 use warnings "all";
diff --git a/xCAT-server/lib/perl/xCAT/IPMI.pm b/xCAT-server/lib/perl/xCAT/IPMI.pm
index c13c01efd..92ee0ab65 100644
--- a/xCAT-server/lib/perl/xCAT/IPMI.pm
+++ b/xCAT-server/lib/perl/xCAT/IPMI.pm
@@ -46,13 +46,24 @@ use Digest::MD5 qw/md5/;
 my $pendingpackets=0;
 my %tabooseq; #TODO: this is a global which means one taboo in the whole set causes unrelated session objects to consider it taboo unnecessarily
 my $maxpending; #determined dynamically based on rcvbuf detection
-my $ipmi2support = eval {
-    require Digest::SHA1;
-    Digest::SHA1->import(qw/sha1/);
-    require Digest::HMAC_SHA1;
-    Digest::HMAC_SHA1->import(qw/hmac_sha1/);
-    1;
-};
+if ( -f "/etc/debian_release" ){
+    $ipmi2support = eval {
+        require Digest::SHA;
+        Digest::SHA->import(qw/sha1/);
+        require Digest::HMAC_SHA1;
+        Digest::HMAC_SHA1->import(qw/hmac_sha1/);
+        1;
+    };
+}
+else {
+    $ipmi2support = eval {
+        require Digest::SHA1;
+        Digest::SHA1->import(qw/sha1/);
+        require Digest::HMAC_SHA1;
+        Digest::HMAC_SHA1->import(qw/hmac_sha1/);
+        1;
+    };
+}
 my $aessupport;
 if ($ipmi2support) {
     $aessupport = eval {
diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm
index 3bd5fb5f8..1d7abb317 100644
--- a/xCAT-server/lib/xcat/plugins/ipmi.pm
+++ b/xCAT-server/lib/xcat/plugins/ipmi.pm
@@ -73,7 +73,6 @@ use IO::Socket;
 use IO::Select;
 use Class::Struct;
 use Digest::MD5 qw(md5);
-use Digest::SHA1 qw(sha1);
 use POSIX qw(WNOHANG mkfifo strftime);
 use Fcntl qw(:flock);
 

From 56b6f4c1b29cd26ebe1cfcf864c1631df9c40f12 Mon Sep 17 00:00:00 2001
From: xq2005 <qxuqxu@cn.ibm.com>
Date: Mon, 5 Aug 2013 01:46:05 -0700
Subject: [PATCH 06/26] xHRM support ubuntu/debian

---
 xCAT-server/share/xcat/scripts/xHRM | 333 ++++++++++++++++++----------
 1 file changed, 214 insertions(+), 119 deletions(-)

diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM
index 38b1f5227..470893c00 100755
--- a/xCAT-server/share/xcat/scripts/xHRM
+++ b/xCAT-server/share/xcat/scripts/xHRM
@@ -7,48 +7,109 @@ function get_def_interface {
     #we are, however, presuming ipv4 for the moment
     retval=$(ping -c 1 `hostname`|head -n 1|cut -d\( -f 2|cut -d\) -f 1)
     if [ -z "$retval" -o "127.0.0.1" = "$retval" ]; then #ok, that didn't pan out, now we grab the first address that looks sane
-	retval=`ifconfig|grep inet" " |grep -v addr:127.0.0.1|grep -v 'addr:169.254'|head -n 1|cut -d: -f 2|cut -d' ' -f 1`
+        retval=`ifconfig|grep inet" " |grep -v addr:127.0.0.1|grep -v 'addr:169.254'|head -n 1|cut -d: -f 2|cut -d' ' -f 1`
     fi
     if [ -z "$retval" ]; then 
-	echo "ERROR: Unable to reasonably guess the 'default' interface" >&2
-	exit 1
+        echo "ERROR: Unable to reasonably guess the 'default' interface" >&2
+        exit 1
     fi
     iface=`ifconfig|grep -v inet6|egrep '(Link|inet)'|grep -B1 'addr:'$retval |head -n 1|awk '{print $1}'`
     if [ -z "$iface" ]; then
-	echo "ERROR: Unable to reasonably guess the default interface" >&2
-	exit 1
+        echo "ERROR: Unable to reasonably guess the default interface" >&2
+        exit 1
     fi
     if brctl show | grep ^$iface >& /dev/null; then #
-	OIFS=$IFS
-	IFS=$'\n'
-	INMATCH=0
-	for brline in $(brctl show); do
-	    IFS=$OIFS
-	    if [ $(expr match "$brline" $iface) == $(expr length $iface) ]; then
-		INMATCH=1
-	    elif [ $(expr match "$brline" "	") != 1 ]; then
-		INMATCH=0
-	    fi
-	    if [ "$INMATCH" == 1 ];  then
-		if ! ethtool -i `echo $brline|awk '{print $NF}'`|grep "driver: tun" >& /dev/null; then
-		    iface=`echo $brline|awk '{print $NF}'`
-		    echo "$iface"
-		    IFS=$OFIS
-		    return
-		fi
-	    fi
-	done
-	IFS=$OFIS
+        OIFS=$IFS
+        IFS=$'\n'
+        INMATCH=0
+        for brline in $(brctl show); do
+            IFS=$OIFS
+            if [ $(expr match "$brline" $iface) == $(expr length $iface) ]; then
+                INMATCH=1
+                elif [ $(expr match "$brline" " ") != 1 ]; then
+                INMATCH=0
+            fi
+            if [ "$INMATCH" == 1 ];  then
+                if ! ethtool -i `echo $brline|awk '{print $NF}'`|grep "driver: tun" >& /dev/null; then
+                    iface=`echo $brline|awk '{print $NF}'`
+                    echo "$iface"
+                    IFS=$OFIS
+                    return
+                fi
+            fi
+    done
+    IFS=$OFIS
     else 
-	echo "$iface"
+        echo "$iface"
     fi
 }
+
+#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
+function debianpreconf(){
+    #create the config sub dir
+    if [ ! -d "/etc/network/interfaces.d" ];then
+        mkdir -p "/etc/network/interfaces.d"
+    fi
+    #search xcat flag
+    XCATFLAG=`grep "#XCAT_CONFIG" /etc/network/interfaces`
+    if [ -n "$XCATFLAG" ];then
+        return
+    fi
+
+    #back up the old interface configure
+    if [ ! -e "/etc/network/interfaces.bak" ];then
+        mv /etc/network/interfaces /etc/network/interfaces.bak
+    fi
+
+    #create the new config file
+    echo "#XCAT_CONFIG" > /etc/network/interfaces
+    echo "source /etc/network/interfaces.d/*" >> /etc/network/interfaces
+
+    CONFFILE=''
+
+    #read the backfile
+    cat /etc/network/interfaces.bak | while read LINE
+    do
+        if [ ! "$LINE" ];then
+            continue
+        fi
+        FIRSTCHAR=${LINE:0:1}
+        if [ $FIRSTCHAR = '#' ];then
+            continue
+        fi
+
+        CONFTYPE=`echo $LINE | cut -d" " -f1`
+        if [ $CONFTYPE = 'auto' -o $CONFTYPE = 'allow-hotplug' ];then
+            LINE=${LINE#$CONFTYPE}
+            for NICNAME in $LINE; do
+                echo "$CONFTYPE $NICNAME" > "/etc/network/interfaces.d/$NICNAME"
+            done
+        elif [ $CONFTYPE = 'iface' -o $CONFTYPE = 'mapping' ];then
+            #find out the nic name, should think about the eth0:1
+            NICNAME=`echo $LINE | cut -d" " -f 2 | cut -d":" -f 1`
+            CONFFILE="/etc/network/interfaces.d/$NICNAME"
+            if [ ! -e $CONFFILE ];then
+                echo "auto $NICNAME" > $CONFFILE
+            fi
+
+            #write lines into the conffile
+            echo $LINE >> $CONFFILE
+        else
+            echo $LINE >> $CONFFILE
+        fi
+
+    done
+}
+
 if [ "storageprereq" = "$1"  ]; then
     MOUNTURI="$2"
     DIRNAME=`echo $MOUNTURI|sed -e 's!nfs://!nfs_!'`
     MOUNTPATH=`echo $DIRNAME|sed -e 's!nfs_!!'|sed -e 's!/!:/!'`
     if mount|grep $MOUNTPATH > /dev/null; then
-	exit 0;
+        exit 0;
     fi
     mkdir -p /var/lib/xcat/vmnt/$DIRNAME
     mount $MOUNTPATH /var/lib/xcat/vmnt/$DIRNAME
@@ -67,29 +128,29 @@ elif [ "bridgeprereq" = "$1" ]; then
         if [ -n "$INSTALLNIC" ]; then
           NETDESC=$INSPORT:default
         else
-	  echo "Incorrect usage"
-	  exit 1
+            echo "Incorrect usage"
+            exit 1
         fi
     fi
     if echo "$NETDESC"|grep ':'> /dev/null; then
-	PORTS=`echo "$NETDESC"|cut -d: -f 1`
-	BNAME=`echo "$NETDESC"|cut -d: -f 2`
+        PORTS=`echo "$NETDESC"|cut -d: -f 1`
+        BNAME=`echo "$NETDESC"|cut -d: -f 2`
     else 
         if [ -n "$INSTALLNIC" ]; then
             PORTS=$INSPORT
         fi
-	BNAME=$NETDESC
+        BNAME=$NETDESC
     fi
     if brctl showstp "$BNAME" > /dev/null; then
-	echo "$BNAME"
-	exit 0
+        echo "$BNAME"
+        exit 0
     fi
     #Still here, that means we must build a bridge
     if [ -z "$PORTS" ]; then #No ports specified, default to whatever looks up
-	PORTS=$(get_def_interface)
+        PORTS=$(get_def_interface)
     fi
     if [ -z "$PORTS" ]; then #This has been checked many times before in theory, check again just in case
-	exit 1
+        exit 1
     fi
     #For now, we only support bridge name==network name.  This precludes
     #the config of the same vlan number on multiple fabrics, but
@@ -97,39 +158,40 @@ elif [ "bridgeprereq" = "$1" ]; then
     #I think it would be unwise to reuse them as it could confuse anyway)
     if echo "$PORTS"|grep '&'; then #we have bonding... fun to be had
     #To be slack, going to just support one bond for now..
-	modprobe bonding miimon=100 mode=4
-	PORTS=`echo $PORTS |sed -e 's/&/ /'`
-	ip link set bond0 up
-	for p in $PORTS; do
-	    #TODO: we are only going to manage the default
-	    #route for now
-	    saveroutes=`ip route | grep default| grep "dev $p"|grep via|sed -e 's/dev .*//'`
-	    OIFS=$IFS
-	    IFS=$'\n'
-	    saveip=`ip addr show dev $p scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'|sed -e 's/[^ ]*$//'`
-	    if [ ! -z "$saveip" ]; then
-	    	for line in $saveip; do 
-			ip addr add dev bond0 $line
-		done
-	    fi
-	    IFS=$OIFS
-	    ifenslave bond0 $p
-	    if [ ! -z "$saveroutes" ]; then
-		ip route add $saveroutes
-	    fi 
-	done
-	PORTS=bond0
+        modprobe bonding miimon=100 mode=4
+        PORTS=`echo $PORTS |sed -e 's/&/ /'`
+        ip link set bond0 up
+        for p in $PORTS; do
+            #TODO: we are only going to manage the default
+            #route for now
+            saveroutes=`ip route | grep default| grep "dev $p"|grep via|sed -e 's/dev .*//'`
+            OIFS=$IFS
+            IFS=$'\n'
+            saveip=`ip addr show dev $p scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'|sed -e 's/[^ ]*$//'`
+            if [ ! -z "$saveip" ]; then
+                for line in $saveip; do 
+                    ip addr add dev bond0 $line
+                done
+            fi
+            IFS=$OIFS
+            ifenslave bond0 $p
+            if [ ! -z "$saveroutes" ]; then
+                ip route add $saveroutes
+            fi 
+        done
+        PORTS=bond0
     fi
     if echo "$BNAME"|egrep '^vl(an)?[0123456789]' > /dev/null; then 
-	vlan="yes"
-	TNAME=${BNAME##vl}
-	TNAME=${TNAME##an}
-	#We have a vlan... more fun
-	modprobe 8021q
-	vconfig add $PORTS $TNAME
-	vconfig set_flag $PORTS.$TNAME 2 1 #Turn on GVRP where supported
-	ip link set $PORTS.$TNAME up
-	PORTS=$PORTS.$TNAME
+        vlan="yes"
+        TNAME=${BNAME##vl}
+        TNAME=${TNAME##an}
+        #We have a vlan... more fun
+        modprobe 8021q
+        vconfig add $PORTS $TNAME
+        vconfig set_flag $PORTS.$TNAME 2 1 #Turn on GVRP where supported
+        ip link set $PORTS.$TNAME up
+        PORTORG=$PORTS
+        PORTS=$PORTS.$TNAME
     fi
     #Now, $PORTS is 'the' physical device to participate in a bridge
     #TODO: we are only going to manage the default
@@ -143,98 +205,131 @@ elif [ "bridgeprereq" = "$1" ]; then
     saveip=`ip addr show dev $PORTS scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'|sed -e 's/[^ ]*$//'`
     #saveip=`ip addr show dev $PORTS scope global|grep inet|sed -e 's/inet.//'|sed -e 's/[^ ]*$//'`
     if [ ! -z "$saveip" ]; then
-    	for line in $saveip; do 
-    		IFS=$OIFS
-		ip addr add dev $BNAME $line
-	done
+        for line in $saveip; do 
+            IFS=$OIFS
+            ip addr add dev $BNAME $line
+        done
     else
         if [ ! -z "$3" ]; then
-	    ip addr add dev $BNAME $3 
-	fi
+            ip addr add dev $BNAME $3 
+        fi
     fi
     brctl addif $BNAME $PORTS
     if [ ! -z "$saveip" ]; then
-    	OIFS=$IFS
-	IFS=$'\n'
-    	for line in $saveip; do 
-    		IFS=$OIFS
-		ip addr del dev $PORTS $line
-	done
-	IFS=$OIFS
+        OIFS=$IFS
+        IFS=$'\n'
+        for line in $saveip; do 
+            IFS=$OIFS
+            ip addr del dev $PORTS $line
+        done
+       IFS=$OIFS
     fi
     IFS=$OIFS
     if [ ! -z "$saveroutes" ]; then
-	ip route add $saveroutes
+        ip route add $saveroutes
     fi
     
     #now save the settings into the config files so that they will be persistent among reboots
     if [[ $OSVER = sles* ]] || [[ $OSVER = suse* ]] || [[ -f /etc/SuSE-release ]]; then
-	nwdir="/etc/sysconfig/network"
-	isSLES=1
+        nwdir="/etc/sysconfig/network"
+        isSLES=1
+    elif [ -f "/etc/debian_version" ];then
+        debianpreconf
+        nwdir="/etc/network/interfaces.d"
+        isDebian=1
+        getcap /usr/bin/qemu-system-x86_64 | grep cap_net_admin
+        if [ $? ne 0 ];then
+            setcap cap_net_admin=ei /usr/bin/qemu-system-x86_64
+        fi
     else 
-	nwdir="/etc/sysconfig/network-scripts"
+        nwdir="/etc/sysconfig/network-scripts"
     fi 
     
      #write into the network configuration file
     if [[ $isSLES -eq 1 ]]; then
-	cat >$nwdir/ifcfg-$PORTS <<EOF
+        cat >$nwdir/ifcfg-$PORTS <<EOF
 DEVICE='$PORTS'
 ONBOOT='yes'
 BRIDGE='$BNAME'
 EOF
-	mac=`ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//'`
-	if [ ! -z "$mac" ]; then
-	    echo "HWADDR='$mac'" >> $nwdir/ifcfg-$PORTS
-	fi
-	if [ ! -z "$vlan" ]; then
-	    echo "VLAN='yes'" >> $nwdir/ifcfg-$PORTS
-	fi
-	cat >$nwdir/ifcfg-$BNAME <<EOF	    
+        mac=`ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//'`
+        if [ ! -z "$mac" ]; then
+            echo "HWADDR='$mac'" >> $nwdir/ifcfg-$PORTS
+        fi
+        if [ ! -z "$vlan" ]; then
+            echo "VLAN='yes'" >> $nwdir/ifcfg-$PORTS
+        fi
+        cat >$nwdir/ifcfg-$BNAME <<EOF      
 DEVICE='$BNAME'
 TYPE='Bridge'
 ONBOOT='yes'
 PEERDNS='yes'
 DELAY='0'
 EOF
-	if [ ! -z "$3" ]; then 
-	    echo "IPADDR='$3'" >> $nwdir/ifcfg-$BNAME 
-	    if [ ! -z "$4" ]; then
-		echo "NETMASK='$4'" >> $nwdir/ifcfg-$BNAME
-	    fi
-	else
-	    echo "BOOTPROTO=dhcp" >> $nwdir/ifcfg-$BNAME
-	fi
+        if [ ! -z "$3" ]; then 
+            echo "IPADDR='$3'" >> $nwdir/ifcfg-$BNAME 
+            if [ ! -z "$4" ]; then
+                echo "NETMASK='$4'" >> $nwdir/ifcfg-$BNAME
+            fi
+        else
+            echo "BOOTPROTO=dhcp" >> $nwdir/ifcfg-$BNAME
+        fi
+    elif [ $isDebian ];then
+        #ubuntu/debian
+        echo "auto $PORTS" >$nwdir/$PORTS
+        echo "iface $PORTS inet manual" >> $nwdir/$PORTS
+        
+        if [ ! -z "$vlan" ];then
+            echo "  vlan-raw-device $PORTORG"
+        fi
+
+        echo "auto $BNAME" > $nwdir/$BNAME
+        if [ ! -z "$3" ];then
+            echo "iface $BNAME inet static" >> $nwdir/$BNAME
+            echo "  address $3" >> $nwdir/$BNAME
+            if [ ! -z "$4" ];then
+                echo "  netmask $4" >> $nwdir/$BNAME
+            else
+                echo "  netmask 255.255.255.0" >> $nwdir/$BNAME
+            fi
+        else
+            echo "iface $BNAME inet dhcp" >> $nwdir/$BNAME
+        fi
+        echo "  bridge_ports $PORTS" >> $nwdir/$BNAME
+        echo "  bridge_stp off" >> $nwdir/$BNAME
+        echo "  bridge_fd 0" >> $nwdir/$BNAME
+        echo "  bridge_maxwait 0" >> $nwdir/$BNAME
     else
-	cat >$nwdir/ifcfg-$PORTS <<EOF
+        cat >$nwdir/ifcfg-$PORTS <<EOF
 DEVICE=$PORTS
 ONBOOT=yes
 BRIDGE=$BNAME
 EOF
-	mac=`ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//'`
-	if [ ! -z "$mac" ]; then
-	    echo "HWADDR=$mac" >> $nwdir/ifcfg-$PORTS
-	fi
-	if [ ! -z "$vlan" ]; then
-	    echo "VLAN=yes" >> $nwdir/ifcfg-$PORTS
-	fi
-	cat >$nwdir/ifcfg-$BNAME <<EOF	    
+        mac=`ip addr show dev $PORTS scope global|grep link|sed -e 's/link\/ether//'|sed -e 's/brd.*$//'|sed -e 's/[ ]*//'`
+        if [ ! -z "$mac" ]; then
+            echo "HWADDR=$mac" >> $nwdir/ifcfg-$PORTS
+        fi
+        if [ ! -z "$vlan" ]; then
+            echo "VLAN=yes" >> $nwdir/ifcfg-$PORTS
+        fi
+        cat >$nwdir/ifcfg-$BNAME <<EOF      
 DEVICE=$BNAME
 TYPE=Bridge
 ONBOOT=yes
 PEERDNS=yes
 DELAY=0
 EOF
-	if [ ! -z "$3" ]; then 
-	    echo "IPADDR=$3" >> $nwdir/ifcfg-$BNAME 
-	    if [ ! -z "$4" ]; then
-		echo "NETMASK=$4" >> $nwdir/ifcfg-$BNAME
-	    fi
-	else
-	    echo "BOOTPROTO=dhcp" >> $nwdir/ifcfg-$BNAME
-	fi
+        if [ ! -z "$3" ]; then 
+            echo "IPADDR=$3" >> $nwdir/ifcfg-$BNAME 
+            if [ ! -z "$4" ]; then
+                echo "NETMASK=$4" >> $nwdir/ifcfg-$BNAME
+            fi
+        else
+            echo "BOOTPROTO=dhcp" >> $nwdir/ifcfg-$BNAME
+        fi
     fi 
  
     ifup $BNAME
 fi #END bridge config.
 
-	
+    

From 3f56f0775e0f348635c479e1cb43d3ec4e864aaa Mon Sep 17 00:00:00 2001
From: xq2005 <qxuqxu@cn.ibm.com>
Date: Mon, 5 Aug 2013 01:50:29 -0700
Subject: [PATCH 07/26] xhrm_satisfy getting vlan information from nics table

---
 xCAT-server/lib/xcat/plugins/kvm.pm | 113 +++++++++++++++-------------
 1 file changed, 61 insertions(+), 52 deletions(-)

diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm
index 7bc988006..fc3880957 100644
--- a/xCAT-server/lib/xcat/plugins/kvm.pm
+++ b/xCAT-server/lib/xcat/plugins/kvm.pm
@@ -1046,69 +1046,80 @@ sub xhrm_satisfy {
     foreach (@nics) {
         s/=.*//; #this code cares not about the model of virtual nic
         my $nic=$_;
-	my $vlanip;
-	my $netmask;
-	my $subnet;
+        my $vlanip;
+        my $netmask;
+        my $subnet;
         my $vlan;
         my $interface;
-	if ($nic =~ /^vl([\d]+)$/) {
-	    $vlan=$1;
-	    my $nwtab=xCAT::Table->new("networks", -create =>0);
-	    if ($nwtab) {
-		my $sent = $nwtab->getAttribs({vlanid=>"$vlan"},'net','mask');
-		if ($sent and ($sent->{net})) {
-		    $subnet=$sent->{net};
-		    $netmask=$sent->{mask};
-		} 
-		if (($subnet) && ($netmask)) {
-		    my $hoststab = xCAT::Table->new("hosts", -create => 0);
-		    if ($hoststab) {
-			my $tmp = $hoststab->getNodeAttribs($hyp, ['otherinterfaces']);
-			if (defined($tmp) && ($tmp) && $tmp->{otherinterfaces})
-			{
-			    my $otherinterfaces = $tmp->{otherinterfaces};
-			    my @itf_pairs=split(/,/, $otherinterfaces);
-			    foreach (@itf_pairs) {
-				my ($name,$vip)=split(/:/, $_);
-				if(xCAT::NetworkUtils->ishostinsubnet($vip, $netmask, $subnet)) {
-				    $vlanip=$vip;
-				    last;
-				}
-			    }
-			}
-		    }
-		}
-	    }
-	}
+        if ($nic =~ /^vl([\d]+)$/) {
+            $vlan=$1;
+            my $nwtab=xCAT::Table->new("networks", -create =>0);
+            if ($nwtab) {
+                my $sent = $nwtab->getAttribs({vlanid=>"$vlan"},'net','mask');
+                if ($sent and ($sent->{net})) {
+                    $subnet=$sent->{net};
+                    $netmask=$sent->{mask};
+                } 
+                if (($subnet) && ($netmask)) {
+                    my $hoststab = xCAT::Table->new("hosts", -create => 0);
+                    if ($hoststab) {
+                        my $tmp = $hoststab->getNodeAttribs($hyp, ['otherinterfaces']);
+                        if (defined($tmp) && ($tmp) && $tmp->{otherinterfaces})
+                        {
+                            my $otherinterfaces = $tmp->{otherinterfaces};
+                            my @itf_pairs=split(/,/, $otherinterfaces);
+                            foreach (@itf_pairs) {
+                                my ($name,$vip)=split(/:/, $_);
+                                if(xCAT::NetworkUtils->ishostinsubnet($vip, $netmask, $subnet)) {
+                                    $vlanip=$vip;
+                                    last;
+                                }
+                            }
+                        }
+                    }
+                    #get the vlan ip from nics table
+                    unless ($vlanip) {
+                        my $nicstable = xCAT::Table->new("nics", -create => 0);
+                        if ($nicstable) {
+                            my $tmp = $nicstable->getNodeAttribs($hyp, ['nicips']);
+                            if ($tmp && $tmp->{nicips}){
+                                $tmp =~ /vl${vlan}nic!([^,]*)/;
+                                $vlanip = $1;
+                            }
+                        }
+                    }
+                }
+            }
+        }
 
         #get the nic that vlan tagged 
         my $swtab = xCAT::Table->new("switch", -create => 0);
         if ($swtab) {
-	    my $tmp_switch = $swtab->getNodesAttribs([$hyp], ['vlan','interface']);
-	    if (defined($tmp_switch) && (exists($tmp_switch->{$hyp}))) { 
-	        my $tmp_node_array=$tmp_switch->{$hyp};
-	        foreach my $tmp (@$tmp_node_array) {
-		    if (exists($tmp->{vlan})) {
-		        my $vlans = $tmp->{vlan};
-		        foreach my $vlan_tmp (split(',',$vlans)) {
-			    if ($vlan_tmp == $vlan) {
-		                if (exists($tmp->{interface})) {
-			            $interface=$tmp->{interface};
-		                }
-                                last;
+            my $tmp_switch = $swtab->getNodesAttribs([$hyp], ['vlan','interface']);
+            if (defined($tmp_switch) && (exists($tmp_switch->{$hyp}))) { 
+                my $tmp_node_array=$tmp_switch->{$hyp};
+                foreach my $tmp (@$tmp_node_array) {
+                    if (exists($tmp->{vlan})) {
+                        my $vlans = $tmp->{vlan};
+                        foreach my $vlan_tmp (split(',',$vlans)) {
+                            if ($vlan_tmp == $vlan) {
+                                if (exists($tmp->{interface})) {
+                                    $interface=$tmp->{interface};
+                                }
+                            last;
                             }
-		        }
-		    }
-	        }
-	    }
+                        }
+                    }
+                }
+            }
         }
         
         if (($interface) || ($interface =~ /primary/)) {
             $interface =~ s/primary(:)?//g;
         }
-	#print "interface=$interface nic=$nic vlanip=$vlanip netmask=$netmask\n";
+        #print "interface=$interface nic=$nic vlanip=$vlanip netmask=$netmask\n";
         if ($interface) {
-	    $rc |=system("ssh $hyp xHRM bridgeprereq $interface:$nic $vlanip $netmask");
+            $rc |=system("ssh $hyp xHRM bridgeprereq $interface:$nic $vlanip $netmask");
         } else {
             $rc |=system("ssh $hyp xHRM bridgeprereq $nic $vlanip $netmask");
         }
@@ -2785,8 +2796,6 @@ sub process_request {
 	  }
         }
       }
-      #donot update node provision status (installing or netbooting) here 
-      xCAT::Utils->filter_nostatusupdate(\%newnodestatus);
       #print "newstatus" . Dumper(\%newnodestatus);
       xCAT_monitoring::monitorctrl::setNodeStatusAttributes(\%newnodestatus, 1);
     }

From 918bd4270a0eb6293a45d762a2738d6baff896db Mon Sep 17 00:00:00 2001
From: xq2005 <qxuqxu@cn.ibm.com>
Date: Mon, 5 Aug 2013 02:22:35 -0700
Subject: [PATCH 08/26] comment the useless apt repo in full installation on
 ubuntu

---
 xCAT-server/share/xcat/install/scripts/post.ubuntu | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xCAT-server/share/xcat/install/scripts/post.ubuntu b/xCAT-server/share/xcat/install/scripts/post.ubuntu
index 364d4f198..70583feb4 100644
--- a/xCAT-server/share/xcat/install/scripts/post.ubuntu
+++ b/xCAT-server/share/xcat/install/scripts/post.ubuntu
@@ -28,6 +28,8 @@ done >>/etc/resolv.conf
 #change the soft link /bin/sh to /bin/bash
 ln -sf /bin/bash /bin/sh
 #
+#delete the useless apt repo
+sed -i 's/^deb.*updates.*$/#&/g' /etc/apt/sources.list
 # Run xCAT post install
 #
 export MASTER_IP="#XCATVAR:XCATMASTER#"

From b7701969edd54fe92dea04c24c372a080769553e Mon Sep 17 00:00:00 2001
From: Jia Zhao <jiazhbj@cn.ibm.com>
Date: Mon, 5 Aug 2013 19:19:00 +0800
Subject: [PATCH 09/26] fix noderegenips scalability problem

---
 xCAT-server/lib/xcat/plugins/00kitnodebase.pm | 187 ++++++++----------
 xCAT-server/lib/xcat/plugins/profilednodes.pm |  16 +-
 2 files changed, 90 insertions(+), 113 deletions(-)

diff --git a/xCAT-server/lib/xcat/plugins/00kitnodebase.pm b/xCAT-server/lib/xcat/plugins/00kitnodebase.pm
index 2a000fa03..ea985c236 100644
--- a/xCAT-server/lib/xcat/plugins/00kitnodebase.pm
+++ b/xCAT-server/lib/xcat/plugins/00kitnodebase.pm
@@ -75,28 +75,65 @@ sub process_request {
     my $nodelist = $request->{node};
     my $retref;
     my $rsp;
-
-    if($command eq 'kitnodeadd')
-    {
-        setrsp_progress("Updating hosts entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Updating DNS entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        if($macflag)
-        {
-            setrsp_progress("Update DHCP entries");
-            $retref = xCAT::Utils->runxcmd({command=>["makedhcp"], node=>$nodelist}, $request_command, 0, 2);
-            log_cmd_return($retref);
+    
+    # Get nodes profile 
+    my $profileref = xCAT::ProfiledNodeUtils->get_nodes_profiles($nodelist);
+    my %profilehash = %$profileref;
+    
+    # Check whetehr we need to run makeconservercf
+    # If one node has hardwareprofile, we need to run makeconservercf
+    my $runconservercmd = 0;
+    foreach (keys %profilehash) {
+        if (exists $profilehash{$_}{'HardwareProfile'}) {
+            $runconservercmd = 1;
+            last;
         }
-
-        setrsp_progress("Update known hosts");
-        $retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
+    }
+    
+    my @commandslist;
+    my %argslist;
+    my %msghash = ( "makehosts"         => "Updating hosts entries",
+                    "makedns"           => "Updating DNS entries",
+                    "makedhcp"          => "Update DHCP entries",
+                    "makeknownhosts"    => "Update known hosts",
+                    "makeconservercf"   => "Updating conserver configuration files",
+                    "kitnoderemove"     => "Remove nodes entries from system configuration files first.",
+                    "nodeset"           => "Update nodes' boot settings",
+                    "rspconfig"         => "Updating FSP's IP address",
+                    "rscan"             => "Update node's some attributes through 'rscan -u'",
+                    "mkhwconn"          => "Sets up connections for nodes to FSP",
+                  );
+    
+    # Stage1:  pre-run     
+    if ($command eq 'kitnoderefresh') {
+        # This is due to once update nicips table, we need remove node's records first and then re-create by run make* commands. If not, old records can't be removed.
+        push @commandslist, ['makedns', '-d'];
+        push @commandslist, ['makehosts', '-d'];
+    }
+    
+    # Stage2: run xcat commands
+    if ($command eq 'kitnodeadd' or $command eq 'kitnodeupdate' or $command eq 'kitnoderefresh') {
+        push @commandslist, ['makehosts', ''];
+        push @commandslist, ['makedns', ''];
+        if ($macflag) {
+            push @commandslist, ['makedhcp', ''];
+        }
+        push @commandslist, ['makeknownhosts', ''];
+        if ($runconservercmd) {
+            push @commandslist, ['makeconservercf', ''];
+        }
+    }elsif ($command eq 'kitnoderemove') {
+        if ($runconservercmd) {
+            push @commandslist, ['makeconservercf', '-d'];
+        }
+        push @commandslist, ['makeknownhosts', '-r'];
+        if ($macflag) {
+            push @commandslist, ['makedhcp', '-d'];
+        }
+    }
+    
+    # Stage3: post-run
+    if ($command eq 'kitnodeadd') {
         my $firstnode = (@$nodelist)[0];
         my $chaintab = xCAT::Table->new("chain");
         my $chainref = $chaintab->getNodeAttribs($firstnode, ['chain']);
@@ -106,107 +143,37 @@ sub process_request {
         if($macflag)
         {
             if ($chainarray[0]){
-                setrsp_progress("Update nodes' boot settings");
-                $retref = xCAT::Utils->runxcmd({command=>["nodeset"], node=>$nodelist, arg=>[$chainarray[0]]}, $request_command, 0, 2);
-                log_cmd_return($retref);
+                push @commandslist, ['nodeset', $chainarray[0]];
             }
         }
         my $isfsp = xCAT::ProfiledNodeUtils->is_fsp_node([$firstnode]);
         if ($isfsp) {
-            setrsp_progress("Updating FSP's IP address");
-            $retref = xCAT::Utils->runxcmd({command=>["rspconfig"], node=>$nodelist, arg=>['network=*']}, $request_command, 0, 2);
-            log_cmd_return($retref);
-
             my $cmmref = xCAT::ProfiledNodeUtils->get_nodes_cmm($nodelist);
             my @cmmchassis = keys %$cmmref;
-            setrsp_progress("Update node's some attributes through 'rscan -u'");
-            $retref = xCAT::Utils->runxcmd({command=>["rscan"], node=>\@cmmchassis, arg=>['-u']}, $request_command, 0, 2);
-            log_cmd_return($retref);
-
-            setrsp_progress("Sets up connections for nodes to FSP");
-            $retref = xCAT::Utils->runxcmd({command=>["mkhwconn"], node=>$nodelist, arg=>['-t']}, $request_command, 0, 2);
-            log_cmd_return($retref);
+            
+            push @commandslist, ['rspconfig', 'network=*'];
+            push @commandslist, ['rscan', '-u'];
+            push @commandslist, ['mkhwconn', '-t'];
         }
-        
-        setrsp_progress("Updating conserver configuration files");
-        $retref = xCAT::Utils->runxcmd({command=>["makeconservercf"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-    }
-    elsif ($command eq 'kitnoderemove'){
-        setrsp_progress("Updating conserver configuration files");
-        $retref = xCAT::Utils->runxcmd({command=>["makeconservercf"], node=>$nodelist, arg=>['-d']}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Update nodes' boot settings");
-        $retref = xCAT::Utils->runxcmd({command=>["nodeset"], node=>$nodelist, arg=>['offline']}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Update known hosts");
-        $retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist, arg=>['-r']}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Update DHCP entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makedhcp"], node=>$nodelist, arg=>['-d']}, $request_command, 0, 2);
-        log_cmd_return($retref);
-    }
-    elsif ($command eq 'kitnodeupdate'){
-        setrsp_progress("Updating hosts entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Updating DNS entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Update DHCP entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makedhcp"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Update known hosts");
-        $retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
+    }elsif ($command eq 'kitnoderemove') {
+        push @commandslist, ['nodeset', 'offline'];
+    }elsif ($command eq 'kitnodeupdate') {
         my $firstnode = (@$nodelist)[0];
-        my $profileref = xCAT::ProfiledNodeUtils->get_nodes_profiles([$firstnode]);
-        my %profilehash = %$profileref;
         if (exists $profilehash{$firstnode}{"ImageProfile"}){
-            setrsp_progress("Update nodes' boot settings");
-            $retref = xCAT::Utils->runxcmd({command=>["nodeset"], node=>$nodelist, arg=>['osimage='.$profilehash{$firstnode}{"ImageProfile"}]}, $request_command, 0, 2);
-            log_cmd_return($retref);
+            my $osimage = 'osimage='.$profilehash{$firstnode}{"ImageProfile"};
+            push @commandslist, ['nodeset', $osimage];
         }
-
-        setrsp_progress("Updating conserver configuration files");
-        $retref = xCAT::Utils->runxcmd({command=>["makeconservercf"], node=>$nodelist}, $request_command, 0, 2);
+    }
+    
+    # Run commands
+    foreach (@commandslist) {
+        my $current_cmd = $_->[0];
+        my $current_args = $_->[1];
+        setrsp_progress($msghash{$current_cmd});
+        my $retref = xCAT::Utils->runxcmd({command=>[$current_cmd], node=>$nodelist, arg=>[$current_args]}, $request_command, 0, 2);
         log_cmd_return($retref);
     }
-    elsif ($command eq 'kitnoderefresh'){
-        # This is due to once update nicips table, we need remove node's records first and then re-create by run make* commands.
-        setrsp_progress("Remove nodes entries from system configuration files first.");
-        $retref = xCAT::Utils->runxcmd({command=>["kitnoderemove"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Updating hosts entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Updating DNS entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Update DHCP entries");
-        $retref = xCAT::Utils->runxcmd({command=>["makedhcp"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Update known hosts");
-        $retref = xCAT::Utils->runxcmd({command=>["makeknownhosts"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-
-        setrsp_progress("Updating conserver configuration files");
-        $retref = xCAT::Utils->runxcmd({command=>["makeconservercf"], node=>$nodelist}, $request_command, 0, 2);
-        log_cmd_return($retref);
-    }
-    else
-    {
-    }
+    
 }
 
 #-------------------------------------------------------
diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm
index 8fff76131..7c0b273bd 100644
--- a/xCAT-server/lib/xcat/plugins/profilednodes.pm
+++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm
@@ -958,13 +958,13 @@ Usage:
         $chaintab->close();
         
         # Remove all nodes information
-        push(@kitcommands, "kitnoderemove");
+        push(@kitcommands, "removenodes");
         # Add all nodes information back
         push(@kitcommands, "kitnodeadd");  
         
     } elsif ( $fsp_flag ) {
         # Remove all nodes information
-        push(@kitcommands, "kitnoderemove");
+        push(@kitcommands, "removenodes");
         # Add all nodes information back
         push(@kitcommands, "kitnodeadd");
     } else {
@@ -973,7 +973,17 @@ Usage:
 
     #10. Call plugins.   
     foreach my $command (@kitcommands) {
-        my $retref = xCAT::Utils->runxcmd({command=>[$command], node=>$nodes, sequential=>[1]}, $request_command, 0, 2);
+        my $retref;
+        if ($command eq 'removenodes'){
+            # Not run makedns -d as it costs too much time
+            #setrsp_progress("Updating DNS entries");
+            #$retref = xCAT::Utils->runxcmd({command=>["makedns"], node=>$nodes, arg=>['-d']}, $request_command, 0, 2);
+
+            #setrsp_progress("Updating hosts entries");
+            $retref = xCAT::Utils->runxcmd({command=>["makehosts"], node=>$nodes, arg=>['-d']}, $request_command, 0, 2);
+            next;
+        }
+        $retref = xCAT::Utils->runxcmd({command=>[$command], node=>$nodes, sequential=>[1]}, $request_command, 0, 2);
         my $retstrref = parse_runxcmd_ret($retref);
         if ($::RUNCMD_RC != 0){
             setrsp_progress("Warning: failed to call kit commands.");

From 0f0046ca9d73dc43d432ad9fe7fef401cfd81513 Mon Sep 17 00:00:00 2001
From: lissav <lissav@us.ibm.com>
Date: Mon, 5 Aug 2013 09:36:08 -0400
Subject: [PATCH 10/26]  add support for updatenode -g flag to generate
 mypostcripts files

---
 perl-xCAT/xCAT/Usage.pm                    |  5 ++-
 xCAT-client/bin/updatenode                 |  1 +
 xCAT-server/lib/xcat/plugins/updatenode.pm | 43 ++++++++++++++++++++++
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm
index 10d370aa0..52e362627 100644
--- a/perl-xCAT/xCAT/Usage.pm
+++ b/perl-xCAT/xCAT/Usage.pm
@@ -343,7 +343,7 @@ my %usage = (
       renergy noderange [-V] { cappingstatus={on | enable | off | disable} | {cappingwatt|cappingvalue}=watt }",
   "updatenode" =>
 "Usage:
-    updatenode [-h|--help|-v|--version]
+    updatenode [-h|--help|-v|--version | -g|--genmypost]
     or
     updatenode <noderange> [-V|--verbose] [-k|--security] [-s|--sn]
     or
@@ -368,6 +368,9 @@ Options:
     [-f|--snsync] Performs File Syncing to the service nodes that service 
         the nodes in the noderange.
 
+    [-g|--genmypost] Will generate a new mypostscript file for the  
+        the nodes in the noderange, if site precreatemypostscripts is 1 or YES.
+
     [-l|--user] User name to run the updatenode command.  It overrides the
         current user which is the default.
 
diff --git a/xCAT-client/bin/updatenode b/xCAT-client/bin/updatenode
index b0c14fe5c..35e7efd99 100755
--- a/xCAT-client/bin/updatenode
+++ b/xCAT-client/bin/updatenode
@@ -88,6 +88,7 @@ if (
                 'v|version'        => \$::VERSION,
                 'V|verbose'        => \$::VERBOSE,
                 'F|sync'           => \$::FILESYNC,
+                'g|genmypost'   => \$::GENMYPOST,
                 'f|snsync'         => \$::SNFILESYNC,
                 'l|user:s'         => \$::USER,
                 'S|sw'             => \$::SWMAINTENANCE,
diff --git a/xCAT-server/lib/xcat/plugins/updatenode.pm b/xCAT-server/lib/xcat/plugins/updatenode.pm
index 7295b26b7..a8e03b1ad 100644
--- a/xCAT-server/lib/xcat/plugins/updatenode.pm
+++ b/xCAT-server/lib/xcat/plugins/updatenode.pm
@@ -218,6 +218,7 @@ sub preprocess_updatenode
                     'v|version'     => \$::VERSION,
                     'V|verbose'     => \$::VERBOSE,
                     'F|sync'        => \$::FILESYNC,
+                    'g|genmypost'   => \$::GENMYPOST,
                     'l|user:s'      => \$::USER,
                     'f|snsync'      => \$::SNFILESYNC,
                     'S|sw'          => \$::SWMAINTENANCE,
@@ -249,6 +250,38 @@ sub preprocess_updatenode
         $callback->($rsp);
         return;
     }
+    # Just generate mypostscripts file and get out 
+    if ($::GENMYPOST)
+    {
+        my @entries =  xCAT::TableUtils->get_site_attribute("precreatemypostscripts");
+        if ($entries[0] ) {
+          $entries[0] =~ tr/a-z/A-Z/;
+          if ($entries[0] =~ /^(1|YES)$/ ) {
+
+            my $notmpfiles=1;
+            my $nofiles=0;
+            xCAT::Postage::create_mypostscript_or_not($request, $callback, $subreq,$notmpfiles,$nofiles);
+            my $rsp = {};
+            $rsp->{data}->[0] = "Generated new mypostscript files";
+            $callback->($rsp);
+          } else {  # not valid unless precreatemypostscripts enabled
+            my $rsp = {};
+            $rsp->{error}->[0] =
+              "This option is only valid if site table precreatemypostscripts attribute is 1 or YES";
+            $rsp->{errorcode}->[0] =1;
+            $callback->($rsp);
+            return ;
+          }
+        } else { # not in the site table
+            my $rsp = {};
+            $rsp->{error}->[0] =
+             "This option is only valid if site table precreatemypostscripts attribute is 1 or YES";
+            $rsp->{errorcode}->[0] =1;
+            $callback->($rsp);
+            return ;
+        }
+        return 0;
+    }
 
     # -c must work with -S for AIX node
     if ($::CMDLINE && !$::SWMAINTENANCE)
@@ -1267,6 +1300,7 @@ sub updatenoderunps
             # Note order of parameters to xcatdsklspost 
             #is important and cannot be changed
             my $runpscmd;
+            
             if ($::SETSERVER){
                $runpscmd  =
                     "$installdir/postscripts/xcatdsklspost $mode -M $snkey '$postscripts' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c";
@@ -1274,6 +1308,11 @@ sub updatenoderunps
                $runpscmd  =
                     "$installdir/postscripts/xcatdsklspost $mode -m $snkey '$postscripts' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c"
             }
+            # add verbose flag
+            if ($::VERBOSE){
+               $runpscmd .= " -V";
+            }
+
             push @$args1,"--nodestatus"; # return nodestatus
             if (defined($::fanout))  {  # fanout
              push @$args1,"-f" ;
@@ -1596,6 +1635,10 @@ sub updatenodesoftware
                 $cmd =
                   "$installdir/postscripts/xcatdsklspost 2 -m $snkey 'ospkgs,otherpkgs' --tftp $tftpdir";
             }
+            # add verbose flag
+            if ($::VERBOSE){
+               $cmd .= " -V";
+            }
     
             # build xdsh command
             push @$args1,"--nodestatus"; # return nodestatus

From cf502073f421fc428fa32bec5b0f1697391be3ee Mon Sep 17 00:00:00 2001
From: lissav <lissav@us.ibm.com>
Date: Mon, 5 Aug 2013 09:52:45 -0400
Subject: [PATCH 11/26] fix defect 3479

---
 xCAT/postscripts/remoteshell | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/xCAT/postscripts/remoteshell b/xCAT/postscripts/remoteshell
index 35ba0dbb6..c8a7553fa 100755
--- a/xCAT/postscripts/remoteshell
+++ b/xCAT/postscripts/remoteshell
@@ -23,21 +23,28 @@ if [ "$(uname -s)" = "AIX" ]; then
 fi
 if [ -r /etc/ssh/sshd_config ]
 then
-	logger -t xcat -p local4.info "Install:  setup /etc/ssh/sshd_config"
+	logger -t xcat -p local4.info "remoteshell:  setup /etc/ssh/sshd_config and ssh_config"
 	cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ORIG
-	sed -i 's/^X11Forwarding .*$/X11Forwarding yes/' /etc/ssh/sshd_config
-	sed -i 's/^KeyRegenerationInterval .*$/KeyRegenerationInterval 0/' /etc/ssh/sshd_config
-	sed -i 's/\(.*MaxStartups.*\)/#\1/' /etc/ssh/sshd_config
-	echo "MaxStartups 1024" >>/etc/ssh/sshd_config
+        #delete all occurance of the attribute and then add xCAT settings
+        sed -i '/X11Forwarding /'d /etc/ssh/sshd_config
+        echo "X11Forwarding yes" >>/etc/ssh/sshd_config
+        sed -i '/KeyRegenerationInterval /'d /etc/ssh/sshd_config
+        echo "KeyRegenerationInterval 0" >>/etc/ssh/sshd_config
+        sed -i '/MaxStartups /'d /etc/ssh/sshd_config
+        echo "MaxStartups 1024" >>/etc/ssh/sshd_config
+ 
     if [ "$SETUPFORPCM" = "1" ];then
-	 sed -i 's/\(.*PasswordAuthentication.*\)/#\1/' /etc/ssh/sshd_config
-     echo "PasswordAuthentication yes" >>/etc/ssh/sshd_config
+         sed -i '/PasswordAuthentication /'d /etc/ssh/sshd_config
+         echo "PasswordAuthentication yes" >>/etc/ssh/sshd_config
+
     fi
 fi
 
 if [ -r /etc/ssh/sshd_config ]
 then
-   echo "   StrictHostKeyChecking no" >> /etc/ssh/ssh_config
+   sed -i '/StrictHostKeyChecking /'d /etc/ssh/ssh_config
+   echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
+
 fi
 
 if [ -d /xcatpost/_ssh ]

From d0411a285f29375cf213ad34ed6e3bcd356c9e51 Mon Sep 17 00:00:00 2001
From: lissav <lissav@us.ibm.com>
Date: Mon, 5 Aug 2013 10:05:05 -0400
Subject: [PATCH 12/26]  fix defect 2959

---
 xCAT-server/lib/perl/xCAT/xcatd.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/xCAT-server/lib/perl/xCAT/xcatd.pm b/xCAT-server/lib/perl/xCAT/xcatd.pm
index 67891d54e..ed76310dc 100644
--- a/xCAT-server/lib/perl/xCAT/xcatd.pm
+++ b/xCAT-server/lib/perl/xCAT/xcatd.pm
@@ -69,15 +69,18 @@ sub validate {
   $policytable->close;
   my $rule;
   my $peerstatus="untrusted";
+  # This sorts the policy table  rows based on the level of the priority field in the row.
+  # note the lower the number in the policy table the higher the priority
+  my @sortedpolicies = sort { $a->{priority} <=> $b->{priority} } (@$policies);
   # check to see if peerhost is trusted
-  foreach $rule (@$policies) {
+  foreach $rule (@sortedpolicies) {
      
     if (($rule->{name} and $rule->{name} eq $peername)  && ($rule->{rule}=~ /trusted/i)) {
      $peerstatus="Trusted";
      last;
     }
   }
-  RULE: foreach $rule (@$policies) {
+  RULE: foreach $rule (@sortedpolicies) {
     if ($rule->{name} and $rule->{name} ne '*') {
       #TODO: more complex matching (lists, wildcards)
       next unless ($peername and $peername eq $rule->{name});

From 861794f576729ff63482685fd921c475e1abe20d Mon Sep 17 00:00:00 2001
From: lissav <lissav@us.ibm.com>
Date: Mon, 5 Aug 2013 10:36:29 -0400
Subject: [PATCH 13/26]  fix defect 3464

---
 perl-xCAT/xCAT/ServiceNodeUtils.pm | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/perl-xCAT/xCAT/ServiceNodeUtils.pm b/perl-xCAT/xCAT/ServiceNodeUtils.pm
index 97cb15ba1..242ccbf08 100644
--- a/perl-xCAT/xCAT/ServiceNodeUtils.pm
+++ b/perl-xCAT/xCAT/ServiceNodeUtils.pm
@@ -30,7 +30,6 @@ use strict;
   Example:
     my $retdata = xCAT::ServiceNodeUtils->readSNInfo;
 =cut
-
 #-----------------------------------------------------------------------------
 sub readSNInfo
 {
@@ -102,13 +101,17 @@ sub isServiceReq
     require xCAT::Table;
     my ($class, $servicenodename, $serviceip) = @_;
 
-    # list of all services from service node table
-    # note this must be updated if more services added
-    my @services = (
-                    "nameserver", "dhcpserver", "tftpserver", "nfsserver",
-                    "conserver",  "monserver",  "ldapserver", "ntpserver",
-                    "ftpserver",  "ipforward"
-                    );
+    # get list of all services from service node table ( actually all defined attributes)
+    # read the  schema
+    my $schema = xCAT::Table->getTableSchema("servicenode");
+    my @services; #  list of only the actual service attributes from the servicenode table
+    my @servicesattrs;  # building second copy for call to getAllNodeAttribs, which modifies the array
+    foreach my $c (@{$schema->{cols}}) {
+      if (($c ne "node") && ($c ne "comments") && ($c ne "disable")) {
+       push @servicesattrs,$c;
+       push @services,$c;
+      }
+    }
 
     my @ips = @$serviceip;    # list of service node ip addresses and names
     my $rc  = 0;
@@ -139,10 +142,11 @@ sub isServiceReq
     }
 
     my $servicehash;
-    # read all the nodes from the table, for each service
-    foreach my $service (@services)
+    
+    # read all the nodes from the table, all the service attributes
+    my @snodelist= $servicenodetab->getAllNodeAttribs(\@servicesattrs); 
+    foreach my $service (@services) # check list of services
     {
-        my @snodelist = $servicenodetab->getAllNodeAttribs([$service]);
 
         foreach $serviceip (@ips)    # check the table for this servicenode
         {

From df1c52016195d223bc0cd3bb0b5e582345f5a291 Mon Sep 17 00:00:00 2001
From: lissav <lissav@us.ibm.com>
Date: Mon, 5 Aug 2013 14:10:20 -0400
Subject: [PATCH 14/26]  add MAX/MIN function

---
 perl-xCAT/xCAT/Table.pm | 94 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm
index 34c73c189..278b11aec 100644
--- a/perl-xCAT/xCAT/Table.pm
+++ b/perl-xCAT/xCAT/Table.pm
@@ -323,6 +323,8 @@ sub handle_dbc_request {
          return $opentables{$tablename}->{$autocommit}->getAllNodeAttribs(@args);
     } elsif ($functionname eq 'getAllEntries') {
          return $opentables{$tablename}->{$autocommit}->getAllEntries(@args);
+    } elsif ($functionname eq 'getMAXMINEntries') {
+         return $opentables{$tablename}->{$autocommit}->getMAXMINEntries(@args);
     } elsif ($functionname eq 'writeAllEntries') {
          return $opentables{$tablename}->{$autocommit}->writeAllEntries(@args);
     } elsif ($functionname eq 'getAllAttribsWhere') {
@@ -3988,5 +3990,97 @@ sub output_table {
    print $fh "\n";
    return 0;
 }
+#--------------------------------------------------------------------------
+
+=head3 getMAXMINEntries
+
+    Description: Select the rows in  the Table which has the MAX and the row with the 
+                 Min value for the input attribute.
+                 Currently only the auditlog and evenlog are setup to have such an attribute (recid). 
+
+    Arguments:
+           Table handle
+           attribute name ( e.g. recid)
+
+    Returns:
+        HASH 
+            max=>  max value
+            min=>  min value 
+    Globals:
+
+    Error:
+
+    Example:
+
+	 my $tabh = xCAT::Table->new($table);
+         my $recs=$tabh->getMAXMINEntries("recid"); 
+
+    Comments:
+        none
+
+=cut
+
+#--------------------------------------------------------------------------------
+sub getMAXMINEntries
+{
+    my $self = shift;
+    my $attr = shift;
+    if ($dbworkerpid) {
+        return dbc_call($self,'getMAXMINEntries',@_);
+    }
+    my $rets;
+    my $query;
+    my $xcatcfg=get_xcatcfg();
+    # delimit the disable column based on the DB 
+    my $disable= &delimitcol("disable");	
+    my $qstring;
+    if ($xcatcfg =~ /^DB2:/) {  # for DB2 
+       $qstring = "SELECT MAX (\"$attr\") FROM " . $self->{tabname} . " WHERE " . $disable . " is NULL or " .  $disable . " in ('0','no','NO','No','nO')";
+    } else {
+       $qstring = "SELECT MAX($attr) FROM " . $self->{tabname} . " WHERE " . $disable . " is NULL or " .  $disable . " in ('0','no','NO','No','nO')";
+    }
+    $query = $self->{dbh}->prepare($qstring);
+
+    $query->execute();
+    while (my $data = $query->fetchrow_hashref())
+    {
+        foreach (keys %$data)
+        {
+            if ($data->{$_} =~ /^$/)
+            {
+                $rets->{"max"} = undef;
+            } else {
+                $rets->{"max"} = $data->{$_};
+
+            }
+            last;   # better only be one value for max
+            
+        }
+    }
+    $query->finish();
+    if ($xcatcfg =~ /^DB2:/) {  # for DB2 
+       $qstring = "SELECT MIN (\"$attr\") FROM " . $self->{tabname} . " WHERE " . $disable . " is NULL or " .  $disable . " in ('0','no','NO','No','nO')";
+    } else {
+    $qstring = "SELECT MIN($attr) FROM " . $self->{tabname} . " WHERE " . $disable . " is NULL or " .  $disable . " in ('0','no','NO','No','nO')";
+    }
+    $query = $self->{dbh}->prepare($qstring);
+
+    $query->execute();
+    while (my $data = $query->fetchrow_hashref())
+    {
+        foreach (keys %$data)
+        {
+            if ($data->{$_} =~ /^$/)
+            {
+                $rets->{"min"} = undef;
+            } else {
+                $rets->{"min"} = $data->{$_};
+            }
+            last;   # better be only one value  for min
+        }
+    }
+    return $rets;
+}
+
 1;
 

From 8921bc2734d2dc7f257526f2ab9386a935f180fb Mon Sep 17 00:00:00 2001
From: immarvin <yangsbj@cn.ibm.comq>
Date: Tue, 6 Aug 2013 00:53:30 -0700
Subject: [PATCH 15/26] fix defect 3245 2.8:return value of nodeset does not
 equal to 0 on ppc64

---
 xCAT-server/lib/xcat/plugins/yaboot.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xCAT-server/lib/xcat/plugins/yaboot.pm b/xCAT-server/lib/xcat/plugins/yaboot.pm
index 004b73360..6351ff2e6 100644
--- a/xCAT-server/lib/xcat/plugins/yaboot.pm
+++ b/xCAT-server/lib/xcat/plugins/yaboot.pm
@@ -296,7 +296,8 @@ sub setstate {
       my $pname = "yaboot.conf-" . $tmp;
       unlink($tftpdir."/".$pname);
       link($tftpdir."/etc/".$node,$tftpdir."/".$pname); 
-  }      
+  }
+  return;      
 }
   
 

From e88a680e6b492745b7e0c1ddc11aa3263bc2e20f Mon Sep 17 00:00:00 2001
From: root <root@dx360m4n05.pok.stglabs.ibm.com>
Date: Tue, 6 Aug 2013 16:02:31 -0400
Subject: [PATCH 16/26] fixed bug 3706. When genimage, it generated the
 CentOS-Base.repo in the /etc/yum.repos.d, but the internet repositories were
 not enabled=0. disable it

---
 xCAT-server/share/xcat/netboot/rh/genimage | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage
index b67cdd98c..aca1fc013 100755
--- a/xCAT-server/share/xcat/netboot/rh/genimage
+++ b/xCAT-server/share/xcat/netboot/rh/genimage
@@ -538,6 +538,14 @@ if (-d "$rootimg_dir/usr/share/dracut") {
     print "Enter the dracut mode. Dracut version: $dracutver. Dracut directory: $dracutdir.\n";
 }
 
+
+#-- for centos, disable the internet repository
+if( -e "$rootimg_dir/etc/yum.repos.d/CentOS-Base.repo" ) {
+    my $repo_content=`sed -e '/enabled/d' $rootimg_dir/etc/yum.repos.d/CentOS-Base.repo | sed -e '/^gpgkey/i enabled=0'`;
+    system("echo '$repo_content' > $rootimg_dir/etc/yum.repos.d/CentOS-Base.repo");
+}
+#
+
 #-- run postinstall script
 unless ($imagename) {
     $postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "postinstall");

From 2bca640ffaad911434e3983ab37202781d9b5508 Mon Sep 17 00:00:00 2001
From: lissav <lissav@us.ibm.com>
Date: Tue, 6 Aug 2013 09:44:52 -0400
Subject: [PATCH 17/26]  fix bug

---
 perl-xCAT/xCAT/Table.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm
index 278b11aec..1e1750d52 100644
--- a/perl-xCAT/xCAT/Table.pm
+++ b/perl-xCAT/xCAT/Table.pm
@@ -4024,10 +4024,10 @@ sub output_table {
 sub getMAXMINEntries
 {
     my $self = shift;
-    my $attr = shift;
     if ($dbworkerpid) {
         return dbc_call($self,'getMAXMINEntries',@_);
     }
+    my $attr = shift;
     my $rets;
     my $query;
     my $xcatcfg=get_xcatcfg();

From 63edd565d11deaea0c2bc5de620ed1d046662841 Mon Sep 17 00:00:00 2001
From: Jarrod Johnson <jbjohnso@us.ibm.com>
Date: Tue, 6 Aug 2013 10:56:57 -0400
Subject: [PATCH 18/26] Correct language in sensor decode

---
 xCAT-server/lib/xcat/plugins/ipmi.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm
index 1d7abb317..8126558c8 100644
--- a/xCAT-server/lib/xcat/plugins/ipmi.pm
+++ b/xCAT-server/lib/xcat/plugins/ipmi.pm
@@ -3905,8 +3905,8 @@ sub getaddsensorevent {
 				0x0f => "Enabling docking station",
 				0x10 => "Docking staion ejection",
 				0x11 => "Disable docking station",
-				0x12 => "Calling operation system wake-up vector",
-				0x13 => "Starting operation system boot process, call init 19h",
+				0x12 => "Calling operating system wake-up vector",
+				0x13 => "Starting operating system boot process, call init 19h",
 				0x14 => "Baseboard or motherboard initialization",
 				0x16 => "Floppy initialization",
 				0x17 => "Keyboard test",

From 780fbaaad823073355c0702c8d6c668fd226a69a Mon Sep 17 00:00:00 2001
From: lissav <lissav@us.ibm.com>
Date: Tue, 6 Aug 2013 12:15:26 -0400
Subject: [PATCH 19/26]  use MAXMIN routine

---
 xCAT-server/lib/xcat/plugins/tabutils.pm | 110 ++++++++---------------
 1 file changed, 38 insertions(+), 72 deletions(-)

diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm
index 9cf8b00fc..2596cab60 100644
--- a/xCAT-server/lib/xcat/plugins/tabutils.pm
+++ b/xCAT-server/lib/xcat/plugins/tabutils.pm
@@ -580,9 +580,10 @@ sub tabdump
     if ($args) {
         @ARGV = @{$args};
     }
-      Getopt::Long::Configure("posix_default");
-      Getopt::Long::Configure("no_gnu_compat");
-      Getopt::Long::Configure("bundling");
+    Getopt::Long::Configure("posix_default");
+    Getopt::Long::Configure("no_gnu_compat");
+    Getopt::Long::Configure("bundling");
+
 
     if (!GetOptions(
           'h|?|help' => \$HELP,
@@ -604,14 +605,15 @@ sub tabdump
         return;
     }
     if ($FILENAME and $FILENAME !~ /^\//) { $FILENAME =~ s/^/$request->{cwd}->[0]\//; }
-
+    
 
     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;
@@ -620,10 +622,8 @@ sub tabdump
           $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)) {
@@ -647,15 +647,15 @@ 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 table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1});
@@ -703,7 +703,6 @@ sub tabdump
      return $rc;
     }
 
-
     my $recs;
     my @ents;
     my @attrarray;
@@ -758,12 +757,12 @@ sub tabdump
 }
 #
 #  display input number of records for the table requested tabdump -n
+#  note currently only supports auditlog and eventlog
 #
 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;
@@ -772,38 +771,21 @@ sub tabdump_numberentries {
        $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 {
+ #determine recid to show all records after 
+ my $RECID;
+ my $attrrecid="recid";
+ my $values = $tab->getMAXMINEntries($attrrecid);
+ my $max=$values->{"max"};
+ if (defined($values->{"max"})){
+      $RECID= $values->{"max"} - $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 
@@ -831,6 +813,7 @@ sub tabdump_recid {
    output_table($table,$cb,$tab,\@recs); 
    return $rc;
 }
+
 # Display information from the daemon.
 #  
 sub lsxcatd 
@@ -1066,7 +1049,7 @@ sub tabprune
     if (($table eq "eventlog") || ($table eq "auditlog")) {
       $attrrecid="recid";
     } else {
-      if ($table eq "isnm_perf") {  # if ISNM  These tables are really not supported in 2.8 or later
+      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
@@ -1134,51 +1117,34 @@ sub tabprune_numberentries {
        $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;
+  my $RECID;
+  my $values = $tab->getMAXMINEntries($attrrecid);
+  if ((defined($values->{"max"})) && (defined($values->{"min"}))) {
+    my  $largerid = $values->{"max"};
+    my  $smallrid = $values->{"min"};
     if ($flag eq "n") {  # deleting number of records
-      #determine recid to delete all entries that come before like the -i flag
-      $RECID= $smallrid->{$attrrecid} + $numberentries ; 
+      #get the smalled recid and add number to delete, that is where to start removing
+      $RECID= $smallrid + $numberentries ; 
     } else {  # flag must be percentage
        #take largest and smallest recid and percentage and determine the recid
        # that will remove the requested percentage.   If some are missing in the
        # middle due to tabedit,  we are not worried about it.
      
-       my $totalnumberrids = $largerid->{$attrrecid} - $smallrid->{$attrrecid} +1;
+       my $totalnumberrids = $largerid - $smallrid +1;
        my $percent = $numberentries / 100;
        my $percentage=$totalnumberrids * $percent ;
        my $cnt=sprintf( "%d", $percentage ); # round to whole number
-       $RECID=$smallrid->{$attrrecid} + $cnt; # get recid to remove all before
+       $RECID=$smallrid + $cnt; # get recid to remove all before
     }
+    # Now prune starting at $RECID
     $rc=tabprune_recid($table,$cb,$RECID, $attrrecid,$VERBOSE); 
-  } else {
+ } else {
       my %rsp;
       push @{$rsp{data}}, "Nothing to prune from $table.";
       $rsp{errorcode} = $rc; 
       $cb->(\%rsp);
-  }
-  return $rc;
+ }
+ return $rc;
 }
 
 #  prune all entries up to the record id input 

From 6fb47b1d50d171d63a4d5cc897c60fe399508b36 Mon Sep 17 00:00:00 2001
From: linggao <linggao@us.ibm.com>
Date: Tue, 6 Aug 2013 20:21:03 -0400
Subject: [PATCH 20/26] fixed defect 3729 imgexport does not honor rootimgdir

---
 xCAT-server/lib/xcat/plugins/imgport.pm | 125 ++++++++++++++----------
 1 file changed, 75 insertions(+), 50 deletions(-)

diff --git a/xCAT-server/lib/xcat/plugins/imgport.pm b/xCAT-server/lib/xcat/plugins/imgport.pm
index db6d04585..9e3e2af9a 100644
--- a/xCAT-server/lib/xcat/plugins/imgport.pm
+++ b/xCAT-server/lib/xcat/plugins/imgport.pm
@@ -438,7 +438,7 @@ sub get_files{
                 my @files;
                 my $dir = "$installroot/netboot/$osvers/s390x/$profile";
                 opendir(DIR, $dir) or $callback->({error=>["Could not open image files in directory $dir"], errorcode=>[1]});
-
+		
                 while (my $file = readdir(DIR)) {
                     # We only want files in the directory that end with .img
                     next unless (-f "$dir/$file");
@@ -449,7 +449,7 @@ sub get_files{
                 if (@files) {
                     $attrs->{rawimagefiles}->{files} = [@files];
                 }
-                               
+		
                 closedir(DIR);
             }
             else {
@@ -465,37 +465,51 @@ sub get_files{
                         $attrs->{linuximage}->{pkglist} = $temp;
                     }
                 }
-        
+		
                 @arr = ("$installroot/netboot");
-    
-                # look for ramdisk
-                my $ramdisk = look_for_file('initrd-stateless.gz', $callback, $attrs, @arr);
-                unless($ramdisk){
-                    $callback->({error=>["Couldn't find ramdisk (initrd-stateless.gz) for  $imagename"],errorcode=>[1]});
-                    $errors++;
-                }else{
-                    $attrs->{ramdisk} = $ramdisk;
-                }
-        
-                # look for kernel
-                my $kernel = look_for_file('kernel', $callback, $attrs, @arr);
-                unless($kernel){
-                    $callback->({error=>["Couldn't find kernel (kernel) for  $imagename"],errorcode=>[1]});
-                    $errors++;
-                }else{
-                    $attrs->{kernel} = $kernel;
-                }
-        
-                # look for rootimg.gz
-                my $rootimg = look_for_file('rootimg.gz', $callback, $attrs, @arr);
-                unless($rootimg){
-                    $callback->({error=>["Couldn't find rootimg (rootimg.gz) for  $imagename"],errorcode=>[1]});
-                    $errors++;
-                }else{
-                    $attrs->{rootimg} = $rootimg;
-                }
-            }
-	    } elsif ($provmethod =~ /statelite/) {
+		my $rootimgdir=$attrs->{linuximage}->{rootimgdir};
+		my $ramdisk;
+                my $kernel;
+		my $rootimg;
+                # look for ramdisk, kernel and rootimg.gz
+		if($rootimgdir) {
+	            if (-f "$rootimgdir/initrd-stateless.gz") {
+			$ramdisk="$rootimgdir/initrd-stateless.gz";
+		    } 
+	            if (-f "$rootimgdir/kernel") {
+			$kernel="$rootimgdir/kernel";
+		    } 
+	            if (-f "$rootimgdir/rootimg.gz") {
+			$rootimg="$rootimgdir/rootimg.gz";
+		    } 
+                    	    
+		} else {
+		    $ramdisk = look_for_file('initrd-stateless.gz', $callback, $attrs, @arr);
+		    $kernel = look_for_file('kernel', $callback, $attrs, @arr);
+		    $rootimg = look_for_file('rootimg.gz', $callback, $attrs, @arr);
+		}
+		unless($ramdisk){
+		    $callback->({error=>["Couldn't find ramdisk (initrd-stateless.gz) for  $imagename"],errorcode=>[1]});
+		    $errors++;
+		}else{
+		    $attrs->{ramdisk} = $ramdisk;
+		}
+		    
+		unless($kernel){
+		    $callback->({error=>["Couldn't find kernel (kernel) for  $imagename"],errorcode=>[1]});
+		    $errors++;
+		}else{
+		    $attrs->{kernel} = $kernel;
+		}
+		    
+		unless($rootimg){
+		    $callback->({error=>["Couldn't find rootimg (rootimg.gz) for  $imagename"],errorcode=>[1]});
+		    $errors++;
+		}else{
+		    $attrs->{rootimg} = $rootimg;
+		}
+	    }
+	} elsif ($provmethod =~ /statelite/) {
             @arr = ("$installroot/custom/netboot", "$xcatroot/share/xcat/netboot");
             #get .pkglist file
             if (! $attrs->{linuximage}->{pkglist})  {
@@ -510,25 +524,36 @@ sub get_files{
             }
         
             @arr = ("$installroot/netboot");
-        
-            # look for kernel
-            my $kernel = look_for_file('kernel', $callback, $attrs, @arr);
-            unless($kernel){
-                $callback->({error=>["Couldn't find kernel (kernel) for  $imagename"],errorcode=>[1]});
-                $errors++;
-            }else{
-                $attrs->{kernel} = $kernel;
-            }
+	    my $rootimgdir=$attrs->{linuximage}->{rootimgdir};
+	    my $kernel;
+            my $ramdisk;
+            #look for kernel and ramdisk
+	    if($rootimgdir) {
+		if (-f "$rootimgdir/kernel") {
+		    $kernel="$rootimgdir/kernel";
+		} 		
+		if (-f "$rootimgdir/initrd-statelite.gz") {
+		    $ramdisk="$rootimgdir/initrd-statelite.gz";
+		} 
+	    } else {
+		$kernel = look_for_file('kernel', $callback, $attrs, @arr);
+		$ramdisk = look_for_file('initrd-statelite.gz', $callback, $attrs, @arr);
+	    }
+	    
+	    unless($kernel){
+		$callback->({error=>["Couldn't find kernel (kernel) for  $imagename"],errorcode=>[1]});
+		$errors++;
+	    }else{
+		$attrs->{kernel} = $kernel;
+	    }
 
-            # look for ramdisk
-            my $ramdisk = look_for_file('initrd-statelite.gz', $callback, $attrs, @arr);
-            unless($ramdisk){
-                $callback->({error=>["Couldn't find ramdisk (initrd-statelite.gz) for  $imagename"],errorcode=>[1]});
-                $errors++;
-            }else{
-                $attrs->{ramdisk} = $ramdisk;
-            }
-        } 
+	    unless($ramdisk){
+		$callback->({error=>["Couldn't find ramdisk (initrd-statelite.gz) for  $imagename"],errorcode=>[1]});
+		$errors++;
+	    }else{
+		$attrs->{ramdisk} = $ramdisk;
+	    }
+	}
     }
     
     if (( $provmethod =~ /raw/ ) and ( $arch =~ /s390x/ )) {    

From 5f8d3943462ed322f50e34d72515bd9cab5ae6c8 Mon Sep 17 00:00:00 2001
From: yinqing <yinqing@cn.ibm.com>
Date: Wed, 7 Aug 2013 11:30:21 +0800
Subject: [PATCH 21/26] #221180 There is no mechanism to prevent error message
 printed in kitimagepostdelete when disassociated kit with the image profile

---
 .../xcat/kits/kit_template/plugins/sample/imageprofile.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm b/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm
index 212aa60e6..cd287a7dd 100644
--- a/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm
+++ b/xCAT-buildkit/share/xcat/kits/kit_template/plugins/sample/imageprofile.pm
@@ -171,6 +171,12 @@ sub process_request {
         # Do the check 
         my $imageprofile = parse_str_arg($request->{arg}->[0]);
 
+        if (! exists($request->{kitdata}))
+        {
+            $rsp->{data}->[0] = "Skipped running \"$command\" plugin command for \"$PLUGIN_KITNAME\" kit.";
+            xCAT::MsgUtils->message("I", $rsp, $callback);
+            return;
+        }
         my $kitdata = $request->{kitdata};
         if (! defined($kitdata)) {
             $kitdata = xCAT::KitPluginUtils->get_kits_used_by_image_profiles([$imageprofile]);
@@ -742,4 +748,4 @@ sub parse_list_arg {
 
 }
 
-1;
\ No newline at end of file
+1;

From 600ab740aea724065e0e6b311b795435e4107588 Mon Sep 17 00:00:00 2001
From: yinqing <yinqing@cn.ibm.com>
Date: Wed, 7 Aug 2013 13:29:25 +0800
Subject: [PATCH 22/26] #220993 Can not import node by auto discovery switch
 and switch port.

---
 perl-xCAT/xCAT/ProfiledNodeUtils.pm           | 27 +++++++++++++++++++
 xCAT-server/lib/xcat/plugins/profilednodes.pm |  2 +-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/perl-xCAT/xCAT/ProfiledNodeUtils.pm b/perl-xCAT/xCAT/ProfiledNodeUtils.pm
index 16fd6ae38..80f740384 100644
--- a/perl-xCAT/xCAT/ProfiledNodeUtils.pm
+++ b/perl-xCAT/xCAT/ProfiledNodeUtils.pm
@@ -550,6 +550,32 @@ sub get_allnode_singleattrib_hash
 
 #-------------------------------------------------------------------------------
 
+=head3 get_db_swtiches
+      Description : Get all records of switch config from a table, then return a string list.
+      Arguments   : $tabname - the table name.
+      Returns     : Reference of the records hash.
+=cut
+
+#-------------------------------------------------------------------------------
+sub get_db_switches
+{
+    my $class = shift;
+    my $table = xCAT::Table->new("switches");
+    my @attribs = ("switch");
+    my @entries = $table->getAllAttribs(@attribs);
+    $table->close();
+    my %allrecords;
+    foreach (@entries) 
+    {
+        if ($_->{'switch'}){
+            $allrecords{$_->{'switch'}} = 0;
+        }
+    }
+    return \%allrecords;
+}
+
+#-------------------------------------------------------------------------------
+
 =head3 get_db_swtichports
       Description : Get all records of switch config from a table, then return a string list.
       Arguments   : $tabname - the table name.
@@ -563,6 +589,7 @@ sub get_db_switchports
     my $table = xCAT::Table->new("switch");
     my @attribs = ("switch", "port");
     my @entries = $table->getAllAttribs(@attribs);
+    $table->close();
     my %allrecords;
     foreach (@entries) 
     {
diff --git a/xCAT-server/lib/xcat/plugins/profilednodes.pm b/xCAT-server/lib/xcat/plugins/profilednodes.pm
index 7c0b273bd..9161577e5 100644
--- a/xCAT-server/lib/xcat/plugins/profilednodes.pm
+++ b/xCAT-server/lib/xcat/plugins/profilednodes.pm
@@ -370,7 +370,7 @@ Usage:
     my %allfspips = %$recordsref;
 
     # Get all switches name
-    $recordsref = xCAT::ProfiledNodeUtils->get_allnode_singleattrib_hash('switches', 'switch');
+    $recordsref = xCAT::ProfiledNodeUtils->get_db_switches();
     %allswitches = %$recordsref;
 
     # Get all switches_switchport

From 5459cf6a60e7b6fef40672e899c982c0f93e0835 Mon Sep 17 00:00:00 2001
From: immarvin <yangsbj@cn.ibm.comq>
Date: Wed, 7 Aug 2013 00:38:15 -0700
Subject: [PATCH 23/26] fix defect 3719 [DEV] rcons fails when nodehm.mgt=kvm

---
 xCAT-server/share/xcat/cons/kvm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xCAT-server/share/xcat/cons/kvm b/xCAT-server/share/xcat/cons/kvm
index ae435a5aa..da90b01b8 100755
--- a/xCAT-server/share/xcat/cons/kvm
+++ b/xCAT-server/share/xcat/cons/kvm
@@ -51,9 +51,9 @@ import File::Basename;
 my $scriptname = $0;
 
 my $cmdref={
-    command=>"getcons",
-    arg=>"text",
-    noderange=>$ARGV[0]
+    command=>["getcons"],
+    arg=>["text"],
+    noderange=>[$ARGV[0]]
 };
 use Data::Dumper;
 my $dsthost;

From 67a48e2ee648a44e99884802fdb8d8b6c01aad5f Mon Sep 17 00:00:00 2001
From: daniceexi <wxp@cn.ibm.com>
Date: Wed, 7 Aug 2013 08:36:41 -0400
Subject: [PATCH 24/26] defect 3726: for the initrd of sles, the /modules in
 initrd should symbol link to the new kernel dir if there's new kernel dir

---
 xCAT-server/lib/xcat/plugins/sles.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm
index b2e9cf4c1..e4abb066f 100644
--- a/xCAT-server/lib/xcat/plugins/sles.pm
+++ b/xCAT-server/lib/xcat/plugins/sles.pm
@@ -1851,6 +1851,15 @@ sub insert_dd () {
             # if the new kernel from update distro is not existed in initrd, create the path for it
             if (! -r "$dd_dir/initrd_img/lib/modules/$new_kernel_ver/") {
                 mkpath ("$dd_dir/initrd_img/lib/modules/$new_kernel_ver/");
+                # link the /modules to this new kernel dir
+                unlink "$dd_dir/initrd_img/modules";
+                $cmd = "/bin/ln -sf lib/modules/$new_kernel_ver/initrd $dd_dir/initrd_img/modules";
+                xCAT::Utils->runcmd($cmd, -1);
+                if ($::RUNCMD_RC != 0) {
+                    my $rsp;
+                    push @{$rsp->{data}}, "Handle the driver update failed. Could not create link to the new kernel dir.";
+                    xCAT::MsgUtils->message("I", $rsp, $callback);
+                }
             }
             
             # Copy the drivers to the rootimage

From 650928ad15f9e8a07e9092d5d3278fd3629a4213 Mon Sep 17 00:00:00 2001
From: Jarrod Johnson <jbjohnso@us.ibm.com>
Date: Wed, 7 Aug 2013 16:59:49 -0400
Subject: [PATCH 25/26] Fix for noderange parentheses handling

---
 perl-xCAT/xCAT/NodeRange.pm | 53 +++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/perl-xCAT/xCAT/NodeRange.pm b/perl-xCAT/xCAT/NodeRange.pm
index 301fffe90..66df2c45c 100644
--- a/perl-xCAT/xCAT/NodeRange.pm
+++ b/perl-xCAT/xCAT/NodeRange.pm
@@ -1,5 +1,6 @@
 # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
 package xCAT::NodeRange;
+use Text::Balanced qw/extract_bracketed/;
 require xCAT::Table;
 require Exporter;
 use strict;
@@ -549,6 +550,26 @@ sub abbreviate_noderange {
     return (join ',',keys %targetelems,keys %nodesleft);
 }
 
+sub set_arith {
+    my $operand = shift;
+    my $op = shift;
+    my $newset = shift;
+    if ($op =~ /@/) {       # compute the intersection of the current atom and the node list we have received before this
+      foreach (keys %$operand) {
+        unless ($newset->{$_}) {
+          delete $operand->{$_};
+        }
+      }
+    } elsif ($op =~ /,-/) {        # add the nodes from this atom to the exclude list
+		foreach (keys %$newset) {
+            delete $operand->{$_}
+		}
+	} else {          # add the nodes from this atom to the total node list
+		foreach (keys %$newset) {
+			$operand->{$_}=1;
+		}
+	}
+}
 # Expand the given noderange
 # Input args:
 #  - noderange to expand
@@ -573,6 +594,38 @@ sub noderange {
   }
   my %nodes = ();
   my %delnodes = ();
+  if ($range =~ /\(/) {
+    my ($middle, $end, $start) =
+        extract_bracketed($range, '()', qr/[^()]*/);
+    unless ($middle) { die "Unbalanced parentheses in noderange" }
+    $middle = substr($middle,1,-1);
+    my $op = ",";
+    if ($start =~ m/-$/) { #subtract the parenthetical
+       $op .= "-"
+    } elsif ($start =~ m/@$/) {
+        $op = "@"
+    }
+    $start =~ s/,-$//;
+    $start =~ s/,$//;
+    $start =~ s/@$//;
+    %nodes = map { $_ => 1 } noderange($start,$verify,$exsitenode,%options);
+    my %innernodes = map { $_ => 1 } noderange($middle,$verify,$exsitenode,%options);
+    set_arith(\%nodes,$op,\%innernodes);
+    $op=",";
+    if ($end =~ m/^,-/) {
+        $op = ",-";
+        $end =~ s/^,-//;
+    } elsif ($end =~ m/^@/) {
+        $op = "@";
+        $end =~ s/^@//;
+    } else {
+        $end =~ s/^,//;
+    }
+    my %endnodes = map { $_ => 1 } noderange($end,$verify,$exsitenode,%options);
+    set_arith(\%nodes,$op,\%endnodes);
+    return sort(keys %nodes)
+  }
+
   my $op = ",";
   my @elems = split(/(,(?![^[]*?])(?![^\(]*?\)))/,$range); # commas outside of [] or ()
   if (scalar(@elems)==1) {

From 68b4a0b5c723ba55ea435f7e8c33013eb22baa1d Mon Sep 17 00:00:00 2001
From: jjhua <jinjhua@cn.ibm.com>
Date: Thu, 8 Aug 2013 14:41:41 -0400
Subject: [PATCH 26/26] fixed bug 3732, centos 5.x needs the url rpository

---
 xCAT-server/lib/perl/xCAT/Template.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm
index 5981f1050..11d9c2085 100644
--- a/xCAT-server/lib/perl/xCAT/Template.pm
+++ b/xCAT-server/lib/perl/xCAT/Template.pm
@@ -178,7 +178,7 @@ sub subvars {
       my $source_in_pre;
       my $c = 0; 
       foreach my $pkgdir(@pkgdirs) {
-          if( $platform =~ /^(rh|SL)$/ ) {
+          if( $platform =~ /^(rh|SL|centos)$/ ) {
               if ( $c == 0 ) {
                   # After some tests, if we put the repo in  pre scripts in the kickstart like for rhels6.x
                   # the rhels5.9 will not be installed successfully. So put in kickstart directly.