Class: Vagrant::Guest

Inherits:
Object
  • Object
show all
Includes:
CapabilityHost
Defined in:
lib/vagrant/guest.rb,
lib/vagrant/guest/remote.rb

Overview

This class handles guest-OS specific interactions with a machine. It is primarily responsible for detecting the proper guest OS implementation and then delegating capabilities.

Vagrant has many tasks which require specific guest OS knowledge. These are implemented using a guest/capability system. Various plugins register as "guests" which determine the underlying OS of the system. Then, "guest capabilities" register themselves for a specific OS (one or more), and these capabilities are called.

Example capabilities might be "mount_virtualbox_shared_folder" or "configure_networks".

This system allows for maximum flexibility and pluginability for doing guest OS specific operations.

Defined Under Namespace

Modules: Remote

Instance Method Summary collapse

Methods included from CapabilityHost

#capability?, #capability_host_chain, #initialize_capabilities!

Constructor Details

#initialize(machine, guests, capabilities) ⇒ Guest

Returns a new instance of Guest.



29
30
31
32
33
# File 'lib/vagrant/guest.rb', line 29

def initialize(machine, guests, capabilities)
  @capabilities = capabilities
  @guests       = guests
  @machine      = machine
end

Instance Method Details

#capability(*args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vagrant/guest.rb', line 47

def capability(*args)
  super
rescue Errors::CapabilityNotFound => e
  raise Errors::GuestCapabilityNotFound,
    cap: e.extra_data[:cap],
    guest: name
rescue Errors::CapabilityInvalid => e
  raise Errors::GuestCapabilityInvalid,
    cap: e.extra_data[:cap],
    guest: name
end

#detect!Object

This will detect the proper guest OS for the machine and set up the class to actually execute capabilities.



37
38
39
40
41
42
43
44
# File 'lib/vagrant/guest.rb', line 37

def detect!
  guest_name = @machine.config.vm.guest
  initialize_capabilities!(guest_name, @guests, @capabilities, @machine)
rescue Errors::CapabilityHostExplicitNotDetected => e
  raise Errors::GuestExplicitNotDetected, value: e.extra_data[:value]
rescue Errors::CapabilityHostNotDetected
  raise Errors::GuestNotDetected
end

#nameSymbol

Returns the specified or detected guest type name.

Returns:

  • (Symbol)


62
63
64
# File 'lib/vagrant/guest.rb', line 62

def name
  capability_host_chain[0][0]
end

#ready?Boolean

This returns whether the guest is ready to work. If this returns false, then #detect! should be called in order to detect the guest OS.

Returns:

  • (Boolean)


71
72
73
# File 'lib/vagrant/guest.rb', line 71

def ready?
  !!capability_host_chain
end