Skip navigation
VMware

This Question is Answered (go to answer)

2 "helpful" answers available (6 pts)
778 Views 10 Replies Last post: Feb 27, 2009 4:09 PM by LucD RSS
halr9000 Master vExpert 1,124 posts since
Jun 7, 2007
Currently Being Moderated

Oct 4, 2008 6:38 PM

Problem getting a NetworkSystem script to work

Alright Luc...what am I missing here?  The last line doesn't work, I get this err:

 

Exception calling "UpdateVirtualSwitch" with "2" argument(s): "A specified parameter was not correct."

+ $ns.UpdateVirtualSwitch( <<<<  $VSwitchName, $vsSpec )

 

param ( [string]$VMHostName, [string]$VSwitchName )

$vmhost = Get-VMHost $VMHostName
$hostview = $vmhost | Get-View
$ns = Get-View -Id $hostview.ConfigManager.NetworkSystem
$vsSpec = New-Object VMware.Vim.HostVirtualSwitchSpec
$vsSpec.Policy = New-Object VMware.Vim.HostNetworkPolicy
$vsSpec.Policy.Security = New-Object VMware.Vim.HostNetworkSecurityPolicy
$vsSpec.Policy.Security.AllowPromiscuous = $true
$vsSpec.Policy.NicTeaming = New-Object VMware.Vim.HostNicTeamingPolicy
$vsSpec.Policy.NicTeaming.Policy = "loadbalance_srcmac"
$ns.UpdateVirtualSwitch( $VSwitchName, $vsSpec )

 

 






Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
1. Oct 5, 2008 3:15 AM in response to: halr9000
Re: Problem getting a NetworkSystem script to work

The UpdateVirtualSwitch method came up in a previous discussion. See  Re: Nic Teaming Policy.

 

In the end I discovered that the way the method is described in the SDK API Reference Guide doesn't correspond with the reality.

The method needs most (if not all) of the properties in the HostVirtualSwitchSpec to be set.

 

You can go the long way. Something like this

param ( [string]$VMHostName, [string]$VSwitchName )
 
$vmhost = Get-VMHost $VMHostName
$hostview = $vmhost | Get-View
$ns = Get-View -Id $hostview.ConfigManager.NetworkSystem
$vsSpec = New-Object VMware.Vim.HostVirtualSwitchSpec
$vsSPec.Bridge = New-Object VMware.Vim.HostVirtualSwitchBondBridge
$vsSPec.Bridge.Beacon = New-Object VMware.Vim.HostVirtualSwitchBeaconConfig
$vsSPec.Bridge.Beacon.Interval = 1
$vsSPec.Bridge.NicDevice = ("vmnic2","vmnic1")
$vsSpec.Mtu = 0
$vsSpec.numPorts = 64
$vsSpec.Policy = New-Object VMware.Vim.HostNetworkPolicy
$vsSpec.Policy.NicTeaming = New-Object VMware.Vim.HostNicTeamingPolicy
$vsSpec.Policy.NicTeaming.FailureCriteria = New-Object VMware.Vim.HostNicFailureCriteria
$vsSpec.Policy.NicTeaming.FailureCriteria.checkBeacon = $false
$vsSpec.Policy.NicTeaming.FailureCriteria.checkDuplex = $false
$vsSpec.Policy.NicTeaming.FailureCriteria.checkErrorPercent = $false
$vsSpec.Policy.NicTeaming.FailureCriteria.checkSpeed = "minimum"
$vsSpec.Policy.NicTeaming.FailureCriteria.fullDuplex = $false
$vsSpec.Policy.NicTeaming.FailureCriteria.Percentage = 0
$vsSpec.Policy.NicTeaming.FailureCriteria.Speed = 10
$vsSpec.Policy.NicTeaming.NicOrder = New-Object VMware.Vim.HostNicOrderPolicy
$vsSpec.Policy.NicTeaming.NicOrder.ActiveNic = ("vmnic1","vmnic2")
$vsSpec.Policy.NicTeaming.NotifySwitches = $true
$vsSpec.Policy.NicTeaming.Policy = "loadbalance_srcmac"
$vsSpec.Policy.NicTeaming.ReversePolicy = $true
$vsSpec.Policy.NicTeaming.RollingOrder = $false
$vsSpec.Policy.OffloadPolicy = New-Object VMware.Vim.HostNetOffloadCapabilities
$vsSpec.Policy.OffloadPolicy.CsumOffload = $true
$vsSpec.Policy.OffloadPolicy.TcpSegmentation = $true
$vsSpec.Policy.OffloadPolicy.ZeroCopyXmit = $true
$vsSpec.Policy.Security = New-Object VMware.Vim.HostNetworkSecurityPolicy
$vsSpec.Policy.Security.AllowPromiscuous = $true
$vsSpec.Policy.Security.ForgedTransmits = $true
$vsSpec.Policy.Security.MacChanges = $true
$vsSpec.Policy.ShapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy
$vsSpec.Policy.ShapingPolicy.AverageBandwidth = 0
$vsSpec.Policy.ShapingPolicy.BurstSize = 0
$vsSpec.Policy.ShapingPolicy.Enabled = $false
$vsSpec.Policy.ShapingPolicy.PeakBandwidth = 0

$ns.UpdateVirtualSwitch($VSwitchName,$vsSpec)

You would need some extra params to do it like this (i.e. for the NICs).

 

Or you could go the short(er) way.

param ( [string]$VMHostName, [string]$VSwitchName )

$esxImpl = Get-VMHost -Name $VMHostName
$esx = $esxImpl | Get-View

foreach($sw in $esx.Config.Network.Vswitch){
  if($sw.Name -eq $VSwitchName){break}
}

$vsSpec = $sw.Spec
$vsSpec.Policy.NicTeaming.Policy = "loadbalance_srcmac"
$vsSpec.Policy.Security.AllowPromiscuous = $true

$ns.UpdateVirtualSwitch($VSwitchName,$vsSpec)

 

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
jdvcp Enthusiast 57 posts since
Feb 21, 2007
Currently Being Moderated
3. Oct 20, 2008 6:42 PM in response to: halr9000
Re: Problem getting a NetworkSystem script to work

the code gets truncated, etc.  Anyway you can attach it?  thx!

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
4. Oct 23, 2008 3:55 AM in response to: jdvcp
Re: Problem getting a NetworkSystem script to work

Sure.

 

The short version was missing 1 line.

The attached script is updated.

 

Thanks for noticing this to rdejong.

 

Message was edited by: LucD

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
jdvcp Enthusiast 57 posts since
Feb 21, 2007
Currently Being Moderated
5. Oct 21, 2008 4:29 AM in response to: LucD
Re: Problem getting a NetworkSystem script to work

Luc, one more quick one. I cannot find out how to set Failback to NO under nic teaming (from the gui). I have tried both the ReversePolicy and another option (can't recall since I'm on bberry). I did not get any errors when executing my script but nothing changed in the GUI for VI client (but other settings I put in the script worked fine). Wondering if you have been able to get Failback set to NO in a script before. I can do it in vimsh but I really want to use powershell.

 

Thx

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
6. Oct 21, 2008 5:09 AM in response to: jdvcp
Re: Problem getting a NetworkSystem script to work

I think you should use the rollingOrder property of the HostNicTeamingPolicy.

$vsSpec.Policy.NicTeaming.RollingOrder = $false

 

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
jdvcp Enthusiast 57 posts since
Feb 21, 2007
Currently Being Moderated
7. Oct 21, 2008 11:24 AM in response to: LucD
Re: Problem getting a NetworkSystem script to work

Strange...after trying that as I did before, in the GUI (following a refresh etc), Failback still shows as YES.  And, there are no errors in powershell or in PowerGUI.  I wonder if doing a vimsh network restart will help.

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
8. Oct 21, 2008 11:41 AM in response to: jdvcp
Re: Problem getting a NetworkSystem script to work

In my VI Client it showed.

Perhaps the VI Client version is different ? I'm at the latest version (October patches included).

Did you try to stop/start the VI Client ?

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
lienhapi Novice 6 posts since
Jun 19, 2008
Currently Being Moderated
9. Feb 27, 2009 1:37 PM in response to: jdvcp
Re: Problem getting a NetworkSystem script to work

 

Hi,

 

 

Don't know if you found the solution but I can't resist :

I was also looking to set the failback parameter to "NO" and ran into

the same issue (not updated under VC)

 

 

 

After some research i found in the vi api documentation that the RollingOver flag must be set to $TRUE in order to disable nic teaming failback (i know, it's very logical)

You'll

find the information here :

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.host.NetworkPolicy.NicTeamingPolicy.html

 

 

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
10. Feb 27, 2009 4:09 PM in response to: lienhapi
Re: Problem getting a NetworkSystem script to work

You are right, the rollingOrder property needs to be set to $true to have it display as "No" in the VIC.

 

Just cross-checked with my portgroup teaming document in  Portgroup - how to configure Nic Teaming and there in Example 4 the value for the rollingOrder property is correct !

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com

Bookmarked By (0)

Share This Page

Communities