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.



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

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

Instance Attribute Details

#fromObject

Returns the value of attribute from.



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

def from
  @from
end

#vmObject

Returns the value of attribute vm.



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

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.



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

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

Instance Method Details

#destroyObject



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

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

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



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

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)


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

def powered_off?; @vm.powered_off? end

#reload!Object



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

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

#resumeObject



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

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

#saved?Boolean

Returns:

  • (Boolean)


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

def saved?
  @vm.saved?
end

#startObject



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

def start
  return if @vm.running?

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

#suspendObject



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

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

#uuidObject



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

def uuid
  vm ? vm.uuid : nil
end