Pages: [1]
Print
Author Topic: Link working ethernet adapter in vSwitch0  (Read 1377 times)
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« on: January 14, 2009, 07:54:45 AM »

this was written by Eric Wannemacher -http://www.wannemacher.us/

Code:
#!/bin/bash

# Author:   Eric Wannemacher
# Date:     9/1/2007
# Desc:     Configure the IP of the service console and find the correct
#               ethernet interface for that network.


# Assumptions to make life easier
#   A file was already created by a previous process that contains the desired
#       ip address for the console.
#   The subnets are all class C
#   The default gateway will be at network.254
#   This is a new build and the service console is on vSwitch0

# This file will be removed when configuration is complete.
# Monitor this file to know when the network configuration is done
SC_IP_FILE="/var/install.ip"

if [ ! -f $SC_IP_FILE ]; then
  echo "Did not find the IP configuration file $SC_IP_FILE"
  exit 1
fi

# Souce the IP file to set the desired service console IP
. $SC_IP_FILE

if [ "$SC_IP_ADDR" == "" ]; then
  echo "No IP address to configure"
  exit 1
fi

# Determine the other important network settings
SC_IP_NM="255.255.255.0"
SC_IP_GW=$(echo $SC_IP_ADDR | sed s/[0-9]*$/254/)



# Configure the settings
echo "CONFIGURING WITH THE FOLLOWING INFORMATION"
echo -e "IP:\t\t$SC_IP_ADDR"
echo -e "NETMASK:\t$SC_IP_NM"
echo -e "GATEWAY:\t$SC_IP_GW"

# IP
/usr/sbin/esxcfg-vswif -i $SC_IP_ADDR -n $SC_IP_NM vswif0

# Gateway
if [ ! $(grep 'GATEWAY=' /etc/sysconfig/network) ]; then
  echo "GATEWAY=$SC_IP_GW" >> /etc/sysconfig/network
else
  mv /etc/sysconfig/network /etc/sysconfig/network.orig
  cat /etc/sysconfig/network.orig | sed "s/GATEWAY=.*/GATEWAY=$SC_IP_GW/" > /etc/sysconfig/network
fi

# Restart the network
echo "restarting the network!"
service network restart

# What vswitch is the service console on?
SC_SWITCH="vSwitch0"

# Unlink all of the NICs from the vSwitch
echo "Unlinking all nics"
for NIC in $(esxcfg-nics -l | awk 'NR>1{print $1}'); do
  /usr/sbin/esxcfg-vswitch -U $NIC $SC_SWITCH
done

# Link the NICs one at a time until one of them works
echo "Start checking for a good NIC"
for NIC in $(esxcfg-nics -l | awk 'NR>1{print $1}'); do
  echo "Linking $NIC"
  /usr/sbin/esxcfg-vswitch -L $NIC $SC_SWITCH

  # If we can ping the gateway, be happy and exit
  ping -c 4 $SC_IP_GW > /dev/null
  if [ "$?" -eq "0" ]; then
    echo "Found a good NIC: $NIC"
    rm -f $SC_IP_FILE
    # Restart the Altiris agent to make sure it reconnects to the server
    service adlagent restart
    exit 0
  fi

  # Unlink non-responding nic
  /usr/sbin/esxcfg-vswitch -U $NIC $SC_SWITCH
done

# Uh oh, if we got here then the network was not configured correctly.
echo "Problem configuring the network"
exit 1

Logged
Pages: [1]
Print
Jump to: