The vCenter simulator (vcsim) contains a vSphere Web Services (SOAP) SDK endpoint. This is intended for testing consumers of the Web Service API. It can be used by any language that can talk to the vSphere Web Service API. This post describes how to install and test it on the one hand with VMware PowerCLI and on the other hand with VMware pyVmomi.
Installation and Testing VMware vCenter and ESXi API Simulator with PowerCLI and pyVmomi
PowerCLI is a command-line and scripting tool built on PowerShell, to manage and automate VMware infrastructure. pyVmomi is the Python SDK for the VMware vSphere Web Service API that allows you to manage ESX, ESXi, and vCenter. On this way an independent local test environment can be implemented.
Hint: vCenter servers offers two main API services:
REST is not a replacement for SOAP APIs, but a complement to them.
vCenter and ESXi API Simulator (vcsim)
Instructions for installing and testing of vcsim:
- Download the current version of vCenter and ESXi Web Service API based simulator from the release page.
- Start the vCenter server simulator with the command:
& .\vcsim -username root -password root
- Check its function in the browser with the URL:
https://root:root@127.0.0.1:8989/about
- It is also possible to work without Secure Sockets Layer (SSL) encryption, but not with PowerCLI:
& .\vcsim -username root -password root tls=false
- To activate the SOAP (Simple Object Access Protocol) trace start it with the command:
& .\vcsim.exe -username root -password root -trace
With this setting detailed and interesting information about the request and the response is output.
A detailed description of vcsim is available here.
The following vCenter hierarchy is represented by vcsim:
Default vCenter inventory of vcsim:
Folder /
Datacenter /DC0
Folder /DC0/vm
VirtualMachine /DC0/vm/DC0_H0_VM0
VirtualMachine /DC0/vm/DC0_H0_VM1
VirtualMachine /DC0/vm/DC0_C0_RP0_VM0
VirtualMachine /DC0/vm/DC0_C0_RP0_VM1
Folder /DC0/host
ComputeResource /DC0/host/DC0_H0
HostSystem /DC0/host/DC0_H0/DC0_H0
ResourcePool /DC0/host/DC0_H0/Resources
ClusterComputeResource /DC0/host/DC0_C0
HostSystem /DC0/host/DC0_C0/DC0_C0_H0
HostSystem /DC0/host/DC0_C0/DC0_C0_H1
HostSystem /DC0/host/DC0_C0/DC0_C0_H2
ResourcePool /DC0/host/DC0_C0/Resources
Folder /DC0/datastore
Datastore /DC0/datastore/LocalDS_0
Folder /DC0/network
Network /DC0/network/VM Network
DistributedVirtualSwitch /DC0/network/DVS0
DistributedVirtualPortgroup /DC0/network/DVS0-DVUplinks-9
DistributedVirtualPortgroup /DC0/network/DC0_DVPG0
|
PowerCLI
Instructions for installing and testing of PowerCLI:
- Download the current .NET package manager.
- Download of VMware PowerCLI from PowerShell Galery and all dependencies with the command:
& .\nuget.exe install vmware.powercli -Source https://www.powershellgallery.com/api/v2/
An internet connection is required to use this command, because necessary files are downloaded here.
Hint: The response time of the PowerShell Gallery is not always fast, so this approach is recommended.
- Extract all NuGet packages from the directories with the PowerShell script
$NuGets = Get-ChildItem -LiteralPath $PSScriptRoot *.nupkg -Depth 1
ForEach($NuGet in $NuGets) {
Copy-Item "$($NuGet.DirectoryName)\$($NuGet.Name)" -Destination $PSScriptRoot
Remove-Item "$($NuGet.DirectoryName)" -Recurse -Force
}
|
- Install VMware PowerCLI with the following PowerShell commands in admin mode:
Register-PSRepository -Name "myRepositoryName" -SourceLocation "C:\Dummy"
Install-Module -Name "VMware.PowerCLI" -Repository "myRepositoryName" -AllowClobber
Unregister-PSRepository -Name "myRepositoryName"
Hint: To uninstall use
Uninstall-Module -Name "VMware.PowerCLI"
Hint: If you use an old Windows version, it is necessary to switch to TLS 1.2 with
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Hint: If NuGet package provider is not installed, install it first with
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208
To check if it is installed use the command Get-PackageProvider
- Set the configuration with the command
Set-PowerCLIConfiguration -ParticipateInCEIP $false -InvalidCertificateAction Ignore -Confirm:$false
-
Connect the PowerCLI to vCenter server simulator with the command
Connect-VIServer -Server 127.0.0.1 -Port 8989 -User "root" -Password "root"
and check the function with the commands
Get-VMHost
or Get-VM
PowerCLI in PowerShell Windows with vCenter simulator
PowerCLI in PowerShell Core on Windows with vCenter simulator
PowerCLI in PowerShell Core on Linux with vCenter simulator
- Get the current version of PowerCLI with
$PowerCLIVersion = Get-Module -Name VMware.VimAutomation.Core
Write-Host "$($PowerCLIVersion.Version.toString())"
|
- It is possible to get more information with
$global:DefaultVIServer | select *
If the attribute ProductLine delivers vpx, a connection to a vCenter was established.
- The following code can be used for testing the connection.
if ($global:DefaultVIServer) {
# Your code here
}
|
- It is possible to view all available commands with Get-VICommand;
A detailed help for each command is available with e.g. Get-Help Get-VM -Full
A detailed description of PowerCLI is available here.
pyVmomi
Instructions for installing and testing of pyVmomi:
- Download the current version of pyVmomi from the release page.
- Convert the tar.gz source code file to a wheel with
pip wheel pyvmomi-8.0.2.0.1.tar.gz
- Install pyVmomi with
pip install pyvmomi-8.0.2.0.1-py2.py3-none-any.whl
-
The following code can be used for testing the connection.
from pyVim.connect import *
serviceInstance = Connect(
host = "127.0.0.1",
port = 8989,
user = "root",
pwd = "root",
sslContext = None
)
serviceInstanceContent = serviceInstance.RetrieveContent()
aboutInfo = serviceInstanceContent.about
print("Name:", aboutInfo.name)
print("Fullname:", aboutInfo.fullName)
# Your code here
Disconnect(serviceInstance)
|
pyVmomi on Windows with vCenter simulator
A detailed description of pyVmomi is available here.
Conclusion
This approach shows that it is very easy to implement a test environment for experimenting with PowerCLI or pyVmomi. The vCenter simulator provides the necessary prerequisites for this. The operating system used is irrelevant, because all necessary components are offered for several platforms.