I had to reload all registered virtual machine configurations after replacing an NVMe adapter in one of my ESXi hosts (see the posts next week).
The below script is based on this series of April last year on listing, stopping, starting, hibernating and waking up VMs, especially vim-cmd-list-all-VMs.sh
:
- VMware ESXi console: viewing all VMs, suspending and waking them up: part 1 on Busybox, sed and regular expressions (especially capture groups)
- VMware ESXi console: viewing all VMs, suspending and waking them up: part 2 on
vim-cmd vmsvc
commands, especially the on the ones accepting a vmid
parameter
- VMware ESXi console: viewing all VMs, suspending and waking them up: part 3 digging deeper into the various
vim-cmd vmsvc/power.*
commands
- VMware ESXi console: viewing all VMs, suspending and waking them up: part 4 on amending
vim-cmd vmsvc/getallvms
with information from vim-cmd vmsvc/power.getstate
and vim-cmd vmsvc/get.config
- VMware ESXi console: viewing all VMs, suspending and waking them up: part 5 on applying the various
vim-cmd vmsvc/power.*
commands on a list of relevant virtual machines
Here is the script vim-cmd-reload-all-VM-vmx-configurations.sh
:
#!/bin/sh
vmids=`vim-cmd vmsvc/getallvms | sed -n -E -e "s/^([[:digit:]]+)\s+((\S.+\S)?)\s+(\[\S+\])\s+(.+\.vmx)\s+(\S+)\s+(vmx-[[:digit:]]+)\s*?((\S.+)?)$/\1/p"`
for vmid in ${vmids} ; do
powerState=`vim-cmd vmsvc/power.getstate ${vmid} | sed '1d'`
name=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/\(vim.vm.ConfigInfo\) \{/,/files = \(vim.vm.FileInfo\) \{/ s/^ +name = "(.*)",.*?/\1/p'`
vmPathName=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/files = \(vim.vm.FileInfo\) \{/,/tools = \(vim.vm.ToolsConfigInfo\) \{/ s/^ +vmPathName = "(.*)",.*?/\1/p'`
echo "Reloading vmx of VM with id ${vmid} which has power state ${powerState} (name = ${name}; vmPathName = ${vmPathName})."
vim-cmd vmsvc/reload ${vmid}
done
exit 0
Note that the script can throw errors, for instance the below one:
# vim-cmd vmsvc/reload 27
(vmodl.fault.SystemError) {
faultCause = (vmodl.MethodFault) null,
faultMessage = ,
reason = "Invalid fault"
msg = "Received SOAP response fault from []: reload
vim.fault.InvalidState"
}
This particular error means that the ESXi system itself is in an invalid state (as opposed to the virtual machine being an invalid state). In this case, it can be thrown if the ESXi system is in Maintenance Mode: in that case, it is not allowed to reload any .vmx
virtual machine configurations (it only shows the configuration at the time that hostd
got started).
There are two ways to solve this:
- The blunt way: restart the
hostd
as this will re-read the .vmx
files
- The not so blunt way: bring the server out of maintenance mode, then rerun the
vim-cmd vmsvc/reload
command.
On the many places that can throw vim.fault.InvalidState
In this case, the reason for vim.fault.InvalidState
was that the server was in maintenance mode. However, be aware that there are way more places that can throw vim.fault.InvalidState
.
Via [Wayback/Archive.is] 1-day-SAP-custom/InvalidState
.rst at master · bcstryker/1-day-SAP-custom and [Wayback/Archive.is] bcstryker/1-day-SAP-custom, I found [Wayback/Archive.is] InvalidState – vSphere Web Services API – VMware {code} that lists about 200 API calls for this seemingly simple fault:
Fault Description
An InvalidState
fault is thrown if the operation failed due to the current state of the system.
For example, at [Wayback] Failed to deploy VM: vim.fault.InvalidState – VMware Technology Network VMTN the cause of vim.fault.InvalidState
was deploying an .ova
file over a slow WiFi connection.
On VMware services and their names
The VMware service names are very well explained in the [Wayback] what is difference between hostd, Vpxa and vpxd. – VMware Technology Network VMTN answer by [Wayback] About AndreTheGiant – VMware Technology Network VMTN
hostd
is the daemon for direct VIC connection (when you use VIC to connect to your ESX).
vpx
is the original name of vCenter Center, so:
vpxa
is the VC agent (ESX side)
vpxd
is the VC daemon (VC side)
Since ESXi 5.0, the VIC (VMware Infrastructure Client) got gradually replaced by the vSphere Web Client which is serviced by the hostd
as well, see:
–jeroen
Like this:
Like Loading...