Module: Vagrant

Defined in:
lib/vagrant/util.rb,
lib/vagrant/ui.rb,
lib/vagrant/box.rb,
lib/vagrant/cli.rb,
lib/vagrant/host.rb,
lib/vagrant/alias.rb,
lib/vagrant/guest.rb,
lib/vagrant/action.rb,
lib/vagrant/config.rb,
lib/vagrant/errors.rb,
lib/vagrant/plugin.rb,
lib/vagrant/bundler.rb,
lib/vagrant/machine.rb,
lib/vagrant/util/io.rb,
lib/vagrant/version.rb,
lib/vagrant/registry.rb,
lib/vagrant/util/env.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/ui/remote.rb,
lib/vagrant/util/busy.rb,
lib/vagrant/util/caps.rb,
lib/vagrant/util/mime.rb,
lib/vagrant/box/remote.rb,
lib/vagrant/util/which.rb,
lib/vagrant/action/hook.rb,
lib/vagrant/environment.rb,
lib/vagrant/host/remote.rb,
lib/vagrant/vagrantfile.rb,
lib/vagrant/batch_action.rb,
lib/vagrant/box_metadata.rb,
lib/vagrant/guest/remote.rb,
lib/vagrant/util/counter.rb,
lib/vagrant/util/keypair.rb,
lib/vagrant/util/numeric.rb,
lib/vagrant/action/runner.rb,
lib/vagrant/action/warden.rb,
lib/vagrant/config/loader.rb,
lib/vagrant/machine_index.rb,
lib/vagrant/machine_state.rb,
lib/vagrant/plugin/remote.rb,
lib/vagrant/util/platform.rb,
lib/vagrant/util/presence.rb,
lib/vagrant/util/safe_env.rb,
lib/vagrant/util/uploader.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/machine/remote.rb,
lib/vagrant/plugin/manager.rb,
lib/vagrant/plugin/v1/host.rb,
lib/vagrant/plugin/v2/host.rb,
lib/vagrant/plugin/v2/push.rb,
lib/vagrant/shared_helpers.rb,
lib/vagrant/util/directory.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/capability_host.rb,
lib/vagrant/plugin/v1/guest.rb,
lib/vagrant/plugin/v2/guest.rb,
lib/vagrant/util/deep_merge.rb,
lib/vagrant/util/downloader.rb,
lib/vagrant/util/file_mutex.rb,
lib/vagrant/util/network_ip.rb,
lib/vagrant/util/powershell.rb,
lib/vagrant/util/remote/ssh.rb,
lib/vagrant/util/safe_chdir.rb,
lib/vagrant/util/subprocess.rb,
lib/vagrant/config/v1/loader.rb,
lib/vagrant/config/v2/loader.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/util/curl_helper.rb,
lib/vagrant/util/guest_hosts.rb,
lib/vagrant/util/line_buffer.rb,
lib/vagrant/util/shell_quote.rb,
lib/vagrant/plugin/state_file.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/plugin/v2/trigger.rb,
lib/vagrant/util/experimental.rb,
lib/vagrant/util/is_port_open.rb,
lib/vagrant/util/windows_path.rb,
lib/vagrant/environment/remote.rb,
lib/vagrant/plugin/remote/host.rb,
lib/vagrant/plugin/remote/push.rb,
lib/vagrant/plugin/v1/provider.rb,
lib/vagrant/plugin/v2/provider.rb,
lib/vagrant/vagrantfile/remote.rb,
lib/vagrant/action/builtin/call.rb,
lib/vagrant/action/builtin/disk.rb,
lib/vagrant/action/builtin/lock.rb,
lib/vagrant/box_metadata/remote.rb,
lib/vagrant/config/version_base.rb,
lib/vagrant/plugin/remote/guest.rb,
lib/vagrant/machine_index/remote.rb,
lib/vagrant/plugin/remote/plugin.rb,
lib/vagrant/plugin/v2/components.rb,
lib/vagrant/util/ipv4_interfaces.rb,
lib/vagrant/action/primary_runner.rb,
lib/vagrant/box_collection/remote.rb,
lib/vagrant/plugin/remote/command.rb,
lib/vagrant/plugin/remote/manager.rb,
lib/vagrant/plugin/v1/provisioner.rb,
lib/vagrant/plugin/v2/provisioner.rb,
lib/vagrant/util/guest_inspection.rb,
lib/vagrant/util/remote/safe_puts.rb,
lib/vagrant/util/silence_warnings.rb,
lib/vagrant/action/builtin/box_add.rb,
lib/vagrant/action/builtin/confirm.rb,
lib/vagrant/action/builtin/delayed.rb,
lib/vagrant/action/builtin/env_set.rb,
lib/vagrant/action/builtin/message.rb,
lib/vagrant/action/builtin/ssh_run.rb,
lib/vagrant/action/builtin/trigger.rb,
lib/vagrant/action/general/package.rb,
lib/vagrant/config/v1/dummy_config.rb,
lib/vagrant/config/v2/dummy_config.rb,
lib/vagrant/plugin/remote/provider.rb,
lib/vagrant/plugin/v1/communicator.rb,
lib/vagrant/plugin/v2/communicator.rb,
lib/vagrant/util/checkpoint_client.rb,
lib/vagrant/util/logging_formatter.rb,
lib/vagrant/util/template_renderer.rb,
lib/vagrant/action/builtin/is_state.rb,
lib/vagrant/action/builtin/ssh_exec.rb,
lib/vagrant/plugin/v2/synced_folder.rb,
lib/vagrant/action/builtin/provision.rb,
lib/vagrant/util/command_deprecation.rb,
lib/vagrant/util/credential_scrubber.rb,
lib/vagrant/util/line_ending_helpers.rb,
lib/vagrant/util/map_command_options.rb,
lib/vagrant/util/stacked_proc_runner.rb,
lib/vagrant/util/string_block_editor.rb,
lib/vagrant/action/builtin/box_remove.rb,
lib/vagrant/action/builtin/box_update.rb,
lib/vagrant/action/builtin/handle_box.rb,
lib/vagrant/action/builtin/is_env_set.rb,
lib/vagrant/plugin/remote/provisioner.rb,
lib/vagrant/util/scoped_hash_override.rb,
lib/vagrant/plugin/remote/communicator.rb,
lib/vagrant/action/builtin/set_hostname.rb,
lib/vagrant/plugin/remote/synced_folder.rb,
lib/vagrant/action/builtin/cleanup_disks.rb,
lib/vagrant/action/builtin/graceful_halt.rb,
lib/vagrant/action/builtin/prepare_clone.rb,
lib/vagrant/action/builtin/handle_box_url.rb,
lib/vagrant/action/builtin/remote/ssh_run.rb,
lib/vagrant/action/builtin/synced_folders.rb,
lib/vagrant/util/ansi_escape_code_remover.rb,
lib/vagrant/util/install_cli_autocomplete.rb,
lib/vagrant/action/builtin/cloud_init_wait.rb,
lib/vagrant/action/builtin/config_validate.rb,
lib/vagrant/action/builtin/destroy_confirm.rb,
lib/vagrant/action/builtin/has_provisioner.rb,
lib/vagrant/action/builtin/cloud_init_setup.rb,
lib/vagrant/action/builtin/box_check_outdated.rb,
lib/vagrant/action/builtin/mixin_provisioners.rb,
lib/vagrant/util/hash_with_indifferent_access.rb,
lib/vagrant/action/builtin/provisioner_cleanup.rb,
lib/vagrant/action/general/package_setup_files.rb,
lib/vagrant/action/builtin/mixin_synced_folders.rb,
lib/vagrant/action/builtin/synced_folder_cleanup.rb,
lib/vagrant/action/builtin/wait_for_communicator.rb,
lib/vagrant/action/general/package_setup_folders.rb,
lib/vagrant/action/builtin/remote/mixin_synced_folders.rb,
lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb,
ext/vagrant/vagrant_ssl/vagrant_ssl.c,
lib/vagrant.rb,
lib/vagrant.rb

Overview

Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: BUSL-1.1

Defined Under Namespace

Modules: Action, CapabilityHost, Config, Errors, Plugin, UI, Util Classes: Alias, BatchAction, Box, BoxCollection, BoxMetadata, Bundler, CLI, Environment, Guest, Host, Machine, MachineIndex, MachineState, OptionParser, Registry, Vagrantfile

Constant Summary collapse

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

File.read(
File.expand_path("../../../version.txt", __FILE__)).chomp
DEFAULT_SERVER_URL =

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.

Returns:

  • (String)
"https://vagrantcloud.com".freeze
THREAD_MAX_JOIN_TIMEOUT =
Note:

This is not the maximum time for a thread to complete.

Max number of seconds to wait for joining an active thread.

Returns:

  • (Integer)
60
SERVER_MODE_CALLBACKS =
[
  ->{ Vagrant::Box.prepend(Vagrant::Box::Remote) },
  ->{ Vagrant::BoxCollection.prepend(Vagrant::BoxCollection::Remote) },
  ->{ Vagrant::BoxMetadata.prepend(Vagrant::BoxMetadata::Remote) },
  ->{ Vagrant::Guest.prepend(Vagrant::Guest::Remote) },
  ->{ Vagrant::Host.prepend(Vagrant::Host::Remote) },
  ->{ Vagrant::Machine.prepend(Vagrant::Machine::Remote) },
  ->{ Vagrant::Environment.prepend(Vagrant::Environment::Remote) },
  ->{ Vagrant::MachineIndex.prepend(Vagrant::MachineIndex::Remote) },
  ->{ Vagrant::MachineIndex::Entry.prepend(Vagrant::MachineIndex::Entry::Remote::InstanceMethods) },
  ->{ Vagrant::MachineIndex::Entry.extend(Vagrant::MachineIndex::Entry::Remote::ClassMethods) },
  ->{ Vagrant::Action::Builtin::MixinSyncedFolders.prepend(Vagrant::Action::Builtin::Remote::MixinSyncedFolders) },
  ->{ Vagrant::Action::Builtin::SSHRun.prepend(Vagrant::Action::Builtin::Remote::SSHRun) },
  ->{ Vagrant::Vagrantfile.prepend(Vagrant::Vagrantfile::Remote) },
  ->{ Vagrant::Util::SSH.prepend(Vagrant::Util::Remote::SSH) },
  ->{ Vagrant::Util::SafePuts.prepend(Vagrant::Util::Remote::SafePuts) },
].freeze
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 }
  c.register([:"2", :push])         { Plugin::V2::Push }
  c.register([:"2", :synced_folder]) { Plugin::V2::SyncedFolder }

  c.register(:remote)               { Plugin::Remote::Plugin }
end
@@global_lock =
Mutex.new

Class Method Summary collapse

Class Method Details

.add_default_cli_options(block) ⇒ nil

Add a new block of default CLI options which should be automatically added to all commands

Parameters:

  • block (Proc)

    Proc instance containing OptParser configuration

Returns:

  • (nil)


206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/vagrant/shared_helpers.rb', line 206

def self.add_default_cli_options(block)
  if !block.is_a?(Proc)
    raise TypeError,
      "Expecting type `Proc` but received `#{block.class}`"
  end
  if block.arity != 1 && block.arity != -1
    raise ArgumentError,
      "Proc must accept OptionParser argument"
  end
  @_default_cli_options = [] if !@_default_cli_options
  @_default_cli_options << block
  nil
end

.allow_prerelease_dependencies?Boolean

This returns true/false if the Vagrant should allow prerelease versions when resolving plugin dependency constraints

Returns:

  • (Boolean)


135
136
137
# File 'lib/vagrant/shared_helpers.rb', line 135

def self.allow_prerelease_dependencies?
  !!ENV["VAGRANT_ALLOW_PRERELEASE"]
end

.auto_install_local_plugins?Boolean

Automatically install locally defined plugins instead of waiting for user confirmation.

Returns:

  • (Boolean)


156
157
158
159
160
161
162
# File 'lib/vagrant/shared_helpers.rb', line 156

def self.auto_install_local_plugins?
  if ENV["VAGRANT_INSTALL_LOCAL_PLUGINS"]
    true
  else
    false
  end
end

.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



215
216
217
# File 'lib/vagrant.rb', line 215

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

.default_cli_optionsArray<Proc>

Array of default CLI options to automatically add to commands.

Returns:

  • (Array<Proc>)

    Default optparse options



224
225
226
227
# File 'lib/vagrant/shared_helpers.rb', line 224

def self.default_cli_options
  @_default_cli_options = [] if !@_default_cli_options
  @_default_cli_options.dup
end

.enable_resolv_replaceboolean

Use Ruby Resolv in place of libc

Returns:

  • (boolean)

    enabled or not



167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/vagrant/shared_helpers.rb', line 167

def self.enable_resolv_replace
  if ENV["VAGRANT_ENABLE_RESOLV_REPLACE"]
    if !ENV["VAGRANT_DISABLE_RESOLV_REPLACE"]
      begin
        require "resolv-replace"
        true
      rescue
        false
      end
    else
      false
    end
  end
end

.enable_server_mode!true

Flag Vagrant as running in server mode

Returns:

  • (true)


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/vagrant/shared_helpers.rb', line 239

def self.enable_server_mode!
  if !server_mode?
    Util::HCLogOutputter.new("hclog")
    Log4r::Outputter["hclog"].formatter = Util::HCLogFormatter.new
    Log4r::Outputter.stderr.formatter = Log4r::Outputter["hclog"].formatter
    Log4r::RootLogger.instance.outputters = Log4r::Outputter["hclog"]
    Log4r::Logger.each_logger do |l|
      l.outputters = Log4r::Outputter["hclog"] #if l.parent&.is_root?
    end

    Log4r::Logger::Repository.class_eval do
      def self.[]=(n, l)
        self.synchronize do
          l.outputters = Log4r::Outputter["hclog"] # if l.parent&.is_root?
          instance.loggers[n] = l
        end
      end
    end

    # By default only display error logs from the mappers unless explicitly
    # requested due to their verbosity
    if ENV["VAGRANT_LOG_MAPPER"].to_s == ""
      l = Log4r::Logger.factory("vagrantplugins::commandserve::mappers")
      l.level = Log4r::ERROR
    end
  end
  Log4r::Logger.factory("vagrant").trace("service logger initialization")
  Log4r::Logger.factory("vagrantplugins").trace("service logger initialization")

  load_vagrant_proto!
  SERVER_MODE_CALLBACKS.each(&:call)

  @_server_mode = true
end

.global_lockObject

This holds a global lock for the duration of the block. This should be invoked around anything that is modifying process state (such as environmental variables).



27
28
29
30
31
# File 'lib/vagrant/shared_helpers.rb', line 27

def self.global_lock
  @@global_lock.synchronize do
    return yield
  end
end

.global_loggerLogger

Get the global logger instance

Returns:

  • (Logger)


193
194
195
196
197
198
199
# File 'lib/vagrant/shared_helpers.rb', line 193

def self.global_logger
  if @_global_logger.nil?
    require "log4r"
    @_global_logger = Log4r::Logger.new("vagrant::global")
  end
  @_global_logger
end

.global_logger=(log) ⇒ Logger

Set the global logger

Parameters:

  • log

    Logger

Returns:

  • (Logger)


186
187
188
# File 'lib/vagrant/shared_helpers.rb', line 186

def self.global_logger=(log)
  @_global_logger = log
end

.has_plugin?(name, version = nil) ⇒ Boolean

This checks if a plugin with the given name is available (installed and enabled). This can be used from the Vagrantfile to easily branch based on plugin availability.

Returns:

  • (Boolean)


222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/vagrant.rb', line 222

def self.has_plugin?(name, version=nil)
  return false unless Vagrant.plugins_enabled?

  if !version
    # We check the plugin names first because those are cheaper to check
    return true if plugin("2").manager.registered.any? { |p| p.name == name }
  end

  # Now check the plugin gem names
  require "vagrant/plugin/manager"
  Plugin::Manager.instance.plugin_installed?(name, version)
end

.in_bundler?Boolean

This returns a true/false if we are running within a bundler environment

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/vagrant/shared_helpers.rb', line 44

def self.in_bundler?
  !!ENV["BUNDLE_GEMFILE"] &&
    !defined?(::Bundler).nil?
end

.in_installer?Boolean

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

Returns:

  • (Boolean)


37
38
39
# File 'lib/vagrant/shared_helpers.rb', line 37

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

.installer_embedded_dirString

Returns the path to the embedded directory of the Vagrant installer, if there is one (if we're running in an installer).

Returns:

  • (String)


53
54
55
56
# File 'lib/vagrant/shared_helpers.rb', line 53

def self.installer_embedded_dir
  return nil if !Vagrant.in_installer?
  ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
end

.load_vagrant_proto!Object

Load the vagrant proto messages



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/vagrant/shared_helpers.rb', line 275

def self.load_vagrant_proto!
  return if @_vagrant_proto_loaded
  # Update the load path so our protos can be located
  $LOAD_PATH << Vagrant.source_root.join("lib/vagrant/protobufs").to_s
  $LOAD_PATH << Vagrant.source_root.join("lib/vagrant/protobufs/proto").to_s
  $LOAD_PATH << Vagrant.source_root.join("lib/vagrant/protobufs/proto/vagrant_plugin_sdk").to_s

  # Load our protos so they are available
  require 'vagrant/protobufs/proto/vagrant_server/server_pb'
  require 'vagrant/protobufs/proto/vagrant_server/server_services_pb'
  require 'vagrant/protobufs/proto/ruby_vagrant/ruby-server_pb'
  require 'vagrant/protobufs/proto/ruby_vagrant/ruby-server_services_pb'
  require 'vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb'
  require 'vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb'
  require 'vagrant/protobufs/proto/plugin/grpc_broker_pb'
  require 'vagrant/protobufs/proto/plugin/grpc_broker_services_pb'
  @_vagrant_proto_loaded = true
end

.log_levelString

The current log level for Vagrant

Returns:

  • (String)


82
83
84
# File 'lib/vagrant/shared_helpers.rb', line 82

def self.log_level
  ENV.fetch("VAGRANT_LOG", "fatal").downcase
end

.original_envHash

This allows plugin developers to access the original environment before Vagrant even ran. This is useful when shelling out, especially to other Ruby processes.

Returns:

  • (Hash)


316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/vagrant.rb', line 316

def self.original_env
  {}.tap do |h|
    ENV.each do |k,v|
      if k.start_with?("VAGRANT_OLD_ENV")
        key = k.sub(/^VAGRANT_OLD_ENV_/, "")
        if !key.empty?
          h[key] = v
        end
      end
    end
  end
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)


252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/vagrant.rb', line 252

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

.plugins_enabled?Boolean

This returns whether or not 3rd party plugins should and can be loaded.

Returns:

  • (Boolean)


68
69
70
# File 'lib/vagrant/shared_helpers.rb', line 68

def self.plugins_enabled?
  !ENV["VAGRANT_NO_PLUGINS"]
end

.plugins_init?Boolean

Should the plugin system be initialized

Returns:

  • (Boolean)


61
62
63
# File 'lib/vagrant/shared_helpers.rb', line 61

def self.plugins_init?
  !ENV['VAGRANT_DISABLE_PLUGIN_INIT']
end

.prerelease?Boolean

This returns true/false if the running version of Vagrant is a pre-release version (development)

Returns:

  • (Boolean)


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

def self.prerelease?
  Gem::Version.new(Vagrant::VERSION).prerelease?
end

.require_plugin(name) ⇒ Object

Deprecated.


268
269
270
271
272
# File 'lib/vagrant.rb', line 268

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

.require_version(*requirements) ⇒ Object

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")



297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/vagrant.rb', line 297

def self.require_version(*requirements)
  logger = Log4r::Logger.new("vagrant::root")
  logger.info("Version requirements from Vagrantfile: #{requirements.inspect}")

  if version?(*requirements)
    logger.info("  - Version requirements satisfied!")
    return
  end

  raise Errors::VagrantVersionBad,
    requirements: requirements.join(", "),
    version: VERSION
end

.server_mode?Boolean

Check if Vagrant is running in server mode

Returns:

  • (Boolean)


232
233
234
# File 'lib/vagrant/shared_helpers.rb', line 232

def self.server_mode?
  !!@_server_mode
end

.server_url(config_server_url = nil) ⇒ String

Returns the URL prefix to the server.

Returns:

  • (String)


89
90
91
92
93
# File 'lib/vagrant/shared_helpers.rb', line 89

def self.server_url(config_server_url=nil)
  result = ENV["VAGRANT_SERVER_URL"]
  result = config_server_url if result == "" or result == nil
  result || DEFAULT_SERVER_URL
end

.source_rootPathname

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

Returns:

  • (Pathname)


98
99
100
# File 'lib/vagrant/shared_helpers.rb', line 98

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

.strict_dependency_enforcementBoolean

This allows control over dependency resolution when installing plugins into vagrant. When true, dependency libraries that Vagrant core relies upon will be hard constraints.

Returns:

  • (Boolean)


144
145
146
147
148
149
150
# File 'lib/vagrant/shared_helpers.rb', line 144

def self.strict_dependency_enforcement
  if ENV["VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT"]
    false
  else
    true
  end
end

.user_data_pathPathname

This returns the path to the ~/.vagrant.d folder where Vagrant's per-user state is stored.

Returns:

  • (Pathname)


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/vagrant/shared_helpers.rb', line 106

def self.user_data_path
  # Use user specified env var if available
  path = ENV["VAGRANT_HOME"]

  # On Windows, we default to 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

.vagrant_ssl_loadObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'ext/vagrant/vagrant_ssl/vagrant_ssl.c', line 10

static VALUE vagrant_ssl_load(VALUE self) {
  OSSL_PROVIDER *legacy;
  OSSL_PROVIDER *deflt;

  legacy = OSSL_PROVIDER_load(NULL, "legacy");
  if(legacy == NULL) {
    rb_raise(rb_eStandardError, "Failed to load OpenSSL legacy provider");
    return self;
  }

  deflt = OSSL_PROVIDER_load(NULL, "default");
  if(deflt == NULL) {
    rb_raise(rb_eStandardError, "Failed to load OpenSSL default provider");
    return self;
  }
}

.version?(*requirements) ⇒ Boolean

This checks if Vagrant is installed in a specific version.

Example:

Vagrant.version?(">= 2.1.0")

Returns:

  • (Boolean)


280
281
282
283
# File 'lib/vagrant.rb', line 280

def self.version?(*requirements)
  req = Gem::Requirement.new(*requirements)
  req.satisfied_by?(Gem::Version.new(VERSION))
end

.very_quiet?Boolean

Whether or not super quiet mode is enabled. This is ill-advised.

Returns:

  • (Boolean)


75
76
77
# File 'lib/vagrant/shared_helpers.rb', line 75

def self.very_quiet?
  !!ENV["VAGRANT_I_KNOW_WHAT_IM_DOING_PLEASE_BE_QUIET"]
end