VMware Cloud Community
friedeva
Contributor
Contributor

Problem with Policy.NicTeaming.NicOrder.activeNic

Hello all,

I'm trying to write a function for configuring a vSwitch, like this:

"

function standardvswitch {

param ($esx, $vs, $actnic)

$vmhost = Get-VMHost $esx

$hostview = $vmhost | Get-View

$ns = Get-View -Id $hostview.ConfigManager.NetworkSystem

$vsConfig = $hostview.Config.Network.Vswitch | Where-Object { $_.Name -eq $vs }

$vsSpec = $vsConfig.Spec

$vsSpec.Policy.security = New-Object VMWare.Vim.HostNetworkSecurityPolicy

$vsSpec.Policy.Security.allowPromiscuous = $false

$vsSpec.Policy.Security.forgedTransmits = $false

$vsSpec.Policy.Security.macChanges = $true

$vsspec.Policy.ShapingPolicy = New-Object VMWare.Vim.HostNetworkTrafficShapingPolicy

$vsSpec.Policy.shapingPolicy.enabled = $false

$vsspec.policy.NicTeaming = New-object VMWare.Vim.HostNicTeamingPolicy

$vsSpec.Policy.NicTeaming.notifySwitches = $true

$vsSpec.Policy.NicTeaming.policy = "loadbalance_srcid"

$vsSpec.Policy.NicTeaming.ReversePolicy = $false

$vsSpec.Policy.NicTeaming.RollingOrder = $true

$vsSpec.Policy.NicTeaming.NicOrder = New-Object VMware.Vim.HostNicOrderPolicy

$vsSpec.Policy.NicTeaming.NicOrder.activeNic = $actnic

$vsSpec.Policy.NicTeaming.NicOrder.standbyNic = $null

$vsSpec.Policy.NicTeaming.failureCriteria = New-Object VMWare.Vim.HostNicFailureCriteria

$vsSpec.Policy.NicTeaming.failureCriteria.checkBeacon = $false

$vsSpec.Policy.nicTeaming.failureCriteria.checkSpeed = "minimum"

$vsSpec.Policy.nicTeaming.failureCriteria.speed = 10

$vsSpec.Policy.nicTeaming.failureCriteria.checkDuplex = $false

$vsSpec.Policy.nicTeaming.failureCriteria.fullDuplex = $false

$vsSpec.Policy.nicTeaming.failureCriteria.checkErrorPercent = $false

$vsSpec.Policy.nicTeaming.failureCriteria.percentage = 0

$ns.UpdateVirtualSwitch( $vs, $vsSpec)

}

#calling the function

$esxiname = "myesxi.server"

$esxi = Connect-VIServer $esxiname -username root -password mypassword

$dmznic = @("vmnic1")

standardvswitch myesxi.server vSwitch1 $dmznic

"

This function works fine.

The problem arises when I try to pass a second active nic to the switch as a variable. For instance, if I write $dmznic = @("vmnic0", "vmnic1") then execution always fails with :

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

I tried many different techniques (with the @), without, with simple quotes, double quotes, without coma...). It does not seem to work. Of course, if I set the nics directly in the function, like : $vsSpec.Policy.NicTeaming.NicOrder.activeNic = @("vmnic1", vmnic2"), then it works. But it defeats the point of my function, of course, as I want the nics defined outside the function.

Any idea ?

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership

You have to specify that the $actnic parameter is an array.

I attached the corrected script since it contains square brackets.

And the forum SW doesn't like square brackets.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
friedeva
Contributor
Contributor

Sadly the problem remains. Maybe the variable definition has to be changed, as we already specify an array at the function parameters ?

$dmznic = @("vmnic0", "vmnic1")

A did tests again with different forms of quotes, @'s or not. No luck !

Reply
0 Kudos
LucD
Leadership
Leadership

The problem is in the param line.

It should say

param (\[string\]$esx, \[string\]$vs, \[string\[\]\]$actnic)

I hope this display correctly.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
friedeva
Contributor
Contributor

This has been changed already ! I'm now using your version of the script for my testing and the param line has been corrected.

Still, it's not working; there must be something else. Still searching!

Reply
0 Kudos
LucD
Leadership
Leadership

Are you getting a message ?

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
friedeva
Contributor
Contributor

Same good old :

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

Reply
0 Kudos
LucD
Leadership
Leadership

Strange, works for me.

Since your copying the current config of the vSwitch it could be one of the values you copy.

Can you set up the NIC Teaming via the vSphere Client ?

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
friedeva
Contributor
Contributor

As my hosts for testing are limited to two nics I'm testing the nicteaming setting on vSwitch0. The vSwitch0 is created at installation with vmnic0 connected, and I try to add vmnic1 with the script. Maybe there is a problem due to vmnic0 already present on the vSwitch ? In this case, what would be the solution?

Or maybe, something related to the management network present on this vSwitch?

Nevertheless, if I add vmnic1 to the vSwitch0 from the GUI it succeeds, so it's clearly related to the script itself.

Thanks a lot for your help!

Reply
0 Kudos
LucD
Leadership
Leadership

The problem is due to the fact that for the UpdateVirtualSwitch method, the NICs must already be attached to the vSwitch.

You can do this with the Set-VirtualSwitch cmdlet like this for example

...
#calling the function
$esxiname = "myesxi.server"

$esxi = Connect-VIServer $esxiname -username root -password mypassword 

Get-VMHost $esxiname | Get-VirtualSwitch -Name "vSwitch1" | Set-VirtualSwitch -Nic "vmnic1"

$dmznic = @("vmnic0", "vmnic1")

standardvswitch $esxiname vSwitch1 $dmznic

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
friedeva
Contributor
Contributor

OK I see!

In other words, it means that you cannot add a vmnic to a vswitch using UpdateVirtualSwitch. Strange, given the number of options you can customize this way! But well, it's a logical explanation at least.

I'll have to think my script again !

Thanks a lot for your help.

Reply
0 Kudos
LucD
Leadership
Leadership

Unfortunately, I wasn't too specific in my previous answer Smiley Sad

You can add the 2nd NIC to the vSwitch in the same call to UpdateVirtualSwitch.

But not through the ActiveNic, nor standbyNic properties, you will have to use the Bridge.nicDevice property.

$vsSpec.Bridge.nicDevice = $actnic

See the attached file for the full script.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
friedeva
Contributor
Contributor

I had to define the bridge first, with :

$vsSPec.Bridge = New-Object VMware.Vim.HostVirtualSwitchBondBridge

And then...it worked!

Thanks a lot!

Reply
0 Kudos