Class: Vagrant::Guest
- Inherits:
-
Object
- Object
- Vagrant::Guest
- 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
- #capability(*args) ⇒ Object
-
#detect! ⇒ Object
This will detect the proper guest OS for the machine and set up the class to actually execute capabilities.
-
#initialize(machine, guests, capabilities) ⇒ Guest
constructor
A new instance of Guest.
-
#name ⇒ Symbol
Returns the specified or detected guest type name.
-
#ready? ⇒ Boolean
This returns whether the guest is ready to work.
Methods included from CapabilityHost
#capability?, #capability_host_chain, #initialize_capabilities!
Constructor Details
#initialize(machine, guests, capabilities) ⇒ Guest
Returns a new instance of Guest.
28 29 30 31 32 |
# File 'lib/vagrant/guest.rb', line 28 def initialize(machine, guests, capabilities) @capabilities = capabilities @guests = guests @machine = machine end |
Instance Method Details
#capability(*args) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vagrant/guest.rb', line 46 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.
36 37 38 39 40 41 42 43 |
# File 'lib/vagrant/guest.rb', line 36 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 |
#name ⇒ Symbol
Returns the specified or detected guest type name.
61 62 63 |
# File 'lib/vagrant/guest.rb', line 61 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.
70 71 72 |
# File 'lib/vagrant/guest.rb', line 70 def ready? !!capability_host_chain end |