Another post coming from our Dutch VMUG Event 2011 presentation. On position number 10, we find the vMotion Enhancements that were introduced with vSphere 5.
A single vMotion can now scale over multiple NICs. This feature can use a regular vSwitch or distributed vSwitch.On YouTube there are 2 videos, uploaded by VMwareKB, that show how to configure such a vMotion enabled multi-NIC vSwitch, regular and distributed.
Very useful videos, but as you can imagine, I wanted to automate this. No GUI clicking for me 😉
The script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
function Set-vMotionMultiNic{ <# .SYNOPSIS Configure multi-NIC vMotion .DESCRIPTION The function will configure multi-NIC vMotion enabled portgroups on a regular vSwitch .NOTES Author: Luc Dekens .PARAMETER VMHost The ESXi host where the vMotion enabled portgroups shall be configured. The parameter accepts a string or the object returned by the Get-VMHost cmdlet. .PARAMETER VirtualSwitch The virtual switch on which the vMotion enabled portgroups shall be configured. The parameter accepts a string or the object returned by the Get-VirtualSwitch cmdlet. .PARAMETER pNic An array with the vnics that shall be used to configure the portgroups. Depending on the number of provided vnics, the function will create the optimal number of portgroups. The arrays on pNic, IPaddress and SubnetMask shall have the same number of elements. .PARAMETER IpAddress An array with the IP addresses that shall be used on the portgroups .PARAMETER SubnetMask An array with the subnetmasks. .EXAMPLE PS> Set-vMotionMultiNic -VMHost MyESX -VSwitch MyvSw ` PS>> -pNic "vmnic2","vmnic3","vmnic4" ` PS>> -IpAddress "192.168.1.1","192.168.1.2","192.168.1.3" ` PS>> -SubnetMask (,"255.255.255.0" * 3) #> param( [psobject]$VMHost, [psobject]$VirtualSwitch, [string[]]$pNic, [string[]]$IpAddress, [string[]]$SubnetMask )56 if($VMHost.getType().Name -eq "string"){ $VMHost = Get-VMHost -Name $VMHost } if($VMHost.ApiVersion.Split('.')[0] -lt 5){ Write-Warning "MultiNic for vMotion requires at least ESXi 5.0" exit } if($VirtualSwitch.getType().Name -eq "string"){ $VirtualSwitch = $VMHost | Get-VirtualSwitch -Name $VirtualSwitch } $indices = 0..($pNic.Count - 1) foreach($i in $indices){ $pg = New-VirtualPortGroup -Name ("vMotion-{0:d2}" -f ($i + 1)) -VirtualSwitch $VirtualSwitch New-VMHostNetworkAdapter -VMHost $VMHost -VirtualSwitch $VirtualSwitch -PortGroup $pg -IP $IpAddress[$i] -SubnetMask $SubnetMask[$i] -VMotionEnabled:$true | Out-Null Get-NicTeamingPolicy -VirtualPortGroup $pg | Set-NicTeamingPolicy -MakeNicActive $pNic[$i] -MakeNicStandby $pNic[($indices | where {$_ -ne $i})] |Out-Null } } |
Annotations
Line 42-44: A simple Object By Name (OBN) implementation for the ESXi host
Line 45-48: A check if we are configuring this for at least a vSphere 5 server
Line 50-52: A simple Object By Name (OBN) implementation for the regular vSwitch
Line 53: When the function is called with ‘n’ vnics, it will have to create ‘n’ portgroups. This calculation creates the list of suffixes that will be used on the portgroup names.
Line 55: The creation of the portgroup. Note how the function adds a 2 digit suffix with the -format operator to the basename (‘vMotion’)
Line 56: Set the IP address and subnetmask
Line 57-58: The Teaming is configured in the same way the VMwareKB video demonstrates.
Sample use
To demonstrate the function, I will use a simple configuration. We have 1 regular vSwitch that has 3 vnics connected to it.
We call the function
1 2 3 4 5 |
$IP = "192.168.0.210","192.168.0.211","192.168.0.212" $MASK = "255.255.255.0","255.255.255.0","255.255.255.0" $NIC = "vmnic1","vmnic2","vmnic3" Set-vMotionMultiNic -VMHost 192.168.0.107 -VirtualSwitch vSwitch1 -pNic $NIC -IPAddress $IP -SubnetMask $MASK |
The function creates the vMotion portgroups (in the same way as the VMwareKB video shows).
And each of these vMotion enabled portgroups is configured similar to the method shown in the video.
In a following post I will show how this can be done for a dvSwitch.
Enjoy !