Class: ESX::VM

Inherits:
Object
  • Object
show all
Defined in:
lib/esx.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cpusObject

Returns the value of attribute cpus.



420
421
422
# File 'lib/esx.rb', line 420

def cpus
  @cpus
end

#ethernet_cards_numberObject

Returns the value of attribute ethernet_cards_number.



420
421
422
# File 'lib/esx.rb', line 420

def ethernet_cards_number
  @ethernet_cards_number
end

#memory_sizeObject

Returns the value of attribute memory_size.



420
421
422
# File 'lib/esx.rb', line 420

def memory_size
  @memory_size
end

#nameObject

Returns the value of attribute name.



421
422
423
# File 'lib/esx.rb', line 421

def name
  @name
end

#virtual_disks_numberObject

Returns the value of attribute virtual_disks_number.



421
422
423
# File 'lib/esx.rb', line 421

def virtual_disks_number
  @virtual_disks_number
end

#vm_objectObject

Returns the value of attribute vm_object.



421
422
423
# File 'lib/esx.rb', line 421

def vm_object
  @vm_object
end

Class Method Details

.wrap(vm) ⇒ Object

Wraps a RbVmomi::VirtualMachine object

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



427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/esx.rb', line 427

def self.wrap(vm)
  _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
end

Instance Method Details

#destroyObject

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



459
460
461
462
# File 'lib/esx.rb', line 459

def destroy
  #disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
  vm_object.Destroy_Task.wait_for_completion
end

#guest_infoObject



468
469
470
# File 'lib/esx.rb', line 468

def guest_info
  GuestInfo.wrap(vm_object.guest)
end

#ip_addressObject

Shortcut to GuestInfo.ip_address



475
476
477
# File 'lib/esx.rb', line 475

def ip_address
  guest_info.ip_address
end

#nicsObject



479
480
481
482
483
484
485
# File 'lib/esx.rb', line 479

def nics
  list = []
  vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).each do |n|
    list << NetworkInterface.wrap(n)
  end
  list
end

#power_offObject

Power Off a VM



453
454
455
# File 'lib/esx.rb', line 453

def power_off
  vm_object.PowerOffVM_Task.wait_for_completion
end

#power_onObject

Power On a VM



448
449
450
# File 'lib/esx.rb', line 448

def power_on
  vm_object.PowerOnVM_Task.wait_for_completion
end

#power_stateObject

Returns the state of the VM as a string ‘poweredOff’, ‘poweredOn’



443
444
445
# File 'lib/esx.rb', line 443

def power_state
  vm_object.summary.runtime.powerState
end

#resetObject



464
465
466
# File 'lib/esx.rb', line 464

def reset
  vm_object.ResetVM_Task.wait_for_completion
end