Apr 3, 2012

Power on VM with command line at VMware vSphere Hypervisor Host


We change UPS eqipment today, so I shutdown VMware vSphere Hypervisor from remote.
I forgot to setup VM boot when VMware vSphere Hypervisor boot.


I didn't have windows with vSphere client, and I didn't want to download vCLI.
I start google and looking some method. I find this VMware KB ( http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1038043 )

Login  VMware vSphere Hypervisor with ssh.

use " vim-cmd " command  to get VM id and some information.


# vim-cmd   vmsvc/getallvms
Vmid       Name                          File                        Guest OS      Version   Annotation
     openSUSE12-1   [datastore1] openSUSE12-1/openSUSE12-1.vmx   rhel6_64Guest   vmx-08            

Now, our target VM's Vmid is 2.

To get power status use #vim-cmd   vmsvc/power.getstate  vmid
# vim-cmd  vmsvc/power.getstate   2
Retrieved runtime info
Powered off


Power on VM.
# vim-cmd   vmsvc/power.on   2
Powering on VM:


Double confirm the powerstatus
# vim-cmd   vmsvc/power.getstate  2
Retrieved runtime info
Powered on     




If you want to set VM boot with VMware vSphere Hypervisor you could see this( http://communities.vmware.com/thread/254854 ) or this one ( http://communities.vmware.com/message/1450748 )



To view the default value, use


# vim-cmd   hostsvc/autostartmanager/get_defaults  
(vim.host.AutoStartManager.SystemDefaults) {
   dynamicType =
   enabled =
   startDelay = 120, 
   stopDelay = 120, 
   waitForHeartbeat = false, 
   stopAction = "PowerOff", 
}

The command will reference the /etc/vmware/hostd/vmAutoStart.xml

# cat   /etc/vmware/hostd/vmAutoStart.xml 
 
    <_length>0
    <_type>vim.host.AutoStartManager.AutoPowerInfo[]
 
 
    <_type>vim.host.AutoStartManager.SystemDefaults
    120
    PowerOff
    120
    false
 

Enable autostart  ( 1 = enable )
# vim-cmd   hostsvc/autostartmanager/enable_autostart  1


View the vmAutoStart.xml

# cat /etc/vmware/hostd/vmAutoStart.xml

 
    <_length>0
    <_type>vim.host.AutoStartManager.AutoPowerInfo[]
 
 
    <_type>vim.host.AutoStartManager.SystemDefaults
    true
    120
    PowerOff
    120
    false
 




for update_autostartentry syntax
# vim-cmd hostsvc/autostartmanager/update_autostartentry
Insufficient arguments.
Usage: update_autostartentry VMId StartAction StartDelay StartOrder StopAction StopDelay WaitForHeartbeat


Setting up VM autostart



# vim-cmd hostsvc/autostartmanager/update_autostartentry 2  "PowerOn" "15" "1" "systemDefault" "systemDefault" "systemDefault"
1Updated AutoStart order.



Review the vmAutoStart.xml


# cat /etc/vmware/hostd/vmAutoStart.xml

 
    <_length>1
    <_type>vim.host.AutoStartManager.AutoPowerInfo[]
    
      <_type>vim.host.AutoStartManager.AutoPowerInfo
     
        <_type>vim.VirtualMachine
        2
     
      PowerOn
      15
      1
      systemDefault
      0
      systemDefault
   
 
 
    <_type>vim.host.AutoStartManager.SystemDefaults
    true
    120
    PowerOff
    120
    false
 



We could use command to check too
# vim-cmd   hostsvc/autostartmanager/get_autostartseq
(vim.host.AutoStartManager.AutoPowerInfo) [
   (vim.host.AutoStartManager.AutoPowerInfo) {
      dynamicType =
      key = 'vim.VirtualMachine:2', 
      startOrder = 1, 
      startDelay = 15, 
      waitForHeartbeat = "systemDefault", 
      startAction = "PowerOn", 
      stopDelay = 0, 
      stopAction = "systemDefault", 
   }
]




~ enjoy it

^__^

No comments:

Post a Comment