In part one of Managing ESXi without the VI client, I dealt with some initial setup issues and creating a VM. In this part, I show the process to add a license key, how to enable VM auto-start options and how to unregister a VM.
Adding A License File
The VMs on the host had been running for some time without any issues, but were powered off due to a power failure so I had to login and start them manually.
1) I tried to power on the VM and received the below error about the evaluation period being over.
~ # vim-cmd vmsvc/power.on 96
Powering on VM:
(vim.fault.LicenseExpired) {
dynamicType = <unset>,
faultCause = (vmodl.MethodFault) null,
faultMessage = (vmodl.LocalizableMessage) [
(vmodl.LocalizableMessage) {
dynamicType = <unset>,
key = "com.vmware.vim.license.error.evalPeriodOver",
arg = (vmodl.KeyAnyValue) [
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
key = "info",
value = "notinstalled",
}
],
message = "Evaluation period is over, Please install a license.",
}
],
licenseKey = "00000-00000-00000-00000-00000",
msg = "License key has expired."
}
~ #
2) The command vim-cmd includes a license option within the /vimsvc node. The license option includes both a set and switch option. Running vim-cmd vimsvc/license –show displayed similar information as when I tried to power on the VM.
~ # vim-cmd vimsvc/license --show
[200] Sending request for installed licenses...[200] Complete, result is:
serial: 00000-00000-00000-00000-00000
vmodl key: eval
name: Evaluation Mode
total: 0
used: 0
unit: host
Properties:
[expirationHours] = 0
[expirationMinutes] = 0
[diagnostic] = Evaluation period has expired, please install license.
3) I tried to set the license with vim-cmd vimsvc/license –set, but kept getting an error shown below. I did try the license serial with both single and double quotes and also without quotes and dashes, but always got the same error.
/etc/vmware # vim-cmd vimsvc/license --set="M0025-*****-*****-*****-0D040"
[500] Unexpected operation, aborting command.
Update: the help for vim-cmd incorrectly includes an equal sign. The command should be entered as: vim-cmd vimsvc/license –set “M0025-*****-*****-*****-0D040”
4) So to set the license I edited the license file with the command vi /etc/vmware/vmware.lic. I replaced 00000-00000-00000-00000-00000 with my serial number and then saved the file. I then querried the license data and got this response.
etc/vmware # vim-cmd vimsvc/license --show
[200] Sending request for installed licenses...[200] Complete, result is:
serial: M0025-*****-*****-*****-0D040
vmodl key: esxBasic
name: ESXi 4 Single Server
total: 0
used: 1
unit: cpuPackage:6core
Properties:
[ProductName] = VMware ESX Server
[ProductVersion] = 4.0
[feature] = maxRAM:256g ("Up to 256 GB of memory")
[feature] = vsmp:4 ("Up to 4-way virtual SMP")
[count_disabled] = This license is unlimited
[200] End of report.
5) I then tried to power on a VM and got this error. So I ran services.sh restart
vim-cmd vmsvc/power.on 96
Powering on VM:
(vim.fault.LicenseExpired) {
dynamicType = <unset>,
faultCause = (vmodl.MethodFault) null,
faultMessage = (vmodl.LocalizableMessage) [
(vmodl.LocalizableMessage) {
dynamicType = <unset>,
key = "com.vmware.vim.license.error.evalPeriodOver",
arg = (vmodl.KeyAnyValue) [
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
key = "info",
value = "notinstalled",
}
],
message = "Evaluation period is over, Please install a license.",
}
],
licenseKey = "M0025-*****-*****-*****-0D040",
msg = "License key has expired."
6) I could then power on the VM. I got an error on the first power on attempt, but things were fine after that.
/etc/vmware # vim-cmd vmsvc/power.on 96
Failed to connect: 514 Error connecting to hostd-vmdb service instance.
/etc/vmware # vim-cmd vmsvc/power.on 96
Powering on VM:
Enabling VM Auto Start and Shutdown Options
The configuration values for VM automatic startup and shutdown is stored in the file /etc/vmware/hostd/vmAutoStart.xml.
1) By default auto start is not enabled and the configuration file will look like this.
<ConfigRoot>
<AutoStartOrder>
<_length>0</_length>
<_type>vim.host.AutoStartManager.AutoPowerInfo[]</_type>
</AutoStartOrder>
<SystemDefaults>
<_type>vim.host.AutoStartManager.SystemDefaults</_type>
<startDelay>120</startDelay>
<stopAction>PowerOff</stopAction>
<stopDelay>120</stopDelay>
<waitForHeartbeat>false</waitForHeartbeat>
</SystemDefaults>
</ConfigRoot>
2) The first step taken in the VI client is to enable the option “Allow virtual machines to start and stop automatically with the system”. When you enable this option the file changes as shown below.
<ConfigRoot>
<AutoStartOrder>
<_length>0</_length>
<_type>vim.host.AutoStartManager.AutoPowerInfo[]</_type>
</AutoStartOrder>
<SystemDefaults>
<_type>vim.host.AutoStartManager.SystemDefaults</_type>
<enabled>true</enabled>
<startDelay>120</startDelay>
<stopAction>PowerOff</stopAction>
<stopDelay>120</stopDelay>
<waitForHeartbeat>false</waitForHeartbeat>
</SystemDefaults>
</ConfigRoot>
3) To control the shut down options you can change both stopDelay and stopAction. stopDelay is the time in seconds (120 second by default) that ESXi should wait for each VM to power down. You can set stopAction to PowerOff, GuestShutdown or Suspend.
4) For VM startup you can also set the startDelay option and also the waitForHeartbeat option.
5) Once VMs are enable for autostart, the vmAutoStart.xml file will grow much larger. The below file shows 4 VMs enabled for auto start. Two VMs have been specified to start first and second, and the other two can start in any order. There are a number of things to note.
a) The section <AutoStartOrder> </AutoStartOrder> has been added above the SystemDefaults section.
b) The length parameter should equal the number of VMs enable for auto startup (four in this case).
c) Each VM is referenced by the VM ID. You can get this with the command vim-cmd vmsvc/getallvms.
d) VM ID 144 is set to start first. You can see the startOrder value set to 1. VM ID 128 is set to start second and has a value of 2. The other 2 VMs have a value of -1 which means that they can be started in anyorder.
e) For all the VMs but VM ID 144, they are set to use the system setting for startup and shutdown. Thus startDelay and stopDelay are set to -1 and likewise stopAction and waitForHeartBeat are set to systemDefault. VM ID 144 has custom values for those 4 settings.
<ConfigRoot>
<AutoStartOrder>
<_length>4</_length>
<_type>vim.host.AutoStartManager.AutoPowerInfo[]</_type>
<e id="0">
<_type>vim.host.AutoStartManager.AutoPowerInfo</_type>
<key>
<_type>vim.VirtualMachine</_type>
<moid>144</moid>
</key>
<startAction>PowerOn</startAction>
<startDelay>60</startDelay>
<startOrder>1</startOrder>
<stopAction>Suspend</stopAction>
<stopDelay>60</stopDelay>
<waitForHeartbeat>yes</waitForHeartbeat>
</e>
<e id="1">
<_type>vim.host.AutoStartManager.AutoPowerInfo</_type>
<key>
<_type>vim.VirtualMachine</_type>
<moid>128</moid>
</key>
<startAction>PowerOn</startAction>
<startDelay>-1</startDelay>
<startOrder>2</startOrder>
<stopAction>SystemDefault</stopAction>
<stopDelay>-1</stopDelay>
<waitForHeartbeat>systemDefault</waitForHeartbeat>
</e>
<e id="2">
<_type>vim.host.AutoStartManager.AutoPowerInfo</_type>
<key>
<_type>vim.VirtualMachine</_type>
<moid>96</moid>
</key>
<startAction>PowerOn</startAction>
<startDelay>-1</startDelay>
<startOrder>-1</startOrder>
<stopAction>SystemDefault</stopAction>
<stopDelay>-1</stopDelay>
<waitForHeartbeat>systemDefault</waitForHeartbeat>
</e>
<e id="3">
<_type>vim.host.AutoStartManager.AutoPowerInfo</_type>
<key>
<_type>vim.VirtualMachine</_type>
<moid>112</moid>
</key>
<startAction>PowerOn</startAction>
<startDelay>-1</startDelay>
<startOrder>-1</startOrder>
<stopAction>SystemDefault</stopAction>
<stopDelay>-1</stopDelay>
<waitForHeartbeat>systemDefault</waitForHeartbeat>
</e>
</AutoStartOrder>
<SystemDefaults>
<_type>vim.host.AutoStartManager.SystemDefaults</_type>
<enabled>true</enabled>
<startDelay>120</startDelay>
<stopAction>GuestShutdown</stopAction>
<stopDelay>120</stopDelay>
<waitForHeartbeat>false</waitForHeartbeat>
</SystemDefaults>
6) The file was saved after make the below changes and the server was rebooted to test things out.
Unregistering a VM
I had one VM that I was pretty much done using, but wasn’t quick ready to delete. As it was a domain controller I wanted to ensure that it wasn’t accidentally started so I wanted to unregister it.
1) I used vim-cmd vmsvc/getallvms to get the VM ID for the virtual machine.
2) I then ran vim-cmd vmsvc/unregister VMID to remove it. The VM was no longer listed in the output of getallvms, but the virtual hard drive and VMX file were still in the datastore should I need to access the VM in the future. Otherwise I would have deleted the folder for the VM and it would gone.