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

- (Object) cpus

Returns the value of attribute cpus



179
180
181
# File 'lib/esx.rb', line 179

def cpus
  @cpus
end

- (Object) ethernet_cards_number

Returns the value of attribute ethernet_cards_number



179
180
181
# File 'lib/esx.rb', line 179

def ethernet_cards_number
  @ethernet_cards_number
end

- (Object) memory_size

Returns the value of attribute memory_size



179
180
181
# File 'lib/esx.rb', line 179

def memory_size
  @memory_size
end

- (Object) name

Returns the value of attribute name



180
181
182
# File 'lib/esx.rb', line 180

def name
  @name
end

- (Object) virtual_disks_number

Returns the value of attribute virtual_disks_number



180
181
182
# File 'lib/esx.rb', line 180

def virtual_disks_number
  @virtual_disks_number
end

- (Object) vm_object

Returns the value of attribute vm_object



180
181
182
# File 'lib/esx.rb', line 180

def vm_object
  @vm_object
end

Class Method Details

+ (Object) wrap(vm)

Wraps a RbVmomi::VirtualMachine object

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



186
187
188
189
190
191
192
193
194
195
# File 'lib/esx.rb', line 186

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

- (Object) destroy

Destroy the VirtualMaching removing it from the inventory

This operation does not destroy VM disks



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/esx.rb', line 218

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

- (Object) power_off

Power Off a VM



210
211
212
# File 'lib/esx.rb', line 210

def power_off
  vm_object.PowerOffVM_Task.wait_for_completion
end

- (Object) power_on

Power On a VM



205
206
207
# File 'lib/esx.rb', line 205

def power_on
  vm_object.PowerOnVM_Task.wait_for_completion
end

- (Object) power_state

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



200
201
202
# File 'lib/esx.rb', line 200

def power_state
  vm_object.summary.runtime.powerState
end