PowerCLI has a new object to interact with, thanks to NSX-T! The Opaque Network managed object gives us the ability to interact with NSX-T provisioned logical switches as though they are port groups. Technically, it has been available for a couple releases of vSphere but the functionality was really improved here recently.
Last year we released KB 65149 that included code to create a new function, named Set-NetworkAdapterOpaqueNetwork. This function could be used to assign an opaque network to a VM’s network adapter. I’m happy to relay that, as of PowerCLI 11.2.0, we no longer have to rely on that function. We can now use the Set-NetworkAdapater to assign an opaque network just as we would any other normal port group with the NetworkName parameter. We also have the ability to deploy OVAs and/or OVFs with an opaque network configured in the OVFConfiguration parameter.
Before we dive into some coding examples, we should begin by showing how to list out the available opaque networks. This is because opaque networks aren’t included as part of the response for either Get-VirtualPortGroup or Get-VDPortGroup. Each of those cmdlets return their own object types. Therefore, we need to rely on the Get-View cmdlet to interact directly with the vSphere Web Services API.
Retrieving Opaque Networks
We can list all of our vCenter’s opaque networks with the following command:
Get-View -ViewType OpaqueNetwork
Since we’re interacting directly with the API, we’re going to receive back all of the top-level information about each opaque network. We can condense the output and make it a little easier to read with the following code:
Get-View -ViewType OpaqueNetwork | Select-Object Name,OverallStatus
Configuring Opaque Networks
We now have a list of opaque networks which are available for us to use. The next step is to start configuring our VMs to use them. As of PowerCLI 11.2.0, we can use the already existing Set-NetworkAdapter cmdlet combined with the NetworkName parameter to make the change.
We can update a VM’s port group association to be an opaque network with the following code:
Get-VM -Name “VMName” | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName “OpaqueNetworkName”
NSX-T adds a new object for PowerCLI to interact with in the form of an opaque network. These are a representation, at the vSphere level, of a logical switch which has been provisioned from NSX-T. PowerCLI 11.2.0 includes updates to existing cmdlets that allow us to assign opaque networks to our VMs as port groups. The first, which was demonstrated in this post, is to modify a VM’s network adapter with the Set-NetworkAdapter cmdlet paired with the NetworkName parameter. The second, while deploying OVAs and/or OVFs through Import-VApp when using the OvfConfiguration parameter.
Update today to the latest version of PowerCLI to ensure you have access to the latest features and functionalities.