Automation

 View Only
Expand all | Collapse all

Apply VMNICs to LAG Uplink

  • 1.  Apply VMNICs to LAG Uplink

    Posted Mar 30, 2021 06:19 PM

    I was just testing a script to configure all new vHosts vDS and was really happy it worked, but then I see it assigned them to my "uplink" groups and not the LAG group named "TRAFFIC". I can't find much on how to fix this.  

    Thank you and any help is always appreciated.

     

    ## Attach vHost to vDS
    Get-VDSwitch -Name $vDS | Add-VDSwitchVMHost -VMHost $TargetvHostHostname

    ## Add Uplinks to vDS
    $Traffic1 = Get-VMHost $TargetvHostHostname | Get-VMHostNetworkAdapter -Physical -Name vmnic$TrafficPhy1
    Get-VDSwitch $vDS | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $Traffic1 -Confirm:$false
    $Traffic2 = Get-VMHost $TargetvHostHostname | Get-VMHostNetworkAdapter -Physical -Name vmnic$TrafficPhy2
    Get-VDSwitch $vDS | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $Traffic2 -Confirm:$false
    $Traffic3 = Get-VMHost $TargetvHostHostname | Get-VMHostNetworkAdapter -Physical -Name vmnic$TrafficPhy3
    Get-VDSwitch $vDS | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $Traffic3 -Confirm:$false



  • 2.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 30, 2021 06:39 PM

    I'm afraid that the cmdlet doesn't allow you to specify LAG groups as a destination.
    The only way I know of is via the API methods, there is a good example here.



  • 3.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 02:30 AM

    Man, I am really not sure what I am reading in that code.  Only thing I truly understood is Hold my beer

    What is the cmdlet proxy referring to all over the place??

    His code seems to be also just looking for nearly anything connected and I am more static...and simpler like me

    Any suggestions where to look to begin? 



  • 4.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 05:31 AM


  • 5.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 02:30 PM

    I believe I have altered it correctly, but I am not sure what the error means:

    Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not
    null or empty, and then try the command again.
    At line:1 char:15
    + Get-View -Id $vds.ExtensionData.Summary.Host | ForEach-Object -Proce ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInte
    rop.GetVIView



  • 6.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 02:35 PM

    Are there any ESXi nodes connected to the VDS?



  • 7.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 02:36 PM

    Yes 11 ESXi nodes



  • 8.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 02:40 PM

    Can you check if the ESXi node MoRefs are in $vds.ExtensionData.Summary.Host?



  • 9.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 03:31 PM

    Sorry not 100% I got this right, but when I try and just use Get-View cmd this is what I get:

    PS C:\WINDOWS\system32> Get-View -Id $vds.ExtensionData.Summary.Host
    Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not
    null or empty, and then try the command again.
    At line:1 char:15
    + Get-View -Id $vds.ExtensionData.Summary.Host
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInte
    rop.GetVIView



  • 10.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 03:58 PM

    Try replacing $vds.ExtensionData.Summary.Host with $vds.ExtensionData.Summary.HostMember



  • 11.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 04:14 PM

    Well it didn't kick an error, just this output:


    VnicDevice ConsoleVnicDevice
    ---------- -----------------

     

     

     

     

     

    ----- yes including all these blank lines



  • 12.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 04:46 PM

    And are the pNICs connected to the LAG?



  • 13.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 04:47 PM

    Sorry, no when I checked it shows no phy adapters in the uplinks.



  • 14.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 05:50 PM

    Strange, seems to work for me.
    Which vSphere version?
    I'm on 7.



  • 15.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 06:05 PM

    I am on 7 as well, this is my full script for testing:

     


    $TargetvHostHostname = 'vhost06.domain'

    $TrafficPhy1 = 1
    $TrafficPhy2 = 4
    $TrafficPhy3 = 8

    ## Attach vHost to vDS
    Get-VDSwitch -Name $vDS | Add-VDSwitchVMHost -VMHost $TargetvHostHostname

    $Traffic1 = Get-VMHost $TargetvHostHostname | Get-VMHostNetworkAdapter -Physical -Name vmnic$TrafficPhy1
    $Traffic2 = Get-VMHost $TargetvHostHostname | Get-VMHostNetworkAdapter -Physical -Name vmnic$TrafficPhy2
    $Traffic3 = Get-VMHost $TargetvHostHostname | Get-VMHostNetworkAdapter -Physical -Name vmnic$TrafficPhy3


    #$vdsName = 'dvs -1'
    $vDS = 'RDC-Production-vDS'
    $lagName = 'TRAFFIC'

    $tgtDevs = $Traffic1, $Traffic2, $Traffic3

    $vds = Get-VDSwitch -Name $vDS

    $uplPg = Get-VDPortgroup -VDSwitch $vds -Name *Uplinks*

    Get-View -Id $vds.ExtensionData.Summary.HostMember | ForEach-Object -Process {
    $netSys = Get-View -Id $_.ConfigManager.NetworkSystem
    $lagPorts = (($netSys.NetworkInfo.ProxySwitch | where { $_.DvsUuid -eq $vds.Key }).HostLag |
    where { $_.LagName -eq $lagName }).UplinkPort.Key
    $i = 0

    $spec = New-Object VMware.Vim.HostNetworkConfig
    $proxy = New-Object VMware.Vim.HostProxySwitchConfig
    $proxy.ChangeOperation = [VMware.Vim.HostConfigChangeOperation]::edit
    $proxy.Uuid = $vds.Key
    $proxy.Spec = New-Object VMware.Vim.HostProxySwitchSpec
    $proxy.Spec.Backing = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicBacking

    ($netSys.NetworkInfo.ProxySwitch | where { $_.DvsUuid -eq $vds.Key }).Spec.Backing.PnicSpec |

    ForEach-Object -Process {
    if ($tgtDevs -contains $_.PnicDevice)
    {
    $pNicSpec = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec
    $pNicSpec.PnicDevice = $_.PnicDevice
    $pNicSpec.UplinkPortKey = $lagPorts[$i]
    $pNicSpec.UplinkPortgroupKey = $uplPg.Key
    $proxy.Spec.Backing.PnicSpec += $pNicSpec
    $i++
    }
    else
    {
    $proxy.Spec.Backing.PnicSpec += $_
    }
    }

    $spec.ProxySwitch += $proxy
    $netSys.UpdateNetworkConfig($spec, [VMware.Vim.HostConfigChangeMode]::modify)
    }



  • 16.  RE: Apply VMNICs to LAG Uplink
    Best Answer

    Posted Mar 31, 2021 07:51 PM

    Ok, I think I know what happened.
    1) The script assumes that the pNICs you want to move to the LAG group are already connected to the VDS in regular Uplinks

    2) There was a bug in the code, it should have said $tgtDevs.Name instead of $tgtDevs

    3) The output you saw is normal, that is what the call to UpdateNetworkConfig returns.

     



  • 17.  RE: Apply VMNICs to LAG Uplink

    Posted Mar 31, 2021 08:03 PM

    You are amazing good sir and I would love to buy you a beer at the next VMWorld that is in person.