Module: Vagrant

Defined in:
lib/vagrant/errors.rb,
lib/vagrant.rb,
lib/vagrant/ui.rb,
lib/vagrant/box.rb,
lib/vagrant/cli.rb,
lib/vagrant/util.rb,
lib/vagrant/hosts.rb,
lib/vagrant/action.rb,
lib/vagrant/config.rb,
lib/vagrant/plugin.rb,
lib/vagrant/machine.rb,
lib/vagrant/version.rb,
lib/vagrant/registry.rb,
lib/vagrant/util/ssh.rb,
lib/vagrant/config/v1.rb,
lib/vagrant/config/v2.rb,
lib/vagrant/plugin/v1.rb,
lib/vagrant/plugin/v2.rb,
lib/vagrant/util/busy.rb,
lib/vagrant/util/which.rb,
lib/vagrant/action/hook.rb,
lib/vagrant/downloaders.rb,
lib/vagrant/environment.rb,
lib/vagrant/util/counter.rb,
lib/vagrant/action/runner.rb,
lib/vagrant/action/warden.rb,
lib/vagrant/config/loader.rb,
lib/vagrant/machine_state.rb,
lib/vagrant/util/platform.rb,
lib/vagrant/action/builder.rb,
lib/vagrant/box_collection.rb,
lib/vagrant/config/v1/root.rb,
lib/vagrant/config/v2/root.rb,
lib/vagrant/config/v2/util.rb,
lib/vagrant/plugin/v1/host.rb,
lib/vagrant/plugin/v2/host.rb,
lib/vagrant/util/file_mode.rb,
lib/vagrant/util/retryable.rb,
lib/vagrant/util/safe_exec.rb,
lib/vagrant/util/safe_puts.rb,
lib/vagrant/plugin/v1/guest.rb,
lib/vagrant/plugin/v2/guest.rb,
lib/vagrant/util/network_ip.rb,
lib/vagrant/util/subprocess.rb,
lib/vagrant/config/container.rb,
lib/vagrant/config/v1/loader.rb,
lib/vagrant/config/v2/loader.rb,
lib/vagrant/downloaders/base.rb,
lib/vagrant/downloaders/file.rb,
lib/vagrant/downloaders/http.rb,
lib/vagrant/plugin/v1/config.rb,
lib/vagrant/plugin/v1/errors.rb,
lib/vagrant/plugin/v1/plugin.rb,
lib/vagrant/plugin/v2/config.rb,
lib/vagrant/plugin/v2/errors.rb,
lib/vagrant/plugin/v2/plugin.rb,
lib/vagrant/plugin/v1/command.rb,
lib/vagrant/plugin/v1/manager.rb,
lib/vagrant/plugin/v2/command.rb,
lib/vagrant/plugin/v2/manager.rb,
lib/vagrant/util/is_port_open.rb,
lib/vagrant/action/builtin/nfs.rb,
lib/vagrant/plugin/v1/provider.rb,
lib/vagrant/plugin/v2/provider.rb,
lib/vagrant/action/builtin/call.rb,
lib/vagrant/action/builtin/lock.rb,
lib/vagrant/config/version_base.rb,
lib/vagrant/plugin/v2/components.rb,
lib/vagrant/plugin/v1/provisioner.rb,
lib/vagrant/plugin/v2/provisioner.rb,
lib/vagrant/action/builtin/box_add.rb,
lib/vagrant/action/builtin/confirm.rb,
lib/vagrant/action/builtin/env_set.rb,
lib/vagrant/action/builtin/ssh_run.rb,
lib/vagrant/action/general/package.rb,
lib/vagrant/config/v1/dummy_config.rb,
lib/vagrant/config/v2/dummy_config.rb,
lib/vagrant/plugin/v1/communicator.rb,
lib/vagrant/plugin/v2/communicator.rb,
lib/vagrant/util/template_renderer.rb,
lib/vagrant/action/builtin/ssh_exec.rb,
lib/vagrant/action/builtin/provision.rb,
lib/vagrant/util/line_ending_helpers.rb,
lib/vagrant/util/stacked_proc_runner.rb,
lib/vagrant/util/string_block_editor.rb,
lib/vagrant/util/scoped_hash_override.rb,
lib/vagrant/action/builtin/set_hostname.rb,
lib/vagrant/action/builtin/graceful_halt.rb,
lib/vagrant/action/builtin/handle_box_url.rb,
lib/vagrant/util/ansi_escape_code_remover.rb,
lib/vagrant/action/builtin/config_validate.rb,
lib/vagrant/util/hash_with_indifferent_access.rb,
lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb

Overview

This file contains all the errors that the V2 plugin interface may throw.

Defined Under Namespace

Modules: Action, Config, Downloaders, Errors, Hosts, Plugin, UI, Util Classes: Box, BoxCollection, CLI, Environment, Machine, MachineState, Registry

Constant Summary collapse

PLUGIN_COMPONENTS =

These are the various plugin versions and their components in a lazy loaded Hash-like structure.

Registry.new.tap do |c|
  c.register(:"1")                  { Plugin::V1::Plugin }
  c.register([:"1", :command])      { Plugin::V1::Command }
  c.register([:"1", :communicator]) { Plugin::V1::Communicator }
  c.register([:"1", :config])       { Plugin::V1::Config }
  c.register([:"1", :guest])        { Plugin::V1::Guest }
  c.register([:"1", :host])         { Plugin::V1::Host }
  c.register([:"1", :provider])     { Plugin::V1::Provider }
  c.register([:"1", :provisioner])  { Plugin::V1::Provisioner }

  c.register(:"2")                  { Plugin::V2::Plugin }
  c.register([:"2", :command])      { Plugin::V2::Command }
  c.register([:"2", :communicator]) { Plugin::V2::Communicator }
  c.register([:"2", :config])       { Plugin::V2::Config }
  c.register([:"2", :guest])        { Plugin::V2::Guest }
  c.register([:"2", :host])         { Plugin::V2::Host }
  c.register([:"2", :provider])     { Plugin::V2::Provider }
  c.register([:"2", :provisioner])  { Plugin::V2::Provisioner }
end
VERSION =

This will always be up to date with the current version of Vagrant, since it is used to generate the gemspec and is also the source of the version for ‘vagrant -v`

"1.1.4"

Class Method Summary collapse

Class Method Details

.configure(version, &block) ⇒ Object

Configure a Vagrant environment. The version specifies the version of the configuration that is expected by the block. The block, based on that version, configures the environment.

Note that the block isn’t run immediately. Instead, the configuration block is stored until later, and is run when an environment is loaded.

Parameters:

  • version (String)

    Version of the configuration



128
129
130
# File 'lib/vagrant.rb', line 128

def self.configure(version, &block)
  Config.run(version, &block)
end

.in_installer?Boolean

This returns a true/false showing whether we’re running from the environment setup by the Vagrant installers.

Returns:

  • (Boolean)


110
111
112
# File 'lib/vagrant.rb', line 110

def self.in_installer?
  !!ENV["VAGRANT_INSTALLER_ENV"]
end

.plugin(version, component = nil) ⇒ Class

Returns a superclass to use when creating a plugin for Vagrant. Given a specific version, this returns a proper superclass to use to register plugins for that version.

Optionally, if you give a specific component, then it will return the proper superclass for that component as well.

Plugins and plugin components should subclass the classes returned by this method. This method lets Vagrant core control these superclasses and change them over time without affecting plugins. For example, if the V1 superclass happens to be “Vagrant::V1,” future versions of Vagrant may move it to “Vagrant::Plugins::V1” and plugins will not be affected.

Parameters:

  • version (String)
  • component (String) (defaults to: nil)

Returns:

  • (Class)

Raises:

  • (ArgumentError)


149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/vagrant.rb', line 149

def self.plugin(version, component=nil)
  # Build up the key and return a result
  key    = version.to_s.to_sym
  key    = [key, component.to_s.to_sym] if component
  result = PLUGIN_COMPONENTS.get(key)

  # If we found our component then we return that
  return result if result

  # If we didn't find a result, then raise an exception, depending
  # on if we got a component or not.
  raise ArgumentError, "Plugin superclass not found for version/component: " +
    "#{version} #{component}"
end

.require_plugin(name) ⇒ Object

This should be used instead of Ruby’s built-in ‘require` in order to load a Vagrant plugin. This will load the given plugin by first doing a normal `require`, giving a nice error message if things go wrong, and second by verifying that a Vagrant plugin was actually defined in the process.

Parameters:

  • name (String)

    Name of the plugin to load.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/vagrant.rb', line 171

def self.require_plugin(name)
  if ENV["VAGRANT_NO_PLUGINS"]
    logger = Log4r::Logger.new("vagrant::root")
    logger.warn("VAGRANT_NO_PLUGINS is set, not loading 3rd party plugin: #{name}")
    return
  end

  # Redirect stdout/stderr so that we can output it in our own way.
  previous_stderr = $stderr
  previous_stdout = $stdout
  $stderr = StringIO.new
  $stdout = StringIO.new

  # Attempt the normal require
  begin
    require name
  rescue Exception => e
    # Since this is a rare case, we create a one-time logger here
    # in order to output the error
    logger = Log4r::Logger.new("vagrant::root")
    logger.error("Failed to load plugin: #{name}")
    logger.error(" -- Error: #{e.inspect}")
    logger.error(" -- Backtrace:")
    logger.error(e.backtrace.join("\n"))

    # If it is a LoadError we first try to see if it failed loading
    # the top-level entrypoint. If so, then we report a different error.
    if e.is_a?(LoadError)
      # Parse the message in order to get what failed to load, and
      # add some extra protection around if the message is different.
      parts = e.to_s.split(" -- ", 2)
      if parts.length == 2 && parts[1] == name
        raise Errors::PluginLoadError, :plugin => name
      end
    end

    # Get the string data out from the stdout/stderr captures
    stderr = $stderr.string
    stdout = $stdout.string
    if !stderr.empty? || !stdout.empty?
      raise Errors::PluginLoadFailedWithOutput,
        :plugin => name,
        :stderr => stderr,
        :stdout => stdout
    end

    # And raise an error itself
    raise Errors::PluginLoadFailed,
      :plugin => name
  end
ensure
  $stderr = previous_stderr if previous_stderr
  $stdout = previous_stdout if previous_stdout
end

.source_rootObject

The source root is the path to the root directory of the Vagrant gem.



116
117
118
# File 'lib/vagrant.rb', line 116

def self.source_root
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
end