Friday, January 21, 2011

The power of the vim-cmd command

Despite not having a service console, esxi has a lot of commands available. Want something done from the command line NOT using the esxcfg command? No problem. What follows are examples of the capabilities of the vim-cmd command when a virtual machine is concerned.

 # vim-cmd vmsvc

Commands available under vmsvc/:
acquiremksticket           get.configoption
connect                          get.datastores            power.on
convert.toTemplate       get.disabledmethods       power.reboot
convert.toVm                 get.environment           power.reset
createdummyvm            get.filelayout            power.shutdown
destroy                           get.guest                 power.suspend
device.connection          get.guestheartbeatStatus  reload
device.connusbdev         get.managedentitystatus   setscreenres
device.disconnusbdev    get.networks              snapshot.create
device.diskadd               get.runtime               snapshot.dumpoption
device.diskaddexisting   get.snapshotinfo          snapshot.get
device.diskremove          get.summary               snapshot.remove
device.getdevices            get.tasklist              snapshot.removeall
device.toolsSyncSet       getallvms                 snapshot.revert
device.vmiadd                gethostconstraints        snapshot.setoption
device.vmiremove          login                     tools.cancelinstall
devices.createnic           logout                    tools.install
get.capability                message                   tools.upgrade
get.config                      power.getstate            unregister
get.config.cpuidmask    power.hibernate           upgrade

List all of the vms registered in that esxi host:

# vim-cmd vmsvc/getallvms

Vmid        Name                            File                          Guest OS      Version       Annotation
32     WinXP-ibex01-a   [SharedVMs] WinXP-ibex01-a/WinXP-ibex01-a.vmx   winXPProGuest   vmx-07    OneSizeXP-R40c.vmdk
64     WinXP-ibex01-c   [SharedVMs] WinXP-ibex01-c/WinXP-ibex01-c.vmx   winXPProGuest   vmx-07    OneSizeXP-R40c.vmdk

How to halt a virtual machine:

# vim-cmd vmsvc/ 32


# vim-cmd vmsvc/power.shutdown 32

Powering on VM:

# vim-cmd vmsvc/power.on 32

Reboot a VM:

# vim-cmd vmsvc/power.reboot 32
(vim.fault.ToolsUnavailable) {
   dynamicType = <unset>,
   faultCause = (vmodl.MethodFault) null,
   msg = "Cannot complete operation because VMware Tools is not running in this virtual machine.",

Get network related information:

# vim-cmd vmsvc/get.networks 32

(vim.Network.Summary) {
   dynamicType = <unset>,
   network = 'vim.dvs.DistributedVirtualPortgroup:DVPG-a6 77 07 50 43 f3 38 cd-01 b9 dd 92 d3 d4 e7 b0-dvportgroup-146',
   name = "Production",
   accessible = true,
   ipPoolName = "",

Get storage related information about a vm:

# vim-cmd vmsvc/get.datastores 32

name                 SharedVMs
url                  /vmfs/volumes/4d333ff0-28d4682c-49ea-00237da51830
capacity             145492017152
freeSpace            31078744064
accessible           1
type                 VMFS
multipleHostAccess   <unset>

Get snapshot related information about a vm:

# vim-cmd vmsvc/snapshot.get 32

Get Snapshot:
--Snapshot Name        : 01%2f20%2f2011 15:04:40
--Snapshot Desciption  :
--Snapshot Created On  : 1/20/2011 14:59:11
--Snapshot State       : powered on

Remove all snapshots for that vm:

# vim-cmd vmsvc/snapshot.removeall 32

# vim-cmd vmsvc/snapshot.get 32

Create a snapshot for that vm:

# vim-cmd vmsvc/snapshot.create 32 snappy

# vim-cmd vmsvc/snapshot.get 32

Get Snapshot:
--Snapshot Name        : snappy
--Snapshot Desciption  :
--Snapshot Created On  : 1/20/2011 20:0:9
--Snapshot State       : powered off

Remove just one snapshot:

# vim-cmd vmsvc/snapshot.remove 32 snappy

No comments:

Post a Comment