ESX : ESX command line interface (cli)

esxIntroduction

This page lists some of the esx commands I found to be useful, add your own in the comment if you have some good ones !

 

 

 

 

1) VM related commands

We first need to get the list of all existing VMs (as we are going to need each VM ID’s) :

vim-cmd vmsvc/getallvms

Once you get this list you can use the Vmid to send commands to a specific VM, such as :

  • Retrieving the power state of a given VM :
    vim-cmd vmsvc/power.getstate <Vmid>
  • Powering ON a VM :
    vim-cmd vmsvc/power.on <Vmid>
  • Powering OFF a VM :
    vim-cmd vmsvc/power.off <Vmid>

 

2) Host related commands

 

2.1 Check / Enable / Disable VM autostart

Based on this Yellow-Bricks post, here the simplest way to activate / deactivate or simply check the autostart function state :

vim-cmd /hostsvc/autostartmanager/enable_autostart [true-false]

The true parameter would enable the function while the false would (unsurprisingly !) disable this function.

This will update the /etc/vmware/hostd/vmAutoStart.xml file, when the autostart function is enabled you may find the following line in this file :

<enabled>true</enabled>

Therefore, the next command will give you the actual autostart function state :

grep '<enabled>.*</enabled>' /etc/vmware/hostd/vmAutoStart.xml

e.g :

~ # grep '<enabled>.*</enabled>' /etc/vmware/hostd/vmAutoStart.xml
 <enabled>false</enabled>

 

Update : The above tips DOES NOT work as expected, I did use the VSphere Client to enable this function, I did not have the time to search for a cli only solution, but here is the file before and after : This might help you building one working file.

Not working file :

<ConfigRoot>                             
  <AutoStartOrder>                       
    <_length>0</_length>                 
    <_type>vim.host.AutoStartManager.AutoPowerInfo[]</_type>
  </AutoStartOrder>                                         
  <SystemDefaults>                                          
    <_type>vim.host.AutoStartManager.SystemDefaults</_type> 
    <enabled>true</enabled>                                 
    <startDelay>5</startDelay>                              
    <stopAction>PowerOff</stopAction>                       
    <stopDelay>12</stopDelay>                               
    <waitForHeartbeat>false</waitForHeartbeat>              
  </SystemDefaults>                                         
</ConfigRoot>~

Working one :

<ConfigRoot>                             
  <AutoStartOrder>                       
    <_length>2</_length>                 
    <_type>vim.host.AutoStartManager.AutoPowerInfo[]</_type>
    <e id="0">                                              
      <_type>vim.host.AutoStartManager.AutoPowerInfo</_type>
      <key>                                                 
        <_type>vim.VirtualMachine</_type>                   
        <moid>2</moid>                                      
      </key>                                                
      <startAction>PowerOn</startAction>                    
      <startDelay>-1</startDelay>                           
      <startOrder>1</startOrder>                            
      <stopAction>SystemDefault</stopAction>                
      <stopDelay>-1</stopDelay>                             
      <waitForHeartbeat>systemDefault</waitForHeartbeat>    
    </e>                                                    
    <e id="1">                                              
      <_type>vim.host.AutoStartManager.AutoPowerInfo</_type>
      <key>                                                 
        <_type>vim.VirtualMachine</_type>                   
        <moid>1</moid>                                      
      </key>                                                
      <startAction>PowerOn</startAction>                    
      <startDelay>-1</startDelay>                           
      <startOrder>2</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>PowerOff</stopAction>                       
    <stopDelay>120</stopDelay>                              
    <waitForHeartbeat>false</waitForHeartbeat>              
  </SystemDefaults>                                         
</ConfigRoot>~

 

 2.2 Update Server license key from CLI

A quick note to say that the vim-cmd help is wrong :

~ # vim-cmd vimsvc/license
Usage: license [OPTIONS]

Control License Subsystem.
Options:
--show
Display license info.

--set=string
Set license serial number and optionally append /sourceId.

 

The correct syntax to enter a license number from cli does NOT need a equal sign, you may get the following error if you do as stated in the help message :

~ # vim-cmd vimsvc/license --set=1H40K-*****-*****-*****-*****
[500] Unexpected operation, aborting command.

 

When the correct syntax gives :

~ # vim-cmd vimsvc/license --set 1H40K-*****-*****-*****-*****
 serial:1H40K-*****-*****-*****-*****

 vmodl key: esxBasic.vram 
 name: VMware vSphere 5 Hypervisor 
 total: 0 
 used: 1 
 unit: cpuPackage 
 Properties: 
 [ProductName] = VMware ESX Server 
 [ProductVersion] = 5.0 
 [count_disabled] = This license is unlimited
 [feature] = vsmp:8 ("Up to 8-way virtual SMP")
 [FileVersion] = 5.5.0.1 
 [LicenseFilePath] = /usr/lib/vmware/licenses/site/license-esx-50-e01-c3-t2-201006

[... OUTPUT_STRIPPED ...]

 [Localized] = <Not supported type for value: 0x1f306088>
[200] Command Complete.
Result: Success

 

 

 

 

 

More “Virtualisation” posts

 

Resources

Leave a Reply

Your email address will not be published. Required fields are marked *

This site supports SyntaxHighlighter via WP SyntaxHighlighter. It can highlight your code.
How to highlight your code: Paste your code in the comment form, select it and then click the language link button below. This will wrap your code in a <pre> tag and format it when submitted.