TODO:
env.lock
This file contains all of the internal errors in Vagrant's core commands, actions, etc.
This file contains all the errors that the V1 plugin interface may throw.
This file contains all the errors that the V2 plugin interface may throw.
This is the default endpoint of the Vagrant Cloud in use. API calls will be made to this for various functions of Vagrant that may require remote access.
@return [String]
These are the various plugin versions and their components in a lazy loaded Hash-like structure.
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`
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.
@param [String] version Version of the configuration
# File lib/vagrant.rb, line 136 def self.configure(version, &block) Config.run(version, &block) end
This checks if a plugin with the given name is installed. This can be used from the Vagrantfile to easily branch based on plugin availability.
# File lib/vagrant.rb, line 143 def self.has_plugin?(name) # We check the plugin names first because those are cheaper to check return true if plugin("2").manager.registered.any? { |p| p.name == name } # Now check the plugin gem names require "vagrant/plugin/manager" Plugin::Manager.instance.installed_specs.any? { |s| s.name == name } end
This returns a true/false showing whether we're running from the environment setup by the Vagrant installers.
@return [Boolean]
# File lib/vagrant/shared_helpers.rb, line 15 def self.in_installer? !!ENV["VAGRANT_INSTALLER_ENV"] end
Returns the path to the embedded directory of the Vagrant installer, if there is one (if we're running in an installer).
@return [String]
# File lib/vagrant/shared_helpers.rb, line 23 def self.installer_embedded_dir return nil if !Vagrant.in_installer? ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] end
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.
@param [String] version @param [String] component @return [Class]
# File lib/vagrant.rb, line 169 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
This returns whether or not 3rd party plugins should be loaded.
@return [Boolean]
# File lib/vagrant/shared_helpers.rb, line 31 def self.plugins_enabled? !ENV["VAGRANT_NO_PLUGINS"] end
@deprecated
# File lib/vagrant.rb, line 185 def self.require_plugin(name) puts "Vagrant.require_plugin is deprecated and has no effect any longer." puts "Use `vagrant plugin` commands to manage plugins. This warning will" puts "be removed in the next version of Vagrant." end
This allows a Vagrantfile to specify the version of Vagrant that is required. You can specify a list of requirements which will all be checked against the running Vagrant version.
This should be specified at the top of any Vagrantfile.
Examples are shown below:
Vagrant.require_version(">= 1.3.5") Vagrant.require_version(">= 1.3.5", "< 1.4.0") Vagrant.require_version("~> 1.3.5")
# File lib/vagrant.rb, line 203 def self.require_version(*requirements) logger = Log4r::Logger.new("vagrant::root") logger.info("Version requirements from Vagrantfile: #{requirements.inspect}") req = Gem::Requirement.new(*requirements) if req.satisfied_by?(Gem::Version.new(VERSION)) logger.info(" - Version requirements satisfied!") return end raise Errors::VagrantVersionBad, requirements: requirements.join(", "), version: VERSION end
Returns the URL prefix to the server.
@return [String]
# File lib/vagrant/shared_helpers.rb, line 38 def self.server_url result = ENV["VAGRANT_SERVER_URL"] result = nil if result == "" result || DEFAULT_SERVER_URL end
The source root is the path to the root directory of the Vagrant source.
@return [Pathname]
# File lib/vagrant/shared_helpers.rb, line 47 def self.source_root @source_root ||= Pathname.new(File.expand_path('../../../', __FILE__)) end
This returns the path to the ~/.vagrant.d folder where Vagrant's per-user state is stored.
@return [Pathname]
# File lib/vagrant/shared_helpers.rb, line 55 def self.user_data_path # Use user spcified env var if available path = ENV["VAGRANT_HOME"] # On Windows, we default ot the USERPROFILE directory if it # is available. This is more compatible with Cygwin and sharing # the home directory across shells. if !path && ENV["USERPROFILE"] path = "#{ENV["USERPROFILE"]}/.vagrant.d" end # Fallback to the default path ||= "~/.vagrant.d" Pathname.new(path).expand_path end