Class: Tenderloin::VM

Inherits:
Actions::Runner show all
Includes:
Util
Defined in:
lib/tenderloin/vm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#error_and_exit, included, #logger, #wrap_output

Methods inherited from Actions::Runner

#action_klasses, #actions, #add_action, execute!, #execute!, #find_action, #invoke_around_callback, #invoke_callback

Constructor Details

#initialize(vm = nil) ⇒ VM

Returns a new instance of VM.



17
18
19
# File 'lib/tenderloin/vm.rb', line 17

def initialize(vm=nil)
  @vm_id = vm
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



6
7
8
# File 'lib/tenderloin/vm.rb', line 6

def from
  @from
end

#vm_idObject

Returns the value of attribute vm_id.



5
6
7
# File 'lib/tenderloin/vm.rb', line 5

def vm_id
  @vm_id
end

Class Method Details

.find(uuid) ⇒ Object

Finds a virtual machine by a given UUID and either returns a Tenderloin::VM object or returns nil.



11
12
13
14
# File 'lib/tenderloin/vm.rb', line 11

def find(uuid)
  # TODO - just validate the existence - there's no 'loading' needed
  new(uuid) if File.exists? File.join(Tenderloin::Env.vms_path, uuid, uuid + ".vmx")
end

Instance Method Details

#destroyObject



45
46
47
# File 'lib/tenderloin/vm.rb', line 45

def destroy
  execute!(Actions::VM::Destroy)
end

#fusion_vmObject



31
32
33
# File 'lib/tenderloin/vm.rb', line 31

def fusion_vm
  @fusion_vm ||= FusionVM.new(vmx_path) if vmx_path
end

#package(out_path, include_files = []) ⇒ Object



21
22
23
24
25
# File 'lib/tenderloin/vm.rb', line 21

def package(out_path, include_files=[])
  add_action(Actions::VM::Export)
  add_action(Actions::VM::Package, out_path, include_files)
  execute!
end

#powered_off?Boolean

Returns:

  • (Boolean)


61
# File 'lib/tenderloin/vm.rb', line 61

def powered_off?; @vm.powered_off? end

#resumeObject



53
54
55
# File 'lib/tenderloin/vm.rb', line 53

def resume
  execute!(Actions::VM::Resume)
end

#running?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/tenderloin/vm.rb', line 41

def running?
  fusion_vm.running?
end

#saved?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/tenderloin/vm.rb', line 57

def saved?
  @vm.saved?
end

#startObject



35
36
37
38
39
# File 'lib/tenderloin/vm.rb', line 35

def start
  return if running?

  execute!(Actions::VM::Start)
end

#suspendObject



49
50
51
# File 'lib/tenderloin/vm.rb', line 49

def suspend
  execute!(Actions::VM::Suspend)
end

#vmx_pathObject



27
28
29
# File 'lib/tenderloin/vm.rb', line 27

def vmx_path
  File.join(Tenderloin::Env.vms_path, @vm_id, @vm_id + ".vmx")
end