Using vmware-vim-cmd to Modify a Portgroup

While creating a command-line configuration guide for a design that I’d prepared, I found myself in need of a command that sets the NIC failover order explicitly for a portgroup. I suspected—and was correct—that vmware-vim-cmd would do the job, but was having a hard time finding documentation on the correct syntax. Even the extensive XtraVirt vimsh white paper did not have information on the syntax. After a little bit of digging around, I found the information for which I was looking. Here it is for future benefit.

The syntax for using vmware-vim-cmd to modify the NIC failover order for a portgroup looks like this:

vmware-vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-active=<List of NICs> <vSwitch#> <Portgroup>

If the portgroup name includes spaces, then wrap the portgroup name in double quotes, like this:

vmware-vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-active=vmnic0 vSwitch0 "Service Console"

That sets only the active NICs. Any NICs not included in the command above are set to Unused, which is generally not the desired result. Usually, we’d want those to be Standby NICs. To set the standby NICs, use this command:

vmware-vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-standby=<List of VMNICs> <vSwitch#> <Portgroup>

Run the command to set the active NICs first, then run the command to set the standby NICs. The following example will set vmnic0 as Active and vmnic1 as standby for the Service Console port group on vSwitch0:

vmware-vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-active=vmnic0 vSwitch0 "Service Console"
vmware-vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-standby=vmnic1 vSwitch0 "Service Console"

I hope this is helpful to some readers.

UPDATE: A reader clarified in the comments that the parameters can actually be combined into a single command, like so:

vmware-vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-active=vmnic0 --nicorderpolicy-standby=vmnic1 vSwitch0 "Service Console"

I tested this syntax on VMware ESX 3.5 Update 3 and it does work as expected. Thanks, Timo!

Tags: , , ,

  1. Timo Sugliani’s avatar

    This is indeed helpful for network PXE & automatic installations :-)

    If I’m not mistaken, i think you can set active / standby nics with only one command, just using the “two options” on the command line.

    ex: vim-cmd hostsvc/net/portgroup_set –nicorderpolicy-active=vmnic0 –nicorderpolicy-standby=vmnic1 vSwitch0 ‘Management Network’

    I use it to post-conf VMware ESXi portgroups.

    PS: i think this syntax will give you a minimalistic help for the command

    # vim-cmd help hostsvc/net/portgroup_set

  2. slowe’s avatar

    Timo, you are absolutely correct–the command does allow you to set both the active and standby NICs on the command line. Thanks for the tip!

  3. Duncan’s avatar

    I blogged my scripted install kickstart script a while back that actually contains these commands : http://www.yellow-bricks.com/2008/06/27/scripted-install/

  4. William’s avatar

    Hey Scott,

    I just published this small webpage, it contains other useful “vimsh” scripts/commands you might find interesting:

    http://www.engineering.ucsb.edu/~duonglt/vmware/

  5. Ed Bontempo’s avatar

    Scott,

    Thanks for the tip! I’ve incorporated this into my kickstart process.

    I’ve been using vmware-vim-cmd more and more instead of vimsh, and it works very well with the exception of one command:

    vmware-vim-cmd “hostsvc/net/vswitch_setpolicy –nicteaming-policy loadbalance_ip vSwitchX”

    Every time I try to use vmware-vim-cmd to change the NIC teaming policy to loadbalance_ip (or anything, really,) it returns “Invalid Command” (at least, as of ESX 3.5 Update 2. I haven’t tried it in Update 3 yet, though.)

    Have you come across this one yourself? I’d prefer to use vmware-vim-cmd across the board in my scripts since it’s cleaner than vimsh and returns completion codes.

  6. Duncan’s avatar

    Ed, I used the following for ESX 3.5 U1 and it works like a charm:
    /usr/bin/vimsh -n -e “hostsvc/net/vswitch_setpolicy –nicteaming-policy=loadbalance_ip vSwitch1?

  7. William’s avatar

    Ed, as Duncan had already mentioned, you need to add an “=” sign to the end of your –nicteaming-policy:

    vmware-vim-cmd hostsvc/net/vswitch_setpolicy –nicteaming-policy=loadbalance_ip vSwitch0

  8. Chris’s avatar

    Is it recommended that the Service Console and VMotion VMKernal port groups not be set to an active/active nic configuration? My vSwitches are set to active/active with “Route based on ip hash” load balancing policy as I am using stacked Cisco 3120 switches.

  9. slowe’s avatar

    Chris,

    As far as I know, there’s no recommendation for that other than using switches that support Multi-chassis EtherChannel (MEC), also known as cross-stack EtherChannel. The Catalyst 3120 switches, IIRC, do support that. So, you’re covered.

    Just know that using link aggregation like this for those particular types of traffic won’t do a whole lot for you, though–EtherChannel/802.3ad/link aggregation really only gets you more throughput when you have multiple source-destination IP address pairs. VMotion is primarily point-to-point, and the Service Console usually communicates most with vCenter Server.

  10. Shahar’s avatar

    This is all great
    but
    how do I associate a ESX4i guest to a port-group remotly?

  11. kenneth’s avatar

    How do i list multiple vmnics when using this command, i tried “,” and brackets but didn’t seem to like it.

    Thanks!

  12. Kevin’s avatar

    Okay, this rocks! Exactly what I need. Now I’m writing a script to ensure that a server has been built correctly and doesn’t have any settings wrong. What command is equivalent to “get” rather than “set” the active nic and standby nic please?

    cheers,
    Kevin

  13. Antti Pennanen’s avatar

    Hi,

    I started to script automated installation process of our ESXi hosts so that when I plug a blade server into our C7000 blade enclosure it basically installs first a fresh copy of ESXi and then our mgmt linux server connects to it by using vi perl toolkit. I first thought about using host profiles but since they don’t support iscsi configurations I decided to go with the scripts. Now I have a problem because it seems that I cannot modify NIC Failover order by using VI Toolkit and I need to configure that to all of my portgroups (including swiscsi and production networks). Is there anyway how to get this done using “supported” methods instead of logging to ESXi Troubleshooting Mode via SSH and using vim-cmd directly from there? I have been googling around for 8 hours and haven’t found a solution for this.

    Cheers,
    Andy

  14. slowe’s avatar

    Antti, I’m not immediately aware of a workaround, but that doesn’t mean a workaround doesn’t exist. Have you tried something other than the VI Perl Toolkit, like PowerCLI or the vCLI?

  15. Rich’s avatar

    Kenneth,

    This command worked for me in esxi 4.1:
    vim-cmd hostsvc/net/vswitch_setpolicy –nicorderpolicy-active=vmnic5,vmnic0 vSwitch0

    That will apply the policy to the vswitch, but not the port group. However, this fails:
    vim-cmd hostsvc/net/portgroup_set –nicorderpolicy-active=vmnic5,vmnic0 vSwitch0 “Management Network”

    I would call that a bug.