Thursday, November 10, 2022

PowerVMDSC - Intro and Overview

Background 

For the blog announcing the VMDSC Fling and more information on the intent you can check here:

https://octo.vmware.com/introducing-virtual-machine-desired-state-configuration/

The fling itself and documentation can be downloaded here :

https://flings.vmware.com/virtual-machine-desired-state-configuration

The elevator pitch is that VMDSC is a fling that allows you to set a desired configuration state (CPU, Memory, Cores-per-socket) and then have that state automatically realized at a future time when the virtual machine is rebooted, say for patching. So I as an infrastructure administrator can see that a VM is oversized, set a smaller future state, and then at some time in the future when the app owner reboots their VM for whatever reason that new CPU/Memory configuration is applied. The key use cases are rightsizing and NUMA alignment. 

PowerVMDSC

So what is PowerVMDSC? The only way to interact with VMDSC directly is via its API. When we were developing it and testing we primarily used PostMan to drive the API. Then Steve wrote a little vRO integration to pull recommendations from vROPs into VMDSC. I've been using PowerCLI for forever to interact with vSphere, so I decided go ahead and write a PowerShell module to interact with the VMDSC API. I ended up writing most of it in one night on Halloween 2021 while answering the door for trick or treaters. It was updated this spring to support the updated VMDSC API adding the cores per socket desired state. 

You can check out the PowerVMDSC module code on my Github : 
https://github.com/HeathReynolds/PowerVMDSC

How do I install PowerVMDSC?

The easiest way to install PowerVMDSC is by simply installing it from the PowerShell Gallery via the Install-Module cmdlet. Like this :  

Install-Module -Name PowerVMDSC

PowerVMDSC has been tested with both PowerShell and PowerShell Core (on Windows and Linux). The main caveat to the installation is that PowerShell uses the TLS versions of the host OS. So the host OS needs to support TLS versions that can negotiate a connection with the VMDSC appliance API. The appliance supports the following versions. 

Preferred TLSv1.3 128 bits TLS_AES_128_GCM_SHA256 Curve 25519 DHE 253

Accepted TLSv1.3 256 bits TLS_CHACHA20_POLY1305_SHA256 Curve 25519 DHE 253

Accepted TLSv1.3 256 bits TLS_AES_256_GCM_SHA384 Curve 25519 DHE 253

Preferred TLSv1.2 128 bits ECDHE-RSA-AES128-GCM-SHA256 Curve 25519 DHE 253

Accepted TLSv1.2 256 bits ECDHE-RSA-AES256-GCM-SHA384 Curve 25519 DHE 253

The main issue caused by this is that some older operating systems won't work because they don't support any of the TLS secure ciphers supported by the appliance. I tested Windows 2012R2 and it didn't work, but both Windows 2016 and Windows 2019 worked fine. 

How do I use PowerVMDSC?

Use is pretty straightforward if you have any experience with PowerShell and PowerCLI. Like almost all VMware PowerShell modules the first step is to connect to the appliance. The Connect-VMDSC cmdlet will connect to the appliance and cache and authentication token to be used on subsequent commands.

Connect-VMDSC -vmdsc vmdsc.sfo.rainpole.io -vcenter

Once you have an authentication token you can use the PowerVMDSC cmdlets to add new configurations, update existing pending configurations, list pending configurations, and clear pending configurations. You should note that VMs are referenced by their UUID, but all VMDSC cmdlets accept VM UUID as a pipeline input. 

Here are a couple of examples of getting the UUID of a VM and passing it to a PowerVMDSC cmdlet :

PS C:\> Get-VM VMName | %{(Get-View $_.Id).config.uuid} | Clear-VMDSC PS 
C:\> Get-VM VMName | %{(Get-View $_.Id).config.uuid} | Add-VMDSC -mem 4096

Here is an example of setting a pending configuration using the Add-VMDSC cmdlet : 

PS C:\> Add-vmdsc -uuid 420377f7-bceb-d929-912b-6706e5debc71n -cpu 2 -mem 4096 -corespersocket 1 

All of the cmdlets are documented with examples in the PDF documentation downloadable from the VMware Flings site. I'll follow up on this overview with a couple of advanced use cases for PowerVMDSC like exporting all configurations and importing them into a new appliance.