Class: Vagrant::VM

Inherits:
Actions::Runner show all
Includes:
Util
Defined in:
lib/vagrant/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

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

Constructor Details

#initialize(vm = nil) ⇒ VM

Returns a new instance of VM.



19
20
21
# File 'lib/vagrant/vm.rb', line 19

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

Instance Attribute Details

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#fromObject

Returns the value of attribute from.



7
8
9
# File 'lib/vagrant/vm.rb', line 7

def from
  @from
end

#vmObject

Returns the value of attribute vm.



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

def vm
  @vm
end

Class Method Details

.find(uuid) ⇒ Object

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



12
13
14
15
16
# File 'lib/vagrant/vm.rb', line 12

def find(uuid)
  vm = VirtualBox::VM.find(uuid)
  return nil if vm.nil?
  new(vm)
end

Instance Method Details

#destroyObject



43
44
45
# File 'lib/vagrant/vm.rb', line 43

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

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



31
32
33
34
35
# File 'lib/vagrant/vm.rb', line 31

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)


59
# File 'lib/vagrant/vm.rb', line 59

def powered_off?; @vm.powered_off? end

#reload!Object



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

def reload!
  @vm = VirtualBox::VM.find(@vm.uuid)
end

#resumeObject



51
52
53
# File 'lib/vagrant/vm.rb', line 51

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

#saved?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/vagrant/vm.rb', line 55

def saved?
  @vm.saved?
end

#startObject



37
38
39
40
41
# File 'lib/vagrant/vm.rb', line 37

def start
  return if @vm.running?

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

#suspendObject



47
48
49
# File 'lib/vagrant/vm.rb', line 47

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

#uuidObject



23
24
25
# File 'lib/vagrant/vm.rb', line 23

def uuid
  vm ? vm.uuid : nil
end