Skip to content

Commit ea25996

Browse files
committed
Update Vagrant behavior outside of installers
Remove customized require behaviors and modify the bin executable to check for missing tools that Vagrant expects to exist when running outside of an installer.
1 parent 7dcb670 commit ea25996

File tree

319 files changed

+1011
-1061
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+1011
-1061
lines changed

bin/vagrant

+11-9
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,6 @@ begin
187187
argv += argv_extra
188188
end
189189

190-
sub_cmd = Class.new(Vagrant.plugin("2", :command)) {
191-
def sub_command
192-
split_main_and_subcommand(@argv)[1]
193-
end
194-
}.new(argv.dup, nil).sub_command
195-
196190
# Create the environment, which is the cwd of wherever the
197191
# `vagrant` command was invoked from
198192
logger.debug("Creating Vagrant environment")
@@ -209,9 +203,17 @@ begin
209203
end
210204
end
211205

212-
if !Vagrant.in_installer? && !Vagrant.very_quiet?
213-
# If we're not in the installer, warn.
214-
env.ui.warn(I18n.t("vagrant.general.not_in_installer") + "\n", prefix: false)
206+
# If not being run from the installer, check if expected tools
207+
# are available.
208+
if !Vagrant.in_installer?
209+
missing_tools = Vagrant.detect_missing_tools
210+
211+
if !missing_tools.empty?
212+
env.ui.warn(
213+
I18n.t("vagrant.general.not_in_installer", tools: missing_tools.sort.join(", ")) + "\n",
214+
prefix: false
215+
)
216+
end
215217
end
216218

217219
# Acceptable experimental flag values include:

lib/vagrant.rb

+25-25
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
# require helper available.
66
require "vagrant/shared_helpers"
77

8-
Vagrant.require "log4r"
8+
require "log4r"
99

1010
# Add patches to log4r to support trace level
11-
Vagrant.require "vagrant/patches/log4r"
12-
Vagrant.require "vagrant/patches/net-ssh"
13-
Vagrant.require "vagrant/patches/rubygems"
14-
Vagrant.require "vagrant/patches/timeout_error"
11+
require "vagrant/patches/log4r"
12+
require "vagrant/patches/net-ssh"
13+
require "vagrant/patches/rubygems"
14+
require "vagrant/patches/timeout_error"
1515

1616
# Set our log levels and include trace
17-
Vagrant.require 'log4r/configurator'
17+
require 'log4r/configurator'
1818
Log4r::Configurator.custom_levels(*(["TRACE"] + Log4r::Log4rConfig::LogLevels))
1919

2020
# Update the default formatter within the log4r library to ensure
@@ -26,7 +26,7 @@ def format_object(obj)
2626
end
2727
end
2828

29-
Vagrant.require "optparse"
29+
require "optparse"
3030

3131
module Vagrant
3232
# This is a customized OptionParser for Vagrant plugins. It
@@ -51,9 +51,9 @@ module VagrantPlugins
5151
end
5252

5353
# Load in our helpers and utilities
54-
Vagrant.require "rubygems"
55-
Vagrant.require "vagrant/util"
56-
Vagrant.require "vagrant/plugin/manager"
54+
require "rubygems"
55+
require "vagrant/util"
56+
require "vagrant/plugin/manager"
5757

5858
# Enable logging if it is requested. We do this before
5959
# anything else so that we can setup the output before
@@ -110,19 +110,19 @@ def << msg
110110
end
111111
end
112112

113-
Vagrant.require 'json'
114-
Vagrant.require 'pathname'
115-
Vagrant.require 'stringio'
113+
require 'json'
114+
require 'pathname'
115+
require 'stringio'
116116

117-
Vagrant.require 'childprocess'
118-
Vagrant.require 'i18n'
117+
require 'childprocess'
118+
require 'i18n'
119119

120120
# OpenSSL must be loaded here since when it is loaded via `autoload`
121121
# there are issues with ciphers not being properly loaded.
122-
Vagrant.require 'openssl'
122+
require 'openssl'
123123

124124
# Always make the version available
125-
Vagrant.require 'vagrant/version'
125+
require 'vagrant/version'
126126
global_logger = Log4r::Logger.new("vagrant::global")
127127
Vagrant.global_logger = global_logger
128128
global_logger.info("Vagrant version: #{Vagrant::VERSION}")
@@ -143,7 +143,7 @@ def << msg
143143
if vagrant_ssl_locations.any? { |f| File.exist?(f) }
144144
global_logger.debug("vagrant ssl helper found for loading ssl providers")
145145
begin
146-
Vagrant.require "vagrant/vagrant_ssl"
146+
require "vagrant/vagrant_ssl"
147147
Vagrant.vagrant_ssl_load
148148
global_logger.debug("ssl providers successfully loaded")
149149
rescue LoadError => err
@@ -157,8 +157,8 @@ def << msg
157157

158158
# We need these components always so instead of an autoload we
159159
# just require them explicitly here.
160-
Vagrant.require "vagrant/plugin"
161-
Vagrant.require "vagrant/registry"
160+
require "vagrant/plugin"
161+
require "vagrant/registry"
162162

163163
module Vagrant
164164
autoload :Action, 'vagrant/action'
@@ -235,7 +235,7 @@ def self.has_plugin?(name, version=nil)
235235
end
236236

237237
# Now check the plugin gem names
238-
Vagrant.require "vagrant/plugin/manager"
238+
require "vagrant/plugin/manager"
239239
Plugin::Manager.instance.plugin_installed?(name, version)
240240
end
241241

@@ -273,7 +273,7 @@ def self.plugin(version, component=nil)
273273

274274
# @deprecated
275275
def self.require_plugin(name)
276-
puts "Vagrant.require_plugin is deprecated and has no effect any longer."
276+
puts "require_plugin is deprecated and has no effect any longer."
277277
puts "Use `vagrant plugin` commands to manage plugins. This warning will"
278278
puts "be removed in the next version of Vagrant."
279279
end
@@ -297,9 +297,9 @@ def self.version?(*requirements)
297297
#
298298
# Examples are shown below:
299299
#
300-
# Vagrant.require_version(">= 1.3.5")
301-
# Vagrant.require_version(">= 1.3.5", "< 1.4.0")
302-
# Vagrant.require_version("~> 1.3.5")
300+
# require_version(">= 1.3.5")
301+
# require_version(">= 1.3.5", "< 1.4.0")
302+
# require_version("~> 1.3.5")
303303
#
304304
def self.require_version(*requirements)
305305
logger = Log4r::Logger.new("vagrant::root")

lib/vagrant/action.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
Vagrant.require 'vagrant/action/builder'
4+
require 'vagrant/action/builder'
55

66
module Vagrant
77
module Action

lib/vagrant/action/builtin/box_add.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
Vagrant.require "digest/sha1"
5-
Vagrant.require "log4r"
6-
Vagrant.require "pathname"
7-
Vagrant.require "uri"
8-
9-
Vagrant.require "vagrant/box_metadata"
10-
Vagrant.require "vagrant/util/downloader"
11-
Vagrant.require "vagrant/util/file_checksum"
12-
Vagrant.require "vagrant/util/file_mutex"
13-
Vagrant.require "vagrant/util/platform"
4+
require "digest/sha1"
5+
require "log4r"
6+
require "pathname"
7+
require "uri"
8+
9+
require "vagrant/box_metadata"
10+
require "vagrant/util/downloader"
11+
require "vagrant/util/file_checksum"
12+
require "vagrant/util/file_mutex"
13+
require "vagrant/util/platform"
1414

1515
module Vagrant
1616
module Action

lib/vagrant/action/builtin/box_check_outdated.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
Vagrant.require "log4r"
4+
require "log4r"
55

66
module Vagrant
77
module Action

lib/vagrant/action/builtin/box_remove.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
Vagrant.require "log4r"
4+
require "log4r"
55

66
module Vagrant
77
module Action

lib/vagrant/action/builtin/box_update.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
Vagrant.require "log4r"
4+
require "log4r"
55

66
module Vagrant
77
module Action
+56-56
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
# Copyright (c) HashiCorp, Inc.
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
Vagrant.require "json"
5-
6-
module Vagrant
7-
module Action
8-
module Builtin
9-
class CleanupDisks
10-
# Removes any attached disks no longer defined in a Vagrantfile config
11-
def initialize(app, env)
12-
@app = app
13-
@logger = Log4r::Logger.new("vagrant::action::builtin::disk")
14-
end
15-
16-
def call(env)
17-
machine = env[:machine]
18-
defined_disks = get_disks(machine, env)
19-
20-
# Call into providers machine implementation for disk management
21-
disk_meta_file = read_disk_metadata(machine)
22-
23-
if !disk_meta_file.empty?
24-
if machine.provider.capability?(:cleanup_disks)
25-
machine.provider.capability(:cleanup_disks, defined_disks, disk_meta_file)
26-
else
27-
env[:ui].warn(I18n.t("vagrant.actions.disk.provider_unsupported",
28-
provider: machine.provider_name))
29-
end
30-
end
31-
32-
# Continue On
33-
@app.call(env)
34-
end
35-
36-
def read_disk_metadata(machine)
37-
meta_file = machine.data_dir.join("disk_meta")
38-
if File.file?(meta_file)
39-
disk_meta = JSON.parse(meta_file.read)
40-
else
41-
@logger.info("No previous disk_meta file defined for guest #{machine.name}")
42-
disk_meta = {}
43-
end
44-
45-
return disk_meta
46-
end
47-
48-
def get_disks(machine, env)
49-
return @_disks if @_disks
50-
51-
@_disks = []
52-
@_disks = machine.config.vm.disks
53-
54-
@_disks
55-
end
56-
end
57-
end
58-
end
59-
end
4+
require "json"
5+
6+
module Vagrant
7+
module Action
8+
module Builtin
9+
class CleanupDisks
10+
# Removes any attached disks no longer defined in a Vagrantfile config
11+
def initialize(app, env)
12+
@app = app
13+
@logger = Log4r::Logger.new("vagrant::action::builtin::disk")
14+
end
15+
16+
def call(env)
17+
machine = env[:machine]
18+
defined_disks = get_disks(machine, env)
19+
20+
# Call into providers machine implementation for disk management
21+
disk_meta_file = read_disk_metadata(machine)
22+
23+
if !disk_meta_file.empty?
24+
if machine.provider.capability?(:cleanup_disks)
25+
machine.provider.capability(:cleanup_disks, defined_disks, disk_meta_file)
26+
else
27+
env[:ui].warn(I18n.t("vagrant.actions.disk.provider_unsupported",
28+
provider: machine.provider_name))
29+
end
30+
end
31+
32+
# Continue On
33+
@app.call(env)
34+
end
35+
36+
def read_disk_metadata(machine)
37+
meta_file = machine.data_dir.join("disk_meta")
38+
if File.file?(meta_file)
39+
disk_meta = JSON.parse(meta_file.read)
40+
else
41+
@logger.info("No previous disk_meta file defined for guest #{machine.name}")
42+
disk_meta = {}
43+
end
44+
45+
return disk_meta
46+
end
47+
48+
def get_disks(machine, env)
49+
return @_disks if @_disks
50+
51+
@_disks = []
52+
@_disks = machine.config.vm.disks
53+
54+
@_disks
55+
end
56+
end
57+
end
58+
end
59+
end

0 commit comments

Comments
 (0)