Class: Vagrant::Plugin::V2::Provider
- Inherits:
-
Object
- Object
- Vagrant::Plugin::V2::Provider
- Includes:
- CapabilityHost
- Defined in:
- lib/vagrant/plugin/v2/provider.rb
Overview
This is the base class for a provider for the V2 API. A provider is responsible for creating compute resources to match the needs of a Vagrant-configured system.
Direct Known Subclasses
Class Method Summary collapse
-
.installed? ⇒ Boolean
This is called early, before a machine is instantiated, to check if this provider is installed.
-
.usable?(raise_error = false) ⇒ Boolean
This is called early, before a machine is instantiated, to check if this provider is usable.
Instance Method Summary collapse
-
#_initialize(name, machine) ⇒ Object
This is an internal initialize function that should never be overridden.
-
#action(name) ⇒ Object
This should return an action callable for the given name.
-
#initialize(machine) ⇒ Provider
constructor
Initialize the provider to represent the given machine.
-
#machine_id_changed ⇒ Object
This method is called if the underlying machine ID changes.
-
#ssh_info ⇒ Hash
This should return a hash of information that explains how to SSH into the machine.
-
#state ⇒ MachineState
This should return the state of the machine within this provider.
Methods included from CapabilityHost
#capability, #capability?, #capability_host_chain, #initialize_capabilities!
Constructor Details
#initialize(machine) ⇒ Provider
Initialize the provider to represent the given machine.
49 50 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 49 def initialize(machine) end |
Class Method Details
.installed? ⇒ Boolean
This is called early, before a machine is instantiated, to check if this provider is installed. This should return true or false.
If the provider is not installed and Vagrant determines it is able to install this provider, then it will do so. Installation is done by calling Environment.install_provider.
If Environment.can_install_provider? returns false, then an error will be shown to the user.
39 40 41 42 43 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 39 def self.installed? # By default return true for backwards compat so all providers # continue to work. true end |
.usable?(raise_error = false) ⇒ Boolean
This is called early, before a machine is instantiated, to check if this provider is usable. This should return true or false.
If raise_error is true, then instead of returning false, this should raise an error with a helpful message about why this provider cannot be used.
24 25 26 27 28 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 24 def self.usable?(raise_error=false) # Return true by default for backwards compat since this was # introduced long after providers were being written. true end |
Instance Method Details
#_initialize(name, machine) ⇒ Object
This is an internal initialize function that should never be overridden. It is used to initialize some common internal state that is used in a provider.
107 108 109 110 111 112 113 114 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 107 def _initialize(name, machine) initialize_capabilities!( name.to_sym, { name.to_sym => [Class.new, nil] }, Vagrant.plugin("2").manager.provider_capabilities, machine, ) end |
#action(name) ⇒ Object
This should return an action callable for the given name.
57 58 59 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 57 def action(name) nil end |
#machine_id_changed ⇒ Object
This method is called if the underlying machine ID changes. Providers
can use this method to load in new data for the actual backing
machine or to realize that the machine is now gone (the ID can
become nil
). No parameters are given, since the underlying machine
is simply the machine instance given to this object. And no
return value is necessary.
67 68 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 67 def machine_id_changed end |
#ssh_info ⇒ Hash
This should return a hash of information that explains how to
SSH into the machine. If the machine is not at a point where
SSH is even possible, then nil
should be returned.
The general structure of this returned hash should be the following:
{
host: "1.2.3.4",
port: "22",
username: "mitchellh",
private_key_path: "/path/to/my/key"
}
Note: Vagrant only supports private key based authentication,
mainly for the reason that there is no easy way to exec into an
ssh
prompt with a password, whereas we can pass a private key
via commandline.
91 92 93 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 91 def ssh_info nil end |
#state ⇒ MachineState
This should return the state of the machine within this provider. The state must be an instance of MachineState. Please read the documentation of that class for more information.
100 101 102 |
# File 'lib/vagrant/plugin/v2/provider.rb', line 100 def state nil end |