class ESX::VM

Attributes

cpus[RW]
ethernet_cards_number[RW]
host[RW]
memory_size[RW]
name[RW]
virtual_disks_number[RW]
vm_object[RW]
vmid[RW]

Public Class Methods

wrap(vm,host) click to toggle source

Wraps a RbVmomi::VirtualMachine object

**This method should never be called manually.**

# File lib/esx.rb, line 479
def self.wrap(vm,host)
  _vm = VM.new
  _vm.name = vm.name
  ## HACK: for some reason vm.summary.config.memorySizeMB returns nil
  # under some conditions
  _vm.memory_size = vm.summary.config.memorySizeMB*1024*1024 rescue 0
  _vm.cpus = vm.summary.config.numCpu
  _vm.ethernet_cards_number = vm.summary.config.numEthernetCards
  _vm.virtual_disks_number = vm.summary.config.numVirtualDisks
  _vm.vm_object = vm
  _vm.host = host
  _vm.vmid = vm.to_s.scan(/\"([0-9]+)\"/).flatten.first
  _vm
end

Public Instance Methods

destroy() click to toggle source

Destroy the VirtualMaching removing it from the inventory and deleting the disk files

# File lib/esx.rb, line 521
def destroy
  #disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
  unless host.free_license
    vm_object.Destroy_Task.wait_for_completion
  else
    host.remote_command "vim-cmd vmsvc/power.off #{vmid}"
    host.remote_command "vim-cmd vmsvc/destroy #{vmid}"
  end
end
guest_info() click to toggle source
# File lib/esx.rb, line 539
def guest_info
  GuestInfo.wrap(vm_object.guest)
end
ip_address() click to toggle source

Shortcut to GuestInfo.ip_address

# File lib/esx.rb, line 546
def ip_address
  guest_info.ip_address
end
nics() click to toggle source
# File lib/esx.rb, line 550
def nics
  list = []
  vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).each do |n|
    list << NetworkInterface.wrap(n)
  end
  list
end
power_off() click to toggle source

Power Off a VM

# File lib/esx.rb, line 511
def power_off
  unless host.free_license
    vm_object.PowerOffVM_Task.wait_for_completion
  else
    host.remote_command "vim-cmd vmsvc/power.off #{vmid}"
  end
end
power_on() click to toggle source

Power On a VM

# File lib/esx.rb, line 502
def power_on
  unless host.free_license
    vm_object.PowerOnVM_Task.wait_for_completion
  else
    host.remote_command "vim-cmd vmsvc/power.on #{vmid}"
  end
end
power_state() click to toggle source

Returns the state of the VM as a string 'poweredOff', 'poweredOn'

# File lib/esx.rb, line 497
def power_state
  vm_object.summary.runtime.powerState
end
reset() click to toggle source
# File lib/esx.rb, line 531
def reset
  unless host.free_license
    vm_object.ResetVM_Task.wait_for_completion
  else
    host.remote_command "vim-cmd vmsvc/power.reset #{vmid}"
  end
end