VMware Cloud Community
halr9000
Commander
Commander
Jump to solution

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)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The UpdateVirtualSwitch method came up in a previous discussion. See .

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

The UpdateVirtualSwitch method came up in a previous discussion. See .

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

Works great Luc, thanks. Smiley Happy






Author of the upcoming book: Managing VMware Infrastructure with PowerShell

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

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
jdvcp
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jdvcp
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

$vsSpec.Policy.NicTeaming.RollingOrder = $false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jdvcp
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
lienhapi
Contributor
Contributor
Jump to solution

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.Nic...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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 and there in Example 4 the value for the rollingOrder property is correct !


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos