In today’s fast-paced environments, automation is king of the hill. In fact in most operations environments in many businesses, it is simply not possible to do things the way they used to be done. Many if not most of today’s VMware vSphere administrators are making use of PowerCLI to be able to manage, monitor, and automate various processes inside the VMware vSphere environment. PowerCLI is the official PowerShell module for VMware vSphere environemnts that allows interacting with vSphere by way of PowerCLI code. With the release of VMware vSphere 6.7 Update 2, one of the exciting new official components of the new VCSA appliance and the vSphere Client is the new Developer Center that contains various features that allow vSphere administrators to automate various vSphere processes and functionality by way of API calls or PowerCLI code. In this post, we will look at the New VMware vSphere 6.7 Update 2 Client Developer Center API Explorer and Code Capture. Let’s take a look at this powerful new addition to the HTML 5 web interface vSphere Client.
From Fling to vSphere Client in vSphere 6.7 Update 2
The new Developer Center Code Capture started out as a VMware Fling that was received very well in the community as many saw the potential of this great utility integrated with vSphere Client. This is all part of the new Developer Center that is found in vCenter Server 6.7 Update 2. Developer Center will no doubt continue to get new features and additional nuggets of usefulness for automation in the vSphere environment. The Code Capture feature is a great start here for developers in that it allows visibility into the actions that are running under the hood when various actions are taken within vSphere. Simple tasks all the way up to more complicated tasks can be analyzed with the code capture to allow reusing the actions via PowerCLI code.
Code capture allows you to record your actions in the vSphere Client delivering simple, usable code output. This allows seeing how the UI is doing things under the covers. The great part of the Code Capture feature is it is simple. There is a simple “Record” button that is enabled in the vSphere Client that allows recording the actions and then seeing what the output looks like from a code standpoint.
Next, is the API Explorer. RESTful APIs are all the rage today allowing Infrastructure as Code to be a reality by interacting with infrastructure via these API endpoints. This allows provisioning, management, troubleshooting, deprovisioning, and automation all from the constructs of code targetting RESTful APIs. Since the release of VMware vSphere 6.5, VMware has had the API Explorer found at the URL https://<yourVCSA-FQDN>/apiexplorer. However, with this release, the API Explorer has been brought “inside” the vSphere Client which alleviates the extra authentication you had to do with the older mechanism via the standalone URL.
A great feature of the API Explorer in the vSphere Client is the ability to search for APIs containing a specific keyword. This makes for an easy way to query and return the APIs to interact with one in particular.
Using VMware vSphere Client Developer Center API Explorer and Code Capture?
To get to the new Developer Center in the vSphere Client in vSphere 6.7 Update 2, you can simply navigate tot he Menu button next to the vSphere Client logo in the upper left hand corner. Click the Development Center option in the menu.
Let’s go through the tabs here. The first tab is simply an overview. No doubt more will be added here in future versions.
The API Explorer is a great little utility that exposes the vCenter Server APIs for not only seeing what is available, but actually making real changes. A note of caution here. The changes made in the API Explorer are made LIVE so you can potentially do something bad here if not careful.
Using the API Explorer, I have navigated to query something simple like NTP. Here you can perform the GETaction. Click the Execute button to actually perform the query of the API.
On the third tab, the Code Capture functionality allows flagging on the toggle for Enable Code Capture.
After you have toggled on Code Capture, you will have a red “Record button” appear next to the logged in user as displayed in the top right. You can press this like a start/stop button. You can also click the Start Recording link under the Code Capture dashboard here.
Below, I have pressed the code capture and let it record as I stepped through the New VM wizard in the vSphere Client. Note you can either Copy the results or Download them after it is finished. When you click download, it actually downloads as a .PS1 file.
Below is the result of the output from creating a new VMware vSphere virtual machine by simply following the wizard in the vSphere Client.
#----------------- Start of code capture -----------------
#---------------QueryOptions---------------
$name = 'VirtualCenter.InstanceName'
$_this = Get-View -Id 'OptionManager-VpxSettings'
$_this.QueryOptions($name)
#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)
#---------------QueryConfigOptionDescriptor---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-7'
$_this.QueryConfigOptionDescriptor()
#---------------QueryConfigOption---------------
$key = 'vmx-14'
$hostParam = New-Object VMware.Vim.ManagedObjectReference
$hostParam.Type = 'HostSystem'
$hostParam.Value = 'host-12'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-7'
$_this.QueryConfigOption($key, $hostParam)
#---------------QueryConfigOptionEx---------------
$spec = New-Object
VMware.Vim.EnvironmentBrowserConfigOptionQuerySpec
$spec.Host = New-Object VMware.Vim.ManagedObjectReference
$spec.Host.Type = 'HostSystem'
$spec.Host.Value = 'host-12'
$spec.GuestId = New-Object String[] (1)
$spec.GuestId[0] = 'windows8Server64Guest'
$spec.Key = 'vmx-14'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-7'
$_this.QueryConfigOptionEx($spec)
#---------------QueryConfigTarget---------------
$hostParam = New-Object VMware.Vim.ManagedObjectReference
$hostParam.Type = 'HostSystem'
$hostParam.Value = 'host-12'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-7'
$_this.QueryConfigTarget($hostParam)
#---------------QueryTargetCapabilities---------------
$hostParam = New-Object VMware.Vim.ManagedObjectReference
$hostParam.Type = 'HostSystem'
$hostParam.Value = 'host-12'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-7'
$_this.QueryTargetCapabilities($hostParam)
#---------------DatastoreBrowser---------------
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-7'
$_this.DatastoreBrowser
#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)
#---------------HasPrivilegeOnEntities---------------
$entity = New-Object VMware.Vim.ManagedObjectReference[] (1)
$entity[0] = New-Object VMware.Vim.ManagedObjectReference
$entity[0].Type = 'Network'
$entity[0].Value = 'network-19'
$sessionId = '52e590e7-c3d2-263e-5567-cb981788ad27'
$privId = New-Object String[] (1)
$privId[0] = 'Network.Assign'
$_this = Get-View -Id 'AuthorizationManager-AuthorizationManager'
$_this.HasPrivilegeOnEntities($entity, $sessionId, $privId)
#---------------QueryConfigOptionEx---------------
$spec = New-Object
VMware.Vim.EnvironmentBrowserConfigOptionQuerySpec
$spec.Host = New-Object VMware.Vim.ManagedObjectReference
$spec.Host.Type = 'HostSystem'
$spec.Host.Value = 'host-12'
$spec.GuestId = New-Object String[] (1)
$spec.GuestId[0] = 'windows9Server64Guest'
$spec.Key = 'vmx-14'
$_this = Get-View -Id 'EnvironmentBrowser-envbrowser-7'
$_this.QueryConfigOptionEx($spec)
#---------------ListKmipServers---------------
$_this = Get-View -Id 'CryptoManagerKmip-CryptoManager'
$_this.ListKmipServers($null)
#---------------HasPrivilegeOnEntities---------------
$entity = New-Object VMware.Vim.ManagedObjectReference[] (1)
$entity[0] = New-Object VMware.Vim.ManagedObjectReference
$entity[0].Type = 'Network'
$entity[0].Value = 'network-19'
$sessionId = '52e590e7-c3d2-263e-5567-cb981788ad27'
$privId = New-Object String[] (1)
$privId[0] = 'Network.Assign'
$_this = Get-View -Id 'AuthorizationManager-AuthorizationManager'
$_this.HasPrivilegeOnEntities($entity, $sessionId, $privId)
#---------------CreateVM_Task---------------
$config = New-Object VMware.Vim.VirtualMachineConfigSpec
$config.NumCPUs = 2
$config.Flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$config.Flags.VirtualMmuUsage = 'automatic'
$config.Flags.VbsEnabled = $false
$config.Flags.MonitorType = 'release'
$config.Flags.EnableLogging = $true
$config.VirtualSMCPresent = $false
$config.MaxMksConnections = 40
$config.CpuFeatureMask = New-Object VMware.Vim.VirtualMachineCpuIdInfoSpec[]
(0)
$config.Tools = New-Object VMware.Vim.ToolsConfigInfo
$config.Tools.BeforeGuestShutdown = $true
$config.Tools.ToolsUpgradePolicy = 'manual'
$config.Tools.BeforeGuestStandby = $true
$config.Tools.AfterResume = $true
$config.Tools.AfterPowerOn = $true
$config.Version = 'vmx-14'
$config.LatencySensitivity = New-Object
VMware.Vim.LatencySensitivity
$config.LatencySensitivity.Level = 'normal'
$config.VirtualICH7MPresent = $false
$config.MemoryMB = 4096
$config.MemoryAllocation = New-Object
VMware.Vim.ResourceAllocationInfo
$config.MemoryAllocation.Shares = New-Object VMware.Vim.SharesInfo
$config.MemoryAllocation.Shares.Shares = 40960
$config.MemoryAllocation.Shares.Level = 'normal'
$config.MemoryAllocation.Limit = -1
$config.MemoryAllocation.Reservation = 0
$config.NumCoresPerSocket = 2
$config.BootOptions = New-Object
VMware.Vim.VirtualMachineBootOptions
$config.BootOptions.EfiSecureBootEnabled = $true
$config.MigrateEncryption = 'opportunistic'
$config.CpuAllocation = New-Object
VMware.Vim.ResourceAllocationInfo
$config.CpuAllocation.Shares = New-Object VMware.Vim.SharesInfo
$config.CpuAllocation.Shares.Shares = 2000
$config.CpuAllocation.Shares.Level = 'normal'
$config.CpuAllocation.Limit = -1
$config.CpuAllocation.Reservation = 0
$config.DeviceChange = New-Object
VMware.Vim.VirtualDeviceConfigSpec[] (7)
$config.DeviceChange[0] = New-Object
VMware.Vim.VirtualDeviceConfigSpec
$config.DeviceChange[0].Device = New-Object
VMware.Vim.VirtualMachineVideoCard
$config.DeviceChange[0].Device.NumDisplays = 1
$config.DeviceChange[0].Device.UseAutoDetect = $false
$config.DeviceChange[0].Device.ControllerKey = 100
$config.DeviceChange[0].Device.UnitNumber = 0
$config.DeviceChange[0].Device.Use3dRenderer = 'automatic'
$config.DeviceChange[0].Device.Enable3DSupport = $false
$config.DeviceChange[0].Device.DeviceInfo = New-Object
VMware.Vim.Description
$config.DeviceChange[0].Device.DeviceInfo.Summary = 'Video card'
$config.DeviceChange[0].Device.DeviceInfo.Label = 'Video card '
$config.DeviceChange[0].Device.Key = 500
$config.DeviceChange[0].Device.VideoRamSizeInKB = 8192
$config.DeviceChange[0].Operation = 'add'
$config.DeviceChange[1] = New-Object
VMware.Vim.VirtualDeviceConfigSpec
$config.DeviceChange[1].Device = New-Object
VMware.Vim.VirtualLsiLogicSASController
$config.DeviceChange[1].Device.SharedBus = 'noSharing'
$config.DeviceChange[1].Device.ScsiCtlrUnitNumber = 7
$config.DeviceChange[1].Device.DeviceInfo = New-Object
VMware.Vim.Description
$config.DeviceChange[1].Device.DeviceInfo.Summary = 'New SCSI
controller'
$config.DeviceChange[1].Device.DeviceInfo.Label = 'New SCSI
controller'
$config.DeviceChange[1].Device.Key = -106
$config.DeviceChange[1].Device.BusNumber = 0
$config.DeviceChange[1].Operation = 'add'
$config.DeviceChange[2] = New-Object
VMware.Vim.VirtualDeviceConfigSpec
$config.DeviceChange[2].FileOperation = 'create'
$config.DeviceChange[2].Device = New-Object VMware.Vim.VirtualDisk
$config.DeviceChange[2].Device.CapacityInBytes = 42949672960
$config.DeviceChange[2].Device.StorageIOAllocation = New-Object
VMware.Vim.StorageIOAllocationInfo
$config.DeviceChange[2].Device.StorageIOAllocation.Shares =
New-Object VMware.Vim.SharesInfo
$config.DeviceChange[2].Device.StorageIOAllocation.Shares.Shares =
1000
$config.DeviceChange[2].Device.StorageIOAllocation.Shares.Level =
'normal'
$config.DeviceChange[2].Device.StorageIOAllocation.Limit = -1
$config.DeviceChange[2].Device.Backing = New-Object
VMware.Vim.VirtualDiskFlatVer2BackingInfo
$config.DeviceChange[2].Device.Backing.FileName = '[ESX1DS01]'
$config.DeviceChange[2].Device.Backing.EagerlyScrub = $false
$config.DeviceChange[2].Device.Backing.ThinProvisioned = $false
$config.DeviceChange[2].Device.Backing.DiskMode = 'persistent'
$config.DeviceChange[2].Device.ControllerKey = -106
$config.DeviceChange[2].Device.UnitNumber = 0
$config.DeviceChange[2].Device.CapacityInKB = 41943040
$config.DeviceChange[2].Device.DeviceInfo = New-Object
VMware.Vim.Description
$config.DeviceChange[2].Device.DeviceInfo.Summary = 'New Hard
disk'
$config.DeviceChange[2].Device.DeviceInfo.Label = 'New Hard disk'
$config.DeviceChange[2].Device.Key = -107
$config.DeviceChange[2].Operation = 'add'
$config.DeviceChange[3] = New-Object
VMware.Vim.VirtualDeviceConfigSpec
$config.DeviceChange[3].Device = New-Object
VMware.Vim.VirtualE1000e
$config.DeviceChange[3].Device.MacAddress = ''
$config.DeviceChange[3].Device.Connectable = New-Object
VMware.Vim.VirtualDeviceConnectInfo
$config.DeviceChange[3].Device.Connectable.Connected = $true
$config.DeviceChange[3].Device.Connectable.AllowGuestControl =
$true
$config.DeviceChange[3].Device.Connectable.StartConnected = $true
$config.DeviceChange[3].Device.Backing = New-Object
VMware.Vim.VirtualEthernetCardNetworkBackingInfo
$config.DeviceChange[3].Device.Backing.DeviceName = 'VM Network'
$config.DeviceChange[3].Device.Backing.Network = New-Object
VMware.Vim.ManagedObjectReference
$config.DeviceChange[3].Device.Backing.Network.Type = 'Network'
$config.DeviceChange[3].Device.Backing.Network.Value = 'network-19'
$config.DeviceChange[3].Device.AddressType = 'generated'
$config.DeviceChange[3].Device.WakeOnLanEnabled = $true
$config.DeviceChange[3].Device.DeviceInfo = New-Object
VMware.Vim.Description
$config.DeviceChange[3].Device.DeviceInfo.Summary = 'New Network'
$config.DeviceChange[3].Device.DeviceInfo.Label = 'New Network'
$config.DeviceChange[3].Device.Key = -108
$config.DeviceChange[3].Operation = 'add'
$config.DeviceChange[4] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$config.DeviceChange[4].Device = New-Object
VMware.Vim.VirtualAHCIController
$config.DeviceChange[4].Device.DeviceInfo = New-Object
VMware.Vim.Description
$config.DeviceChange[4].Device.DeviceInfo.Summary = 'New SATA
Controller'
$config.DeviceChange[4].Device.DeviceInfo.Label = 'New SATA
Controller'
$config.DeviceChange[4].Device.Key = -109
$config.DeviceChange[4].Device.BusNumber = 0
$config.DeviceChange[4].Operation = 'add'
$config.DeviceChange[5] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$config.DeviceChange[5].Device = New-Object
VMware.Vim.VirtualCdrom
$config.DeviceChange[5].Device.Connectable = New-Object
VMware.Vim.VirtualDeviceConnectInfo
$config.DeviceChange[5].Device.Connectable.Connected = $false
$config.DeviceChange[5].Device.Connectable.AllowGuestControl =
$true
$config.DeviceChange[5].Device.Connectable.StartConnected = $false
$config.DeviceChange[5].Device.Backing = New-Object
VMware.Vim.VirtualCdromRemotePassthroughBackingInfo
$config.DeviceChange[5].Device.Backing.Exclusive = $false
$config.DeviceChange[5].Device.Backing.DeviceName = ''
$config.DeviceChange[5].Device.ControllerKey = -109
$config.DeviceChange[5].Device.UnitNumber = 0
$config.DeviceChange[5].Device.DeviceInfo = New-Object
VMware.Vim.Description
$config.DeviceChange[5].Device.DeviceInfo.Summary = 'New CD/DVD
Drive'
$config.DeviceChange[5].Device.DeviceInfo.Label = 'New CD/DVD
Drive'
$config.DeviceChange[5].Device.Key = -110
$config.DeviceChange[5].Operation = 'add'
$config.DeviceChange[6] = New-Object
VMware.Vim.VirtualDeviceConfigSpec
$config.DeviceChange[6].Device = New-Object
VMware.Vim.VirtualUSBXHCIController
$config.DeviceChange[6].Device.DeviceInfo = New-Object
VMware.Vim.Description
$config.DeviceChange[6].Device.DeviceInfo.Summary = 'New USB
Controller'
$config.DeviceChange[6].Device.DeviceInfo.Label = 'New USB
Controller'
$config.DeviceChange[6].Device.Key = -111
$config.DeviceChange[6].Device.BusNumber = 0
$config.DeviceChange[6].Operation = 'add'
$config.MemoryReservationLockedToMax = $false
$config.Name = 'testrecord'
$config.Files = New-Object VMware.Vim.VirtualMachineFileInfo
$config.Files.VmPathName = '[ESX1DS01]'
$config.CpuAffinity = New-Object
VMware.Vim.VirtualMachineAffinityInfo
$config.CpuAffinity.AffinitySet = New-Object int[] (0)
$config.PowerOpInfo = New-Object
VMware.Vim.VirtualMachineDefaultPowerOpInfo
$config.PowerOpInfo.SuspendType = 'preset'
$config.PowerOpInfo.StandbyAction = 'checkpoint'
$config.PowerOpInfo.ResetType = 'preset'
$config.PowerOpInfo.PowerOffType = 'preset'
$config.SwapPlacement = 'inherit'
$config.Firmware = 'efi'
$config.GuestId = 'windows9Server64Guest'
$pool = New-Object VMware.Vim.ManagedObjectReference
$pool.Type = 'ResourcePool'
$pool.Value = 'resgroup-8'
$hostParam = New-Object VMware.Vim.ManagedObjectReference
$hostParam.Type = 'HostSystem'
$hostParam.Value = 'host-12'
$_this = Get-View -Id 'Folder-group-v3'
$_this.CreateVM_Task($config, $pool, $hostParam)
#----------------- End of code capture ----------------
Wrapping Up
The New VMware vSphere 6.7 Update 2 Client Developer Center API Explorer and Code Capture mechanism found in vSphere 6.7 Update 2 is a great new addition to the functionality within the VMware vSphere Client interface. This reminds me of the functionality that Microsoft had introduced in some of the Server Wizards (VMware’s implementation being much better) where you would see the PowerShell output of let’s say the DCPromo operation. It would give you the PowerShell command to do that. However, VMware is going many steps further here in that you are controlling when the record function is happening and the code that results. Very, very cool! Also, the API Explorer being brought into the vSphere Client circumvents the need to login again to perform API calls. VMware is definitely rolling with the automation and developer mindset, to the benefit of vSphere administrators everywhere.
0 Comments