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.



274
275
276
# File 'lib/esx.rb', line 274

def cpus
  @cpus
end

#ethernet_cards_numberObject

Returns the value of attribute ethernet_cards_number.



274
275
276
# File 'lib/esx.rb', line 274

def ethernet_cards_number
  @ethernet_cards_number
end

#memory_sizeObject

Returns the value of attribute memory_size.



274
275
276
# File 'lib/esx.rb', line 274

def memory_size
  @memory_size
end

#nameObject

Returns the value of attribute name.



275
276
277
# File 'lib/esx.rb', line 275

def name
  @name
end

#virtual_disks_numberObject

Returns the value of attribute virtual_disks_number.



275
276
277
# File 'lib/esx.rb', line 275

def virtual_disks_number
  @virtual_disks_number
end

#vm_objectObject

Returns the value of attribute vm_object.



275
276
277
# File 'lib/esx.rb', line 275

def vm_object
  @vm_object
end

Class Method Details

.wrap(vm) ⇒ Object

Wraps a RbVmomi::VirtualMachine object

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



281
282
283
284
285
286
287
288
289
290
# File 'lib/esx.rb', line 281

def self.wrap(vm)
  _vm = VM.new
  _vm.name = vm.name
  _vm.memory_size = vm.summary.config.memorySizeMB.megabytes.to.bytes
  _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

This operation does not destroy VM disks



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/esx.rb', line 313

def destroy
  disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
  #disks.select { |x| x.backing.parent == nil }.each do |disk|
  #  spec = {
  #    :deviceChange => [
  #      {
  #        :operation => :remove,
  #        :device => disk
  #      }
  #    ]
  #  }
  #  vm_object.ReconfigVM_Task(:spec => spec).wait_for_completion
  #end
  vm_object.Destroy_Task.wait_for_completion
end

#guest_infoObject



329
330
331
# File 'lib/esx.rb', line 329

def guest_info
  GuestInfo.wrap(vm_object.guest)
end

#ip_addressObject

Shortcut to GuestInfo.ip_address



336
337
338
# File 'lib/esx.rb', line 336

def ip_address
  guest_info.ip_address
end

#power_offObject

Power Off a VM



305
306
307
# File 'lib/esx.rb', line 305

def power_off
  vm_object.PowerOffVM_Task.wait_for_completion
end

#power_onObject

Power On a VM



300
301
302
# File 'lib/esx.rb', line 300

def power_on
  vm_object.PowerOnVM_Task.wait_for_completion
end

#power_stateObject

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



295
296
297
# File 'lib/esx.rb', line 295

def power_state
  vm_object.summary.runtime.powerState
end