Automate Migrating ESX Host Interfaces to Nexus 1000V

“We’ve tried, it can’t be automated!” I’ve heard this more times than I can keep track of and if you read my previous blog you will know that I just do not agree. I have written about automation with Linux utilities, UCS PowerTool, AutoHotKey, Excel, etc… 99.999% of operations can be automated. So when a customer tells me that something cannot be automated I usually respond with “Have you tried …?”

Here is the scenario; the customer has an automated build process for ESX hosts. At the point where the host is ready to be connected to the Nexus 1000V the process becomes manual. The customer would like to use VMWare PowerCLI to migrate the host interface but the Cmdlet to retrieve Distributed Virtual Switches, Get-VirtualSwitch, just returns the DVS objects, there isn’t a Cmdlet to migrate the ESX vmnic interface.

Hold on a second, I know that VCenter knows about the Nexus 1000V because I see it in the interface. I know that VCenter can manipulate the Nexus 1000V because VCenter is where interface migration is done. I am fairly certain at this point that ESX interface migration from the VCenter vSwitch to the Nexus 1000V can be automated. But what to use to do it, there is no PowerCLI command like Set-ESXHostInterfaceToN1kv. This is typically where automation ends for many, sometimes you have to dive deep into the objects that the system manages and figure out what to do. Sometimes someone has already done a deep dive into something like what you are trying to do and maybe you can build off of their work.
In this instance I used the work shown here, http://www.lucd.info/2009/10/09/dvswitch-scripting-part-1-creation, it’s a blog about migrating from the VMWare vswitch to the VMWare Distributed Virtual Switch. I thought as I read it, that there could be something here that I can work with. I poked around a bit and tested some ideas and this is what I came up with, Set-EsxVmNic.ps1

Additionally, depending upon your environment and other PowerCLI cmdlets you are running within your script, for example Invoke-VMScript you may need to make sure the script is running in 32 bit mode. If that is the case add this code to your script to relaunch in 32 bit environment.

Line 48 Get the Nexus 1000V Object for the 1000V that the ESX host vmnic is going to be migrated to.

Line 51 Get the ESX host object for the host whose vmnic is going to be migrated to the Nexus 1000V.

Line 54 Create a DVS configuration specification object.

Lines 57-58 Create a DVS Host member configuration specification and set the operation to add.

Line 61 Create a Pnic Backing object and add the to the member host configuration object.

Lines 64-66 Get the object that represents the vmnic in the ESX host and add that as a Pnic object to the Pnic Backing object. At this point there is an object for the Host that contains an object for the Pnic Backing that contains an object for the Pnic specification that has a member that specifies the Pnic itself, got it?

Line 69 Set the target host’s host member to the object reference from the ESX host object retrieved at line 51.

Line 72 Set the DVS configuration specification object host member to the target host object.

Lines 75-77 Get the current state of the Nexus 1000V and set the DVS configuration specification version to that configuration Version of the Nexus 1000V.

Line 80 Reconfigure the Nexus 1000V with the DVS configuration specification object that has been created. The task reference that is returned can be used to monitor the status of the task, refer to lucd’s blog for that bit of code.

Line 82 Disconnect from vCenter.

I should give a reference to the code formatter I used for this blog entry, it is the Source Code Beautifier at http://hilite.me/

4 Comments.

how about the function listed here..
http://www.lucd.info/2009/10/09/dvswitch-scripting-part-1-creation/
function Add-dvSwHost
This will add the host to the Nexus 1000V but you are unable to specify an uplink for your pnic to use. Anyway to add this in?

The DistributedVirtualSwitchHostMemberPnicSpec object allows for the attributes
UplinkPortgroupKey
UplinkPortKey
So you should be able to select the UplinkPortgroup perhaps even the specific port within that group, if it makes sense to do that. However I have not tried this but will update my lab and give it a shot and comment with my results.
The object reference is located here, http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.dvs.HostMember.PnicSpec.html
I would recommend reading all of lucd's blogs, http://www.lucd.info/ there is in depth information in them on networking and adpaters as well as other things.
Regards,
John

Thanks, John.
Yes, I have read through all of LucD's logs on dVs scripting. However, there is currently nothing that supports adding a Nexus 1000V with a specific uplink name.
Hopefully you are able to do so in your lab tests.
Thanks,
JD

Some of the individuals posting to this site, including the moderators, work for Cisco Systems. Opinions expressed here and in any corresponding comments are the personal opinions of the original authors, not of Cisco. The content is provided for informational purposes only and is not meant to be an endorsement or representation by Cisco or any other party. This site is available to the public. No information you consider confidential should be posted to this site. By posting you agree to be solely responsible for the content of all information you contribute, link to, or otherwise upload to the Website and release Cisco from any liability related to your use of the Website. You also grant to Cisco a worldwide, perpetual, irrevocable, royalty-free and fully-paid, transferable (including rights to sublicense) right to exercise all copyright, publicity, and moral rights with respect to any original content you provide. The comments are moderated. Comments will appear as soon as they are approved by the moderator.