Skip to content
@deckyard/vmware

vmware cheatsheet

Every export of @deckyard/vmware. Guides are listed in the introduction.

jennifer
import "@deckyard/vmware/" as vmware;

Every function that sends a request throws Error{kind: "vmware"} when it fails. A vm argument is a VM id such as vm-42.

Constants

ConstantValueMeaning
ERROR_KIND"vmware"the kind of every error the deck throws
MAX_POLL_FAILURES5failed checks in a row after which the wait functions give up
SESSION_HEADER"vmware-api-session-id"the header that carries the session id
POWERED_ON"POWERED_ON"power state: running
POWERED_OFF"POWERED_OFF"power state: off
SUSPENDED"SUSPENDED"power state: suspended

Types

Client

FieldMeaning
url as stringhttps://host, no trailing slash
session as stringsession id from login; "" for none
tls as http.TlsOptionscertificate checking
timeoutMs as intidle timeout per request; 0 for the http default
retries as intretries of a GET answered 429 or 5xx
pollMs as intinterval of waitTask and waitGuestProcess

VmFilter

FieldMeaning
vms as list of stringVM ids
names as list of stringexact VM names
powerStates as list of stringPOWERED_ON, POWERED_OFF, SUSPENDED
hosts as list of stringhost ids
clusters as list of stringcluster ids
datacenters as list of stringdatacenter ids
folders as list of stringfolder ids
resourcePools as list of stringresource pool ids

Placement

FieldMeaning
folder as stringVM folder id
resourcePool as stringresource pool id
cluster as stringcluster id
host as stringhost id
datastore as stringdatastore id

VmSpec

FieldMeaning
name as stringVM name
guestOs as stringguest OS id, e.g. UBUNTU_64
placement as Placementwhere it goes
cpuCount as intvirtual CPUs; 0 for the default
memoryMiB as intmemory in MiB; 0 for the default
diskGiB as intone new disk in GiB; 0 for none
network as stringnetwork id for one NIC; "" for none
networkType as stringthat network's type; "" for STANDARD_PORTGROUP

Version

FieldMeaning
product as stringe.g. VMware vCenter Server
version as stringe.g. 8.0.2.00100
build as stringbuild number
type as stringdeployment type
releasedate as stringe.g. 2023-12-05

VmSummary

FieldMeaning
vm as stringVM id
name as stringVM name
powerState as stringPOWERED_ON, POWERED_OFF or SUSPENDED
cpuCount as intvirtual CPUs
memoryMiB as intmemory in MiB

GuestIdentity

FieldMeaning
name as stringguest OS id, e.g. UBUNTU_64
family as stringe.g. LINUX
fullName as stringe.g. Ubuntu Linux (64-bit)
hostName as stringthe guest's host name
ipAddress as stringits primary IP address

Host

FieldMeaning
host as stringhost id
name as stringhost name
connectionState as stringCONNECTED, DISCONNECTED, NOT_RESPONDING
powerState as stringPOWERED_ON, POWERED_OFF, STANDBY

Cluster

FieldMeaning
cluster as stringcluster id
name as stringcluster name
haEnabled as boolvSphere HA is on
drsEnabled as boolDRS is on

Datastore

FieldMeaning
datastore as stringdatastore id
name as stringdatastore name
type as stringVMFS, NFS, VSAN, ...
capacity as intsize, bytes
freeSpace as intbytes free

Item

FieldMeaning
id as stringobject id
name as stringobject name
type as stringnetwork or folder type; "" otherwise

Task

FieldMeaning
id as stringtask id
status as stringPENDING, RUNNING, BLOCKED, SUCCEEDED, FAILED
description as stringwhat it does
progress as intpercent done
result as stringthe result; a string as it is, else JSON
error as stringwhy it failed

LinuxCustomization

FieldMeaning
hostName as stringhost name
domain as stringdomain name; required
timeZone as stringe.g. Europe/Vienna; "" keeps it
ipAddress as stringfirst NIC's IPv4 address; "" for DHCP
prefix as intits prefix length
gateway as stringdefault gateway
dnsServers as list of stringDNS servers
dnsSuffixes as list of stringDNS search suffixes

Disk

FieldMeaning
disk as stringdisk id, e.g. 2000
label as stringe.g. Hard disk 1
type as stringSCSI, SATA, NVME, IDE
capacity as intsize, bytes
file as stringits VMDK

Nic

FieldMeaning
nic as stringNIC id, e.g. 4000
label as stringe.g. Network adapter 1
type as stringe.g. VMXNET3
macAddress as stringMAC address
state as stringCONNECTED, NOT_CONNECTED, ...
network as stringnetwork id
networkType as stringnetwork type
startConnected as boolconnects at power-on

Category

FieldMeaning
id as stringcategory id
name as stringname
description as stringdescription
cardinality as stringSINGLE or MULTIPLE

Tag

FieldMeaning
id as stringtag id
name as stringname
description as stringdescription
categoryId as stringits category

GuestInterface

FieldMeaning
nic as stringvirtual NIC id; "" for none
macAddress as stringMAC address
addresses as list of stringaddresses with prefix

GuestCredentials

FieldMeaning
user as stringguest user
password as stringits password

GuestProcess

FieldMeaning
pid as intprocess id
finished as boolit has ended
exitCode as intits exit code

Client

FunctionReturnsDoes
vmware.client(address)Clienta client for host, host:port or a URL
vmware.withSession(c, session)Clientuse a session id kept from an earlier login
vmware.withCaCert(c, pem)Clienttrust this PEM certificate too
vmware.withInsecure(c)Clientaccept any certificate
vmware.withTimeout(c, ms)Clientidle timeout per request
vmware.withRetries(c, n)Clientretry a GET answered 429 or 5xx
vmware.withPollInterval(c, ms)Clienthow often the wait functions ask
vmware.login(c, username, password)Clientopen a session
vmware.logout(c)Clientend it
vmware.ensureSession(c, username, password)Clientcheck the session, log in again when it has ended
vmware.describe(c)stringthe client for a log line, without its session

Any endpoint

path is /api/... with any query string.

FunctionReturnsDoes
vmware.query(params)string?k=v&k=v2... from a map of string to list of string
vmware.call(c, method, path, body)json.Valueany method; a null body sends none
vmware.get(c, path)json.ValueGET
vmware.post(c, path, body)json.ValuePOST
vmware.put(c, path, body)json.ValuePUT
vmware.patch(c, path, body)json.ValuePATCH
vmware.delete(c, path)json.ValueDELETE

VMs

FunctionReturnsDoes
vmware.vms(c, filter)list of VmSummarythe VMs a filter selects
vmware.vmByName(c, name)VmSummarythe one VM with this name
vmware.vm(c, vm)json.Valueeverything about one VM
vmware.powerState(c, vm)stringits power state
vmware.powerOn(c, vm)nullpower on
vmware.powerOff(c, vm)nullcut the power
vmware.suspend(c, vm)nullsuspend
vmware.reset(c, vm)nullreset
vmware.shutdownGuest(c, vm)nullask the guest OS to shut down (Tools)
vmware.rebootGuest(c, vm)nullask the guest OS to reboot (Tools)
vmware.guestIdentity(c, vm)GuestIdentityguest OS, host name, IP (Tools)

Creating and deleting

FunctionReturnsDoes
vmware.createSpec(spec)json.Valuethe request body for a VmSpec, to change before createVmFrom
vmware.createVm(c, spec)stringcreate a VM, powered off; returns its id
vmware.createVmFrom(c, body)stringcreate a VM from a full request body
vmware.cloneVm(c, source, name, placement, powerOn)stringclone a VM
vmware.findLibraryItem(c, name)stringthe id of the content library item with this name
vmware.deployTemplate(c, item, name, placement, powerOn)stringdeploy a VM from a library VM template
vmware.deleteVm(c, vm)nulldelete a powered-off VM and its disks
vmware.cloneVmTask(c, source, name, placement, powerOn)stringclone as a task; returns the task id

Tasks

FunctionReturnsDoes
vmware.startTask(c, method, path, body)stringstart an operation with vmw-task=true
vmware.taskStatus(c, id)Taskwhere a task stands
vmware.waitTask(c, id, timeoutMs)Taskwait until it ends; 0 waits for ever

Guest customization

FunctionReturnsDoes
vmware.customizationSpecs(c)list of Itemthe stored specs
vmware.customize(c, vm, specName)nullapply a stored spec at the next power-on
vmware.linuxSpec(lc)json.Valuea Linux spec, to change before customizeWith
vmware.customizeWith(c, vm, spec)nullapply a spec given in full
vmware.customizeLinux(c, vm, lc)nullapply a Linux spec

Hardware

FunctionReturnsDoes
vmware.setCpu(c, vm, count)nullvirtual CPUs
vmware.setMemory(c, vm, mib)nullmemory in MiB
vmware.disks(c, vm)list of Diskthe virtual disks
vmware.addDisk(c, vm, gib)stringadd an empty disk; returns its id
vmware.removeDisk(c, vm, disk)nulldetach a disk; the VMDK stays
vmware.nics(c, vm)list of Nicthe network adapters
vmware.addNic(c, vm, network, networkType)stringadd a VMXNET3 adapter
vmware.connectNic(c, vm, nic)nullplug it in
vmware.disconnectNic(c, vm, nic)nullunplug it
vmware.removeNic(c, vm, nic)nullremove it

Tags

FunctionReturnsDoes
vmware.categories(c)list of Categorythe tag categories
vmware.tags(c)list of Tagthe tags
vmware.createCategory(c, name, cardinality)stringa new category; SINGLE or MULTIPLE
vmware.createTag(c, categoryId, name)stringa new tag
vmware.deleteTag(c, tag)nulldelete a tag
vmware.deleteCategory(c, category)nulldelete a category and its tags
vmware.attachTag(c, tag, vm)nulltag a VM
vmware.detachTag(c, tag, vm)nulluntag it
vmware.vmTags(c, vm)list of stringtag ids on a VM
vmware.taggedVms(c, tag)list of stringVM ids with a tag

Inside the guest

Needs VMware Tools running in the guest.

FunctionReturnsDoes
vmware.guestInterfaces(c, vm)list of GuestInterfaceevery interface and address
vmware.guestAddresses(c, vm)list of stringaddresses without loopback and link-local
vmware.runInGuest(c, vm, creds, path, arguments)intstart a program; returns its pid
vmware.guestProcess(c, vm, creds, pid)GuestProcesswhere it stands
vmware.waitGuestProcess(c, vm, creds, pid, timeoutMs)GuestProcesswait until it ends

Inventory

FunctionReturnsDoes
vmware.version(c)Versionthe appliance's version
vmware.hosts(c)list of Hostthe ESXi hosts
vmware.clusters(c)list of Clusterthe clusters
vmware.datastores(c)list of Datastorethe datastores
vmware.datacenters(c)list of Itemthe datacenters
vmware.networks(c)list of Itemthe networks
vmware.folders(c, type)list of Itemthe folders of a type; "" for all
vmware.resourcePools(c)list of Itemthe resource pools