Class: ESX::VM
- Inherits:
-
Object
- Object
- ESX::VM
- Defined in:
- lib/esx.rb
Instance Attribute Summary collapse
-
#cpus ⇒ Object
Returns the value of attribute cpus.
-
#ethernet_cards_number ⇒ Object
Returns the value of attribute ethernet_cards_number.
-
#host ⇒ Object
Returns the value of attribute host.
-
#memory_size ⇒ Object
Returns the value of attribute memory_size.
-
#name ⇒ Object
Returns the value of attribute name.
-
#virtual_disks_number ⇒ Object
Returns the value of attribute virtual_disks_number.
-
#vm_object ⇒ Object
Returns the value of attribute vm_object.
-
#vmid ⇒ Object
Returns the value of attribute vmid.
Class Method Summary collapse
-
.wrap(vm, host) ⇒ Object
Wraps a RbVmomi::VirtualMachine object.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy the VirtualMaching removing it from the inventory and deleting the disk files.
- #guest_info ⇒ Object
-
#ip_address ⇒ Object
Shortcut to GuestInfo.ip_address.
- #nics ⇒ Object
-
#power_off ⇒ Object
Power Off a VM.
-
#power_on ⇒ Object
Power On a VM.
-
#power_state ⇒ Object
Returns the state of the VM as a string ‘poweredOff’, ‘poweredOn’.
- #reset ⇒ Object
Instance Attribute Details
#cpus ⇒ Object
Returns the value of attribute cpus.
472 473 474 |
# File 'lib/esx.rb', line 472 def cpus @cpus end |
#ethernet_cards_number ⇒ Object
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 |
#host ⇒ Object
Returns the value of attribute host.
473 474 475 |
# File 'lib/esx.rb', line 473 def host @host end |
#memory_size ⇒ Object
Returns the value of attribute memory_size.
472 473 474 |
# File 'lib/esx.rb', line 472 def memory_size @memory_size end |
#name ⇒ Object
Returns the value of attribute name.
473 474 475 |
# File 'lib/esx.rb', line 473 def name @name end |
#virtual_disks_number ⇒ Object
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_object ⇒ Object
Returns the value of attribute vm_object.
473 474 475 |
# File 'lib/esx.rb', line 473 def vm_object @vm_object end |
#vmid ⇒ Object
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
#destroy ⇒ Object
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_info ⇒ Object
539 540 541 |
# File 'lib/esx.rb', line 539 def guest_info GuestInfo.wrap(vm_object.guest) end |
#ip_address ⇒ Object
Shortcut to GuestInfo.ip_address
546 547 548 |
# File 'lib/esx.rb', line 546 def ip_address guest_info.ip_address end |
#nics ⇒ Object
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_off ⇒ Object
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_on ⇒ Object
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_state ⇒ Object
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 |
#reset ⇒ Object
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 |