One of things I’ve been working on most recently is “nested vESX” – where you run ESX inside a VM running on physical ESX (pESX). There’s lots of reasons to do that – testing, VCP preparation, and not least testing scripts out in a sandbox before they get used in a production environment. Just a couple of days ago we released PowerCLI 5.1 Update2 which adds support for Distributed vSwitches, together with recognising the new functionality in vCloud Director 5.1.

Anyway, I thought I would make use of my vINCEPTION Lab to kick the tires on the command-lets (are you reading this Alan Renouf? 😉 ) and see what gives.

Before I embarked on that work I thought I should apply the latest updates to my ESX hosts. I’m currently running on build which I have as offline .ZIP update – so I uploaded this to the vESX local VMFS volume and applied it. Do this sort of “offline” without VMware VUM patching, you merely need the .ZIP VIB Bundle. I initially picked up this method from my colleague William Lam in his blogpost “A Pretty Cool Method of Upgrading to ESXi 5.1

esxcli software vib update –depot=/vmfs/volumes/esx01nj_local/ESXi510-201210001.zip

What’s new in PowerCLI for DvSwitches

Before I document how I created my DvSwitches lets just take a quick run through on what fun-ctionality is. Firstly there’s whole raft of command-lets that will help you create DvSwitches, add hosts, assign nics and create portgroups. If you using vSphere5.1 you can also export and import the DvSwitch functionality – that might be interesting way of creating a new environment – by capturing the DvSwitch configuration from lab environment for example, and pushing it into production.

Creating the DvSwitch…

Firstly I need to create a new datacenter and added my ESX hosts with:

$dc = “NJ Datacenter”

New-Datacenter -Location (Get-Folder -NoRecursion) -Name $dc

Add-VMHost -Name esx01nj.corp.com -Location $dc  -User root -Password Password1 -Force
Add-VMHost -Name esx01nj.corp.com -Location $dc  -User root -Password Password1 -Force
Add-VMHost -Name esx01nj.corp.com -Location $dc  -User root -Password Password1 -Force

Then I set about creating my first DvSwitch. Typically, in my vCloud Director labs I’ve created two DvSwitches – one used for “infrastructure” or management purposes, and then second DvSwitch for VMs/vApps that reside in my vCD environment. These are patched into different physical switches to ensure seperation for both security and making sure I don’t screw one or the other!

New-VDSwitch -Name “Infrastructure DvSwitch” -Location $dc -NumUplinkPorts 2
New-VDSwitch -Name “Virtual DataCenter DvSwitch” -Location $dc -NumUplinkPorts 2

Screen Shot 2013-02-13 at 18.18.16

This pretty much easy to follow I think. The “NumUpLinkPort” parameter allows me control the number of DvUpLinks have per DvSwitch normally set by the “Number of uplinks ports” parameter when you create a DvSwitch through the web-client:

Screen Shot 2013-02-13 at 18.20.27

For a full list of parameters have look at the web-based help for the command-let itself:
http://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/New-VDSwitch.html

Creating the DVPortgroups…

Next I needed to populate the DvSwitches with Portgroups – that’s pretty much standard fair using the New-VDPortgroup command-let using the “Get-VDSwitch” command-let to retrieve the name of the DvSwitch, and the New-VDPortgroup to create the portgroup itself.

$dvs01 = “Virtual DataCenter DvSwitch”

Get-VDSwitch -Name $dvs01 | New-VDPortgroup -Name “ExternalCorpNetwork” -VLanId 1
Get-VDSwitch -Name $dvs01 | New-VDPortgroup -Name “ExternalInternetNetwork” -VLanId 10

and then I did the same for the “Infrastructure DvSwitch” as well.

Screen Shot 2013-02-14 at 08.43.50

 

Adding the ESX hosts to the DvSwitch…

Now the DvSwitches were created I needed to add my ESX hosts into the DvSwitch itself using the Add-VDSwitchVMHost command-let like so:

$dvs01 = “Virtual DataCenter DvSwitch”
Add-VDSwitchVMHost -VDSwitch $dvs01 -VMHost “esx01nj.corp.com”, “esx02nj.corp.com”, “esx03nj.corp.com”

Screen Shot 2013-02-14 at 08.53.53

For a full list of parameters have look at the web-based help for the command-let itself:
http://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/Add-VDSwitchVMHost.html

 Adding the VMNICs to the DvSwitch…

My next step was allocating vmnics from each of my hosts into the DvSwitch itself using the Add-VDSwitchPhysicalNetworkAdapter command-let.

$dvs01 = “Virtual DataCenter DvSwitch”

$vmhostNetworkAdapter = Get-VMHost “esx01nj.corp.com” | Get-VMHostNetworkAdapter -Physical -Name vmnic1

Get-VDSwitch $dvs01 | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false

Note: I’m sure someone cleverer than I could make PowerCLI script that would retrieve all the hosts in vCenter, and then add vmnic1/2 into the DvSwitch.

Screen Shot 2013-02-14 at 09.26.44

http://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/Add-VDSwitchPhysicalNetworkAdapter.html