ADVERTISE HERE

Script to Configure ESX vSwitch Network Load Balancing

Title: Script to Configure ESX vSwitch Network Load Balancing
Author(s): Xtravirt (Gavin Jolliffe)
Target Audience: Technical - Intermediate
Current Revision: 1.0 April 2008
First Published: 1 April 2008
Products: VMware ESX
UID: XD10066
Information
Title: 
Script to Configure ESX vSwitch Network Load Balancing
Author(s): 
Xtravirt (Gavin Jolliffe)
Target Audience: 
Technical - Intermediate
First Published: 
1 April 2008
Products: 
VMware ESX
UID: 
XD10066

Script ESX vSwitch network load balancing using vimsh

1.0 Overview

It is possible to script the load balancing of a Virtual Switch by using the vimsh command.  The basic command syntax is:

vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy [load balance option] [vSwitch#]"

For each of the 4 load balancing options there is a different command option:

Load Balance Type Command Option
Port ID loadbalance_srcid
IP Hash loadbalance_ip
MAC loadbalance_srcmac
Failover Only failover_explicit

For example to change vSwitch1 from the default Port ID to IP address load balancing the command line would look like this:

vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy loadbalance_ip vSwitch1"

This should help those who like to run automated scripted ESX builds.  Note that if using in conjunction with esxcfg commands to create and bind vSwtiches you'll need to run a service management restart and put a 20 second or so sleep to allow background processes to complete, eg: this script creates a vSwitch, labels it Production, binds vmnic 1 & 2 to it, restarts hostd, pauses for 20 seconds then modifies loadbalancing of the vSwitch to the MAC based option.

esxcfg-vswitch -a vSwitch2
esxcfg-vswitch -A Production vSwitch2
esxcfg-vswitch -L vmnic2 vSwitch2
esxcfg-vswitch -L vmnic1 vSwitch2
vimsh -n -e "/internalsvc/refresh_network"
vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy loadbalance_srcmac vSwitch2"

Thanks to Mike Laverick (RTFM Education) for assisting with this Hot Tip

References
References: 
  1. Nil
References
  1. Nil
Tags
ESX
load balancing
switch
teaming
vimsh
VMware
vswitch
Networking

Spotlight:

VMware Documentation Downloader v11.08.30

Updated for vSphere 5 - A free tool for those on the move who need information FAST

vSphere 5 License Entitlement Changes

See what has changed in the license entitlement in vSphere 5?

Thin Client vs Zero Client

The differences between Thin and Zero desktop clients for VDI

Technology Exchange: