class Vagrant::Guest
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.
Public Class Methods
# File lib/vagrant/guest.rb, line 26 def initialize(machine, guests, capabilities) @capabilities = capabilities @guests = guests @machine = machine end
Public Instance Methods
See {CapabilityHost#capability}
Vagrant::CapabilityHost#capability
# File lib/vagrant/guest.rb, line 44 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
This will detect the proper guest OS for the machine and set up the class to actually execute capabilities.
# File lib/vagrant/guest.rb, line 34 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
Returns the specified or detected guest type name.
@return [Symbol]
# File lib/vagrant/guest.rb, line 59 def name capability_host_chain[0][0] end
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.
@return [Boolean]
# File lib/vagrant/guest.rb, line 68 def ready? !!capability_host_chain end