VMware Cloud Community
cliffcahill
Enthusiast
Enthusiast
Jump to solution

vMotion TCP/IP Stack- Created by Powercli

Hi all,

Has anyone successfully automated the creation of the vMotion TCP/IP Stack on each host and then the creation of the vMotion VMK utilizing the newly created stack.

Regards

Cliff

1 Solution

Accepted Solutions
cliffcahill
Enthusiast
Enthusiast
Jump to solution

Its been a  while but here is some updates to the syntax that is working for me .

write-host -ForeGroundColor green "Setting Up Network on Host1"

$esxcli = Get-EsxCli -VMHost Host1

write-host -ForeGroundColor green "Adding portgroup Esx-l3vmotion to vSwitch0"

$esxcli.network.vswitch.standard.portgroup.add("Esx-l3vmotion", "vSwitch0")

write-host -ForeGroundColor green "Setting Portgroup Esx-l3vmotion to vSwitch0"

$esxcli.network.vswitch.standard.portgroup.set("Esx-l3vmotion", "117")

write-host -ForeGroundColor green "Adding vmotion stack to portgroup"

$esxcli.network.ip.netstack.add($false, "vmotion")

write-host -ForeGroundColor blue "Creating Esx-l3vmotion VMKernal on vSwitch0 with VMK Number vmk2"

$esxcli.network.ip.interface.add($null, $null, "vmk2", $null, "1500", "vmotion", "Esx-l3vmotion")

write-host -ForeGroundColor yellow "Assigning 10.10.117.10 to Esx-l3vmotion on vSwitch0"

$esxcli.network.ip.interface.ipv4.set("vmk2", "10.10.117.10","255.255.255.0", $null, "static")

View solution in original post

0 Kudos
16 Replies
tjurgens
Enthusiast
Enthusiast
Jump to solution

You'd be looking for the New-VirtualSwitch and the New-VMHostNetworkAdapter/Set-VMHostNetworkAdapter cmdlets if you are looking to do this on a standard switch.

I'd suggest starting your reading with those - I found the examples quite informative.  Give that a try and report back if you run into problems - remember to post what commands you've tried.

0 Kudos
cliffcahill
Enthusiast
Enthusiast
Jump to solution

Hi tjurgens

Thanks for the reply - I have no issue creating vMotion on the any vSphere version that is Pre 6.0.

Issue only arises when i need to create and new TCP/IP stack and assign that stack to the vMotion VMK - This is to allow for L3 vMotion

Attached is sample of what i used to create vMotion VMk currently on anything pre vSphere6.0

##########################################################

# Add vMotion VMkernel port for all servers in a cluster

#

##########################################################

#

# VERSION - 1.2

#

param(  

  [Parameter(Mandatory=$true)]$vcenter,

  $Subnet = "255.255.255.0",

  $vMotionVLAN = "25",

  $vMotionName = "Vmotion",

  $vmotion_ip_start = "192.168.25.100",

  $VMhost ="*",

  $clusterName = '*'

)

##########################################################   

$server = connect-viserver $vcenter

# Start Creating vMotion Network #############################

$vmotion_ip_start_int=$vmotion_ip_start.split('.')

$vmotion_ip_start_int=[int]$vmotion_ip_start_int[3]

Write-Host -ForegroundColor Yellow "Start Creating vMotion Network".ToUpper()

ForEach ($VMhostname in ($cluster | Get-VMHost -name $VMhost)| sort)

{

  if ($VMhostname | Get-VMHostNetworkAdapter -VMKernel | where {$_.PortGroupName -match $vMotionName}) {

  Write-host -ForegroundColor yellow "WARNING : $VMhostname already has a VMkernel port named $vMotionName - Skipping"

  }

  else {

  write-host -ForegroundColor green "Creating vMotion port group for $VMhostname"

  $netIP = $vmotion_ip_start.split('.')

  $IP = $netIP[0] + '.' + $netIP[1] + '.' + $netIP[2] + '.' + $vmotion_ip_start_int

  $null = New-VMHostNetworkAdapter -VMHost $VMhostname -PortGroup $vMotionName -VirtualSwitch $(Get-VirtualSwitch -VMHost $VMhostname) -IP $IP -SubnetMask $Subnet -VMotionEnabled $true

  $null = Get-VirtualPortGroup -Name $vMotionName -VMHost $VMhostname | Set-VirtualPortGroup -VLanId $vMotionVLAN

  $vmotion_ip_start_int = $vmotion_ip_start_int +1

  }

  }

  Write-Host -ForegroundColor Green "End Creating vMotion Network".ToUpper()

 

# End Creating vMotion Network ###############################

0 Kudos
tjurgens
Enthusiast
Enthusiast
Jump to solution

Hi cliffcahill‌, I don't see any flaws in your script, but I do not have any ESXi 6/vCenter 6 environments to test on.  Do you get any errors?

0 Kudos
cliffcahill
Enthusiast
Enthusiast
Jump to solution

Script works fine one vSphere 6.0 aswell - I'm looking to update it in order to do all the new vMotion L3 Enhancements that were released in vSphere6.0

0 Kudos
vbrad6841
Enthusiast
Enthusiast
Jump to solution

Have you updated your PowerCLI to the latest version?

VMware vSphere PowerCLI 6.0 Release 2 Release Notes

Blog: https://lowercasevblog.wordpress.com/
0 Kudos
cliffcahill
Enthusiast
Enthusiast
Jump to solution

Yep i had a look through the release notes . No New relevant cmdlets unfortunately . I might have a look to complete it by using the ESXCLI in host install KS script 😕

0 Kudos
vbrad6841
Enthusiast
Enthusiast
Jump to solution

The last I looked at this from a CLI perspective it was still only supported via the vSphere web interface.

Blog: https://lowercasevblog.wordpress.com/
0 Kudos
inok
Contributor
Contributor
Jump to solution

I also can not find parameters on PowerCli commandlets for host network config to support this new features, but I successfully did this task with get-esxcli:

$vmhost = Get-VMHost <hostname>

$esxcli= Get-EsxCli -VMHost $vmhost

#adding new portgroup for vmkernel traffic

$vmhost | Get-VirtualSwitch -Name "vSwitch0" | New-VirtualPortGroup "vmk_vmotion1" -VLanId <VLAN>

#adding new network stack

$esxcli.network.ip.netstack.add($false, "vmotion")

#adding new vmkernel interface to new stack

$esxcli.network.ip.interface.add($null, $null, "vmk1", $null, $null, "vmotion", "vmk_vmotion1")

#configuring vmk1 to use dhcp

$esxcli.network.ip.interface.ipv4.set("vmk1", $null, $null, $null, "dhcp")

Also you can archive same result using esxcli directly on the ESXi:

esxcli network ip netstack add -N vmotion

esxcli network vswitch standard portgroup add -p vmk_vmotion1 -v vSwitch0

esxcli network vswitch standard portgroup set -p vmk_vmotion1 -v <VLAN>

esxcli network ip interface add -i vmk1 -N vmotion -p vmk_vmotion1

esxcli network ip interface ipv4 set -i vmk1 -t dhcp

0 Kudos
ccalvetTCC
Enthusiast
Enthusiast
Jump to solution

Get-esxcli is a good option.

However it is also possible to use directly the API via PowerCLI.

To associate a new VMkernel interface to the default VMotion stack

The HostNetworkSystem has a method AddVirtualNic

This AddVirtualNic needs a HostVirtualNicSpec as a parameter.
The HostVirtualNicSpec has a property netStackInstanceKey

You can use there "vmotion" instead of "defaultTcpipStack"

It should also be possible to modify or add a new network stack.

The HostNetworkSystem has a method UpdateNetworkConfig

It needs as a parameter HostNetworkConfig

This object has a property netStackSpec of type HostNetworkConfigNetStackSpec

And in it netStackInstance of type HostNetStackInstance

Blog: http://thecrazyconsultant.com/ | Twitter: @ccalvetTCC
0 Kudos
MPaeth
VMware Employee
VMware Employee
Jump to solution

Hi,

maybe you are still working on this topic. So

I have created a short script which creates a vmkernel port with vmotion stack.

$vmHost = Get-VMHost -Name "esxName"

$portgoup = Get-VirtualPortGroup -Name "Management"

$nic = New-Object VMware.Vim.HostVirtualNicSpec

$distributedVirtualPort = New-Object VMware.Vim.DistributedVirtualSwitchPortConnection

$nic.distributedVirtualPort = $distributedVirtualPort

$nic.distributedVirtualPort.portgroupKey = $portgoup.key

$nic.distributedVirtualPort.switchUuid = $portgoup.VirtualSwitch.key

$nic.netStackInstanceKey = 'vmotion'

$ip = New-Object VMware.Vim.HostIpConfig

$ip.subnetMask = '255.255.255.0'

$ip.ipAddress = '192.168.0..10

$ip.dhcp = $false

$ip.ipV6Config = New-Object VMware.Vim.HostIpConfigIpV6AddressConfiguration

$ip.ipV6Config.dhcpV6Enabled = $false

$ip.ipV6Config.autoConfigurationEnabled = $false

$ip.IpV6Config = $ipV6Config

$nic.Ip = $ip

$networkSystem = $vmHost.ExtensionData.configManager.NetworkSystem

$_this = Get-view -Id ($networkSystem.Type + "-" + $networkSystem.Value)

$_this.AddVirtualNic('', $nic)

You can find the related documentation here:

vSphere 6.0 Documentation Center

0 Kudos
cliffcahill
Enthusiast
Enthusiast
Jump to solution

Let Me test this and ill get back to you .

0 Kudos
JasonOgle
Contributor
Contributor
Jump to solution

The solution provided by inok works great for standard vSwitches and port groups! Thank you!

0 Kudos
JasonOgle
Contributor
Contributor
Jump to solution

The solution provided by MPaeth works great for distributed vSwitches and port groups! Thank you!

0 Kudos
adamjg
Hot Shot
Hot Shot
Jump to solution

I also can not find parameters on PowerCli commandlets for host network config to support this new features, but I successfully did this task with get-esxcli:

$vmhost = Get-VMHost <hostname>

$esxcli= Get-EsxCli -VMHost $vmhost

#adding new portgroup for vmkernel traffic

$vmhost | Get-VirtualSwitch -Name "vSwitch0" | New-VirtualPortGroup "vmk_vmotion1" -VLanId <VLAN>

#adding new network stack

$esxcli.network.ip.netstack.add($false, "vmotion")

#adding new vmkernel interface to new stack

$esxcli.network.ip.interface.add($null, $null, "vmk1", $null, $null, "vmotion", "vmk_vmotion1")

#configuring vmk1 to use dhcp

$esxcli.network.ip.interface.ipv4.set("vmk1", $null, $null, $null, "dhcp")

Also you can archive same result using esxcli directly on the ESXi:

esxcli network ip netstack add -N vmotion

esxcli network vswitch standard portgroup add -p vmk_vmotion1 -v vSwitch0

esxcli network vswitch standard portgroup set -p vmk_vmotion1 -v <VLAN>

esxcli network ip interface add -i vmk1 -N vmotion -p vmk_vmotion1

esxcli network ip interface ipv4 set -i vmk1 -t dhcp

Ok so this creates a new Custom TCP/IP stack.  Do you know how to get this to work using the existing vMotion stack listed under System stacks?

Edit: configuring this on vSwitch0 and not a distributed switch.

0 Kudos
cliffcahill
Enthusiast
Enthusiast
Jump to solution

Its been a  while but here is some updates to the syntax that is working for me .

write-host -ForeGroundColor green "Setting Up Network on Host1"

$esxcli = Get-EsxCli -VMHost Host1

write-host -ForeGroundColor green "Adding portgroup Esx-l3vmotion to vSwitch0"

$esxcli.network.vswitch.standard.portgroup.add("Esx-l3vmotion", "vSwitch0")

write-host -ForeGroundColor green "Setting Portgroup Esx-l3vmotion to vSwitch0"

$esxcli.network.vswitch.standard.portgroup.set("Esx-l3vmotion", "117")

write-host -ForeGroundColor green "Adding vmotion stack to portgroup"

$esxcli.network.ip.netstack.add($false, "vmotion")

write-host -ForeGroundColor blue "Creating Esx-l3vmotion VMKernal on vSwitch0 with VMK Number vmk2"

$esxcli.network.ip.interface.add($null, $null, "vmk2", $null, "1500", "vmotion", "Esx-l3vmotion")

write-host -ForeGroundColor yellow "Assigning 10.10.117.10 to Esx-l3vmotion on vSwitch0"

$esxcli.network.ip.interface.ipv4.set("vmk2", "10.10.117.10","255.255.255.0", $null, "static")

0 Kudos
alpatio
Contributor
Contributor
Jump to solution

HI,

This code works, but the vmotion portgroup is created on a local Switch, how can it be created into a Distributed Switch (vDS)?

I've tried to use similar powercli sintax, searching into esxcli commands to use a DsWitch, without success.  Any suggestion?

Best Regards

0 Kudos