I have been spending quite a bit of time in the lab lately working with some of our "future" software and one of the fun tasks I get to do is perform frequent rebuilds of my lab environment. Depending on the issues I encounter, I may even need to rebuild it on a daily basis and of course I have the majority of this automated so it is not as painful as it would be if I had to go through this manually.
The output of this build is a complete working vSphere environment that consists of several ESXi hosts connected to a vCenter Server with all the network and storage configured. On the networking front, the ESXi hosts were all running on a regular Virtual Standard Switch (VSS) and I needed to migrate them over to a Virtual Distributed Switch (VDS). In this particular environment, there is some Windows infrastructure and I thought about the different ways I could accomplish this and I remember hearing about some new VDS cmdlets that came out of PowerCLI 5.5. release.
Since I already had some scripts being kicked off on this Windows system, I thought I give the new PowerCLI cmdlets a try for VSS->VDS migration as I have heard good things about the new cmdlets. I performed my prototyping on a vSphere 5.5 environment, but I believe you might even be able to use this on older releases of vSphere.
Here is a list of the new VDS cmdlets that I used for the script:
Here are additional vSphere networking cmdlets that were required for script:
- Get-VMHostNetworkAdapter
- Set-VMHostNetworkAdapter
- Get-VirtualSwitch
- Get-VirtualPortGroup
- Remove-VirtualPortGroup
Even as a beginner of PowerCLI, I was able to quickly knock out a script that performed the migration from VSS to VDS and was able migrate ALL VMkernel interfaces and physical interfaces without any downtime. These new cmdlets definitely make it very easy for administrators to go from old Virtual Standard Switch over to the vSphere Distributed Switch.
Here is a overview of what my environment looks like which consists of three ESXi hosts with four physical NICs and three VMkernel interfaces.
The script below will create a brand new VDS and their associated Distributed Portgroups and attach a list of ESXi hosts which is configurable and performs the migration of VMkernel and physical interfaces. It does this by first moving two of the four physical NICs to the new VDS to ensure connectivity and then starts the migration of all VMkernel interfaces. Once that is complete, it will move the remainder physical NICs and then delete the Virtual Stand Switch portgroups.
Disclaimer: Please ensure you test this script in a development/test lab before using it in a production environment.
Connect-VIServer -Server vcenter55-1.primp-industries.com -User *protected email* -Pass vmware # ESXi hosts to migrate from VSS->VDS $vmhost_array = @("vesxi55-1.primp-industries.com", "vesxi55-2.primp-industries.com", "vesxi55-3.primp-industries.com") # Create VDS $vds_name = "VDS-01" Write-Host "`nCreating new VDS" $vds_name $vds = New-VDSwitch -Name $vds_name -Location (Get-Datacenter -Name "VSAN-Datacenter") # Create DVPortgroup Write-Host "Creating new Management DVPortgroup" New-VDPortgroup -Name "Management Network" -Vds $vds | Out-Null Write-Host "Creating new Storage DVPortgroup" New-VDPortgroup -Name "Storage Network" -Vds $vds | Out-Null Write-Host "Creating new vMotion DVPortgroup" New-VDPortgroup -Name "vMotion Network" -Vds $vds | Out-Null Write-Host "Creating new VM DVPortgroup`n" New-VDPortgroup -Name "VM Network" -Vds $vds | Out-Null foreach ($vmhost in $vmhost_array) { # Add ESXi host to VDS Write-Host "Adding" $vmhost "to" $vds_name $vds | Add-VDSwitchVMHost -VMHost $vmhost | Out-Null # Migrate pNIC to VDS (vmnic0/vmnic1) Write-Host "Adding vmnic0/vmnic1 to" $vds_name $vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic0 $vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false $vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic1 $vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false # Migrate VMkernel interfaces to VDS # Management # $mgmt_portgroup = "Management Network" Write-Host "Migrating" $mgmt_portgroup "to" $vds_name $dvportgroup = Get-VDPortgroup -name $mgmt_portgroup -VDSwitch $vds $vmk = Get-VMHostNetworkAdapter -Name vmk0 -VMHost $vmhost Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null # Storage # $storage_portgroup = "Storage Network" Write-Host "Migrating" $storage_portgroup "to" $vds_name $dvportgroup = Get-VDPortgroup -name $storage_portgroup -VDSwitch $vds $vmk = Get-VMHostNetworkAdapter -Name vmk1 -VMHost $vmhost Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null # vMotion # $vmotion_portgroup = "vMotion Network" Write-Host "Migrating" $vmotion_portgroup "to" $vds_name $dvportgroup = Get-VDPortgroup -name $vmotion_portgroup -VDSwitch $vds $vmk = Get-VMHostNetworkAdapter -Name vmk2 -VMHost $vmhost Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null # Migrate remainder pNIC to VDS (vmnic2/vmnic3) Write-Host "Adding vmnic2/vmnic3 to" $vds_name $vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic2 $vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false $vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic3 $vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false # Remove old vSwitch portgroups $vswitch = Get-VirtualSwitch -VMHost $vmhost -Name vSwitch0 Write-Host "Removing vSwitch portgroup" $mgmt_portgroup $mgmt_pg = Get-VirtualPortGroup -Name $mgmt_portgroup -VirtualSwitch $vswitch Remove-VirtualPortGroup -VirtualPortGroup $mgmt_pg -confirm:$false Write-Host "Removing vSwitch portgroup" $vmotion_portgroup $vmotion_pg = Get-VirtualPortGroup -Name $vmotion_portgroup -VirtualSwitch $vswitch Remove-VirtualPortGroup -VirtualPortGroup $vmotion_pg -confirm:$false Write-Host "Removing vSwitch portgroup" $storage_portgroup $storage_pg = Get-VirtualPortGroup -Name $storage_portgroup -VirtualSwitch $vswitch Remove-VirtualPortGroup -VirtualPortGroup $storage_pg -confirm:$false Write-Host "`n" } Disconnect-VIServer -Server $global:DefaultVIServers -Force -Confirm:$false
Here is a screenshot of running through the script:
If we now take a look at our enviornment, we can see all three ESXi hosts have been migrated over to the VDS.
UPDATE (11/4/13) - Thanks to one of the PowerCLI engineers, it looks like there is a PowerCLI cmdlet that can be used to migrate from VDS->VSS. I will be sharing that script in another blog post for those that may want to perform the reverse.
One caveat that I hit during the development of this script is needing the ability to easily migrate between VSS->VDS and VDS->VSS. I was hoping it was simply reversing the set of operations and moving the VMkernel interfaces back to the Virtual Standard Switch but what I found for the Set-VMHostNetworkAdapter cmdlet is that it only accepts a Distributed Virtual Portgroup. This meant that I could only migrate to a VDS but not to a VSS. Though this will probably will fit the majority of customer use cases, for me this was a problem and means I will need to dig into the vSphere APIs to be able to seamlessly perform a VDS->VSS migration. Given that PowerCLI is an abstraction, we should be able to easily add this feature and I will be filing an FR with Engineering to see if we can get this added as I think it would be a useful feature to have.