Class: Vmesh::Machine

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vm) ⇒ Machine

Returns a new instance of Machine.



9
10
11
12
# File 'lib/vmesh/machine.rb', line 9

def initialize(vm)
  Vmesh::logger.debug "New machine wrapper object with #{vm}"
  @vm = vm
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/vmesh/machine.rb', line 6

def name
  @name
end

#vmObject

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_statesObject



21
22
23
# File 'lib/vmesh/machine.rb', line 21

def self.valid_states
  @@states.keys
end

Instance Method Details

#annotationObject



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

#commandObject

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/vmesh/machine.rb', line 36

def command
  raise NotImplementedError
end

#describeObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/vmesh/machine.rb', line 40

def describe
  raise NotImplementedError
end

#ipAddressObject



48
49
50
# File 'lib/vmesh/machine.rb', line 48

def ipAddress
  @vm.guest.ipAddress
end

#power(desired_state) ⇒ Object

Raises:

  • (ArgumentError)


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

#revertObject



32
33
34
# File 'lib/vmesh/machine.rb', line 32

def revert
  @vm.RevertToCurrentSnapshot_Task.wait_for_completion
end

#template?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/vmesh/machine.rb', line 44

def template?
  raise NotImplementedError
end