esxcfg-vswitch-lamw-mod.pl

Version 2

    Table of Contents

    • Author

    • Description

    • Category

    • Requirements

    • Version Support

    • Sample Execution

    • Script Download

     

     

    Author

    William Lam

     

    Description

    This script was motivated by VMTN community member and blogger Cody Bunch who posed a question on the VMware forums regarding vCLI and configuring advanced NIC teaming policy for a vSwitch. With today's current implementation of VMware's vCLI esxcfg-vswitch, it lacks quite on configuring advanced configurations for a vSwitch:

     

     

    General

    • Number of ports when creating a new vSwitch

     

    Security

    • Promiscuous Mode

    • MAC Address Changes

    • Forged Transmits

     

    Traffic Shaping

    • Status

    • Average Bandwidth

    • Peak Bandwidth

    • Burst Size

     

    NIC Teaming

    • Load Balancing

    • Network Failover Detection

    • Notify Switches

    • Failback

    • Failover Order

     

    All these can be configured through the vSphere API, I'm guessing VMware decided not to include these features within esxcfg-vswitch, thinking that not many users will be automating these configurations via the CLI. Even with classic ESX, there were quite a few users wanting to automate these configurations and had to rely on unsupported vimsh wrapper (vmware-vim-cmd/vim-cmd) to setup the more advanced configurations for a vSwitch. This script allows you to configure all of these parameters.

     

    Category

    • Initial Server Set Up

     

    Requirements

     

    Version Support

    • Supports ESX(i) (licensed version only)

     

    Usage

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl
    The options are invalid.
    
    
    Synopsis: ./esxcfg-vswitch-lamw-mod.pl OPTIONS [<vswitch>]
    
    
    Command-specific options:
       --add
        -a
              Add a new virtual switch
       --add-dvp-uplink
        -P
              Add an uplink adapter (pnic) to a DVPort (valid for vSphere 4.0 and later)
       --add-pg
        -A
              Add a portgroup to a virtual switch
       --add-pg-uplink
        -M
              Add an uplink adapter (pnic) to a portgroup (valid for vSphere 4.0 and later)
       --avgband
              Average Bandwidth (Kbits/sec)
       --burstsize
              Burst Size (Kbytes)
       --check
        -c
              Check to see if virtual switch exists
       --check-pg
        -C
              Check to see if a portgroup exists
       --del-dvp-uplink
        -Q
              Delete an uplink adapter from a DVPort (valid for vSphere 4.0 and later)
       --del-pg
        -D
              Delete the portgroup from the virtual switch
       --del-pg-uplink
        -N
              Delete an uplink adapter from a portgroup (valid for vSphere 4.0 and later)
       --delete
        -d
              Delete the virtual switch
       --dvp
        -V
              The name of the DVPort (valid for vSphere 4.0 and later)
       --failback
              Failback [yes|no]
       --faildetect
              Network Failover Detection [LINK|BEACON]
       --forged
              Enable or disable promiscous mode [accept|reject]
       --get-cdp
        -b
              Print the current CDP setting for this virtual switch (valid for vSphere 4.0 and later)
       --link
        -L
              Sets a pnic as an uplink for the virtual switch
       --list
        -l
              List vswitches and port groups
       --loadbalance
              Load Balancing policy [PORTID|IPHASH|MACHASH|FAILOVER]
       --mac
              Enable or disable promiscous mode [accept|reject]
       --mtu
        -m
              Set MTU for the virtual switch
       --nic-active
              List of linked vmnics to be set as active network adapters used for load balancing
       --nic-standby
              List of linked vmnics to be set as standby network adapters used for failover
       --notifysw
              Notify Switches [yes|no]
       --peakband
              Peak Bandwidth (Kbits/sec
       --pg
        -p
              The name of the portgroup
       --port
              The number of ports to vSwitch [8|24|56|120|248|504|1016|2040|4088]
       --promiscuous
              Enable or disable promiscous mode [accept|reject]
       --set-cdp
        -B
              Set the CDP status for a given virtual switch (valid for vSphere 4.0 and later).
              To set pass "down", "listen", "advertise", or "both"
       --trafficshape
              Enable or or disable promiscous mode [true|false]
       --unlink
        -U
              Removes a pnic from the uplinks for the virtual switch
       --vihost
        -h
              The host to use when connecting via Virtual Center
       --vlan
        -v
              Set vlan id for portgroup specified by -p
    
    Common VI options:
       --config (variable VI_CONFIG)
          Location of the VI Perl configuration file
       --credstore (variable VI_CREDSTORE)
          Name of the credential store file defaults to <HOME>/.vmware/credstore/vicredentials.xml on Linux and <APPDATA>/VMware/credstore/vicredentials.xml on Windows
       --encoding (variable VI_ENCODING, default 'utf8')
          Encoding: utf8, cp936 (Simplified Chinese), iso-8859-1 (German), shiftjis (Japanese)
       --help
          Display usage information for the script
       --passthroughauth (variable VI_PASSTHROUGHAUTH)
          Attempt to use pass-through authentication
       --passthroughauthpackage (variable VI_PASSTHROUGHAUTHPACKAGE, default 'Negotiate')
          Pass-through authentication negotiation package
       --password (variable VI_PASSWORD)
          Password
       --portnumber (variable VI_PORTNUMBER)
          Port used to connect to server
       --protocol (variable VI_PROTOCOL, default 'https')
          Protocol used to connect to server
       --savesessionfile (variable VI_SAVESESSIONFILE)
          File to save session ID/cookie to utilize
       --server (variable VI_SERVER, default 'localhost')
          VI server to connect to. Required if url is not present
       --servicepath (variable VI_SERVICEPATH, default '/sdk/webService')
          Service path used to connect to server
       --sessionfile (variable VI_SESSIONFILE)
          File containing session ID/cookie to utilize
       --url (variable VI_URL)
          VI SDK URL to connect to. Required if server is not present
       --username (variable VI_USERNAME)
          Username
       --verbose (variable VI_VERBOSE)
          Display additional debugging information
       --version
          Display version information for the script
    
    

     

    Sample Execution

     

    Create a new vSwitch specifying the number of ports:

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com -a vSwitch2 --port 504
    

     

    Configure Promiscuous Mode (accept|reject):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --promiscuous accept vSwitch2 --server
    

     

    Configure MAC Address change (accept|reject):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --mac accept vSwitch2
    

     

    Configure Forged Transmits (accept|reject):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --forged accept vSwitch2
    

     

    Enable Traffic Shapping:

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --trafficshape true vSwitch2
    

     

    Configure Average Bandwidth (Kbits/sec):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --avgband 100 vSwitch2
    

     

    Configure Peak Bandwidth (Kbits/sec):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --peakband 300 vSwitch2
    

     

    Configure Burst Size (Kbytes):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --burstsize 400 vSwitch2
    

     

    Configure Load Balancing (PORTID|IPHASH|MACHASH|FAILOVER):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --loadbalance IPHASH vSwitch2
    

     

    Configure Network Failover Detection (LINK|BEACON):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --faildetect BEACON vSwitch2
    

     

    Configure Notify Switches (yes|no):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --notifysw yes vSwitch2
    

     

    Configure Failback (yes|no):

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --failback no vSwitch2
    

     

    Configure Failover Order:

     

    Let's say we have 2 vmnic's that have been teamed using -L option and we want to set vmnic1 to active and vmnic2 to standby

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --nic-active vmnic1 --nic-standby vmnic2 vSwitch2
    

     

    *Note:* You can specify multiple vmnic devices to either --nic-active or --nic-standby

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --nic-standby vmnic1,vmnic2 vSwitch2
    

     

    With all these options, it could be painful if you had to run each one at a time? All the features added can actually be specified all on 1 line, assuming you meet all the requirements.

     

    Here is the scenario of creating a new vSwitch named vSwitch2 with 504 ports and teamed with 2 pNIC (vmnic1 and vmnic2) and configured with the following advanced options:

     

    Promiscuous Mode

    reject

    MAC Address Change

    accept

    Forged Transmits

    reject

    Traffic Shaping

    enabled

    Average Bandwidth

    100 Kbits/sec

    Peak Bandwidth

    300 Kbits/sec

    Burst Size

    390 Kbytes

    Load Balancing

    Route based on source MAC hash

    Network Failover Detection

    Beacon Probing

    Notify Switches

    yes

    Failback

    no

    Failover Order

    Active=vmnic1 Standby=vmnic2

     

    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com -a vSwitch2 --port 504
    
    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com -L vmnic1 vSwitch2
    Update uplinks : vmnic1
    
    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com -L vmnic2 vSwitch2
    Update uplinks : vmnic1, vmnic2
    
    [vi-admin@scofield ~]$ ./esxcfg-vswitch-lamw-mod.pl --server esxi4-1.primp-industries.com --promiscuous reject --mac accept --forged reject --trafficshape true --avgband 100 --peakband 300 --burstsize 390 --loadbalance MACHASH --faildetect BEACON --notifysw yes --failback no --nic-active vmnic1 --nic-standby vmnic2 vSwitch2
    

     

    Download script[here|http://vghetto.svn.sourceforge.net/viewvc/vghetto/scripts/esxcfg-vswitch-lamw-mod.pl?view=log]