VMware Cloud Community
nmbgdc
Enthusiast
Enthusiast
Jump to solution

How to Add host in LAG or

Hi Team,

I am trying to find the powercli script but not getting,

So here is my scenario,

1- Host has two physical nics vmnic-0 and vmnic1

2- Host are already part of the dvs behind multiple port group  with uplink1- vmnic0 and uplink2-vmnic1.

Now we have configure LACP & created LAG1 & LAG2, and after this steps just wanted to connect the host in LAGs, existing one and will connect new host also, does anyone has any powercli script which can does the job?

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vdsName = 'dvs-1'

$lagName = 'mgmt-lag'

$tgtDevs = 'vmnic0', 'vmnic1'


$vds = Get-VDSwitch -Name $vdsName

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

Get-View -Id  $vds.ExtensionData.Summary.Host |

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)

}


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

View solution in original post

Reply
0 Kudos
12 Replies
a_p_
Leadership
Leadership
Jump to solution

Discussion moved from Forums to VMware PowerCLI

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not sure exactly what you mean by "connect the host".
Do you mean the Migrating network traffic to LAGs option in the Web Client?


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

ok so let elaborate you,

basically I want to add host in vds but now vds is configured with lag Instid of uplink.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you share a screenshot of the topology of the VDS?


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Here is my VDS topology,

If you see right now all host nic are behind the uplink1 & Uplink2

pastedImage_1.png

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vdsName = 'dvs-1'

$lagName = 'mgmt-lag'

$tgtDevs = 'vmnic0', 'vmnic1'


$vds = Get-VDSwitch -Name $vdsName

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

Get-View -Id  $vds.ExtensionData.Summary.Host |

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)

}


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Thanks LucD its works for all host.

but want specific host only to move behind the lag so how can we configure using the script?

Thanks

Bharat

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try replacing

Get-View -Id  $vds.ExtensionData.Summary.Host |

with

Get-View -Id  $vds.ExtensionData.Summary.Host |

where{$_.Name -eq 'MyHost'} |


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Thanks you Luc it works,

I have multiple Nics on my server hence can move nics based on mac address.

Thanks

Bharat

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

I am trying this script on the  on vcenter version VMware ESXi 6.7.0 ( VMKernal Release Build 15160138)  but its not working any clue where i have tried this on below vcenter  version works .

nmbgdc_0-1616795513485.jpeg

 

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Really?!?
21 months after I provided you with a working script and where you never bothered to mark it as the correct solution.
Don't think so


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

Reply
0 Kudos
NischithHPE
Contributor
Contributor
Jump to solution

Thanks

Reply
0 Kudos