Class: Vmesh::Machine
- Inherits:
-
Object
- Object
- Vmesh::Machine
- Defined in:
- lib/vmesh/machine.rb
Constant Summary collapse
- @@states =
{'on' => 'PowerOnVM_Task', 'off' => 'PowerOffVM_Task', 'reset' => 'ResetVM_Task', 'suspend' => 'SuspendVM_Task', 'destroy' => 'Destroy_Task' }
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#vm ⇒ Object
Returns the value of attribute vm.
Class Method Summary collapse
Instance Method Summary collapse
- #annotation ⇒ Object
- #annotation=(note) ⇒ Object
- #clone_to(vm_name, vm_folder = @vm.parent, datastore = nil, custom_spec = nil, pool = nil, config = {}) ⇒ Object
- #command ⇒ Object
- #describe ⇒ Object
-
#initialize(vm) ⇒ Machine
constructor
A new instance of Machine.
- #ipAddress ⇒ Object
- #power(desired_state) ⇒ Object
- #revert ⇒ Object
- #template? ⇒ Boolean
Constructor Details
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/vmesh/machine.rb', line 6 def name @name end |
#vm ⇒ Object
Returns the value of attribute vm.
6 7 8 |
# File 'lib/vmesh/machine.rb', line 6 def vm @vm end |
Class Method Details
.get(vs_manager, datacenter_name, name) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/vmesh/machine.rb', line 14 def self.get(vs_manager, datacenter_name, name) Vmesh::logger.debug "looking for vm #{name} at dc #{datacenter_name}." vm = vs_manager.vm_root_folder.traverse(name) vm or raise "unable to find machine #{name} at #{datacenter_name}" Machine.new vm end |
.valid_states ⇒ Object
21 22 23 |
# File 'lib/vmesh/machine.rb', line 21 def self.valid_states @@states.keys end |
Instance Method Details
#annotation ⇒ Object
67 68 69 |
# File 'lib/vmesh/machine.rb', line 67 def annotation @vm.config.annotation end |
#annotation=(note) ⇒ Object
71 72 73 74 |
# File 'lib/vmesh/machine.rb', line 71 def annotation=(note) Vmesh::logger.debug "Adding annotation \"#{note}\" to the vm." @vm.ReconfigVM_Task(:spec => RbVmomi::VIM.VirtualMachineConfigSpec(:annotation => note)).wait_for_completion end |
#clone_to(vm_name, vm_folder = @vm.parent, datastore = nil, custom_spec = nil, pool = nil, config = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vmesh/machine.rb', line 52 def clone_to (vm_name, vm_folder = @vm.parent, datastore = nil, custom_spec = nil, pool = nil, config = {}) Vmesh::logger.info "Cloning #{@name} to a new vm named #{vm_name} in folder #{vm_folder}." ds = datastore.ds unless datastore.nil? relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec(:datastore => ds, :diskMoveType => :moveChildMostDiskBacking, :pool => pool) clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocateSpec, :powerOn => false, :template => false) clone_spec.customization = custom_spec.spec if custom_spec Vmesh::logger.debug "Custom spec #{custom_spec} supplied, config #{config.inspect}." Machine.new(@vm.CloneVM_Task(:folder => vm_folder, :name => vm_name, :spec => clone_spec, :numCPUs => config[:numCPUs], :memoryMB => config[:memoryMB]).wait_for_completion) end |
#command ⇒ Object
36 37 38 |
# File 'lib/vmesh/machine.rb', line 36 def command raise NotImplementedError end |
#describe ⇒ Object
40 41 42 |
# File 'lib/vmesh/machine.rb', line 40 def describe raise NotImplementedError end |
#ipAddress ⇒ Object
48 49 50 |
# File 'lib/vmesh/machine.rb', line 48 def ipAddress @vm.guest.ipAddress end |
#power(desired_state) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/vmesh/machine.rb', line 25 def power(desired_state) p "Found" if @@states.has_key? desired_state p "NOT Found" unless @@states.has_key? desired_state raise ArgumentError, "Invalid desired power state" unless @@states.has_key? desired_state @vm.send(@@states[desired_state]) end |
#revert ⇒ Object
32 33 34 |
# File 'lib/vmesh/machine.rb', line 32 def revert @vm.RevertToCurrentSnapshot_Task.wait_for_completion end |
#template? ⇒ Boolean
44 45 46 |
# File 'lib/vmesh/machine.rb', line 44 def template? raise NotImplementedError end |