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.



472
473
474
# File 'lib/esx.rb', line 472

def cpus
  @cpus
end

#ethernet_cards_numberObject

Returns the value of attribute ethernet_cards_number.



472
473
474
# File 'lib/esx.rb', line 472

def ethernet_cards_number
  @ethernet_cards_number
end

#hostObject

Returns the value of attribute host.



473
474
475
# File 'lib/esx.rb', line 473

def host
  @host
end

#memory_sizeObject

Returns the value of attribute memory_size.



472
473
474
# File 'lib/esx.rb', line 472

def memory_size
  @memory_size
end

#nameObject

Returns the value of attribute name.



473
474
475
# File 'lib/esx.rb', line 473

def name
  @name
end

#virtual_disks_numberObject

Returns the value of attribute virtual_disks_number.



473
474
475
# File 'lib/esx.rb', line 473

def virtual_disks_number
  @virtual_disks_number
end

#vm_objectObject

Returns the value of attribute vm_object.



473
474
475
# File 'lib/esx.rb', line 473

def vm_object
  @vm_object
end

#vmidObject

Returns the value of attribute vmid.



472
473
474
# File 'lib/esx.rb', line 472

def vmid
  @vmid
end

Class Method Details

.wrap(vm, host) ⇒ Object

Wraps a RbVmomi::VirtualMachine object

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



479
480
481
482
483
484
485
486
487
488
489
490
491
492
# 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

Instance Method Details

#destroyObject

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



521
522
523
524
525
526
527
528
529
# 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_infoObject



539
540
541
# File 'lib/esx.rb', line 539

def guest_info
  GuestInfo.wrap(vm_object.guest)
end

#ip_addressObject

Shortcut to GuestInfo.ip_address



546
547
548
# File 'lib/esx.rb', line 546

def ip_address
  guest_info.ip_address
end

#nicsObject



550
551
552
553
554
555
556
# 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_offObject

Power Off a VM



511
512
513
514
515
516
517
# 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_onObject

Power On a VM



502
503
504
505
506
507
508
# 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_stateObject

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



497
498
499
# File 'lib/esx.rb', line 497

def power_state
  vm_object.summary.runtime.powerState
end

#resetObject



531
532
533
534
535
536
537
# 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