vagrant 0.7.8 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +39 -0
- data/Gemfile +1 -7
- data/Rakefile +0 -11
- data/bin/vagrant +4 -0
- data/config/default.rb +1 -2
- data/lib/vagrant.rb +7 -5
- data/lib/vagrant/action.rb +5 -1
- data/lib/vagrant/action/builtin.rb +4 -1
- data/lib/vagrant/action/general/package.rb +6 -2
- data/lib/vagrant/action/vm.rb +2 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +9 -22
- data/lib/vagrant/action/vm/clear_shared_folders.rb +9 -14
- data/lib/vagrant/action/vm/customize.rb +9 -4
- data/lib/vagrant/action/vm/forward_ports.rb +10 -11
- data/lib/vagrant/action/vm/match_mac_address.rb +8 -3
- data/lib/vagrant/action/vm/modify.rb +37 -0
- data/lib/vagrant/action/vm/network.rb +9 -2
- data/lib/vagrant/action/vm/provision.rb +10 -17
- data/lib/vagrant/action/vm/provisioner_cleanup.rb +26 -0
- data/lib/vagrant/action/vm/share_folders.rb +16 -8
- data/lib/vagrant/action/warden.rb +8 -2
- data/lib/vagrant/command/ssh.rb +4 -4
- data/lib/vagrant/command/ssh_config.rb +4 -2
- data/lib/vagrant/config/ssh.rb +3 -0
- data/lib/vagrant/config/vm.rb +16 -12
- data/lib/vagrant/downloaders/http.rb +2 -0
- data/lib/vagrant/environment.rb +136 -12
- data/lib/vagrant/errors.rb +15 -0
- data/lib/vagrant/provisioners.rb +1 -1
- data/lib/vagrant/provisioners/base.rb +4 -0
- data/lib/vagrant/provisioners/chef.rb +13 -11
- data/lib/vagrant/provisioners/{chef_server.rb → chef_client.rb} +5 -5
- data/lib/vagrant/provisioners/chef_solo.rb +48 -89
- data/lib/vagrant/provisioners/shell.rb +47 -12
- data/lib/vagrant/ssh.rb +61 -27
- data/lib/vagrant/systems.rb +1 -0
- data/lib/vagrant/systems/base.rb +1 -1
- data/lib/vagrant/systems/linux.rb +7 -9
- data/lib/vagrant/systems/redhat.rb +12 -4
- data/lib/vagrant/systems/solaris.rb +9 -4
- data/lib/vagrant/systems/suse.rb +9 -0
- data/lib/vagrant/ui.rb +12 -5
- data/lib/vagrant/util.rb +2 -2
- data/lib/vagrant/util/counter.rb +22 -0
- data/lib/vagrant/util/platform.rb +1 -2
- data/lib/vagrant/util/safe_exec.rb +28 -0
- data/lib/vagrant/version.rb +1 -1
- data/lib/vagrant/vm.rb +2 -0
- data/templates/chef_solo_solo.erb +4 -4
- data/templates/commands/init/Vagrantfile.erb +4 -0
- data/templates/locales/en.yml +31 -8
- data/templates/ssh_config.erb +6 -0
- data/test/test_helper.rb +5 -3
- data/test/vagrant/action/builder_test.rb +4 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +18 -38
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +7 -16
- data/test/vagrant/action/vm/customize_test.rb +12 -5
- data/test/vagrant/action/vm/forward_ports_test.rb +12 -7
- data/test/vagrant/action/vm/match_mac_address_test.rb +5 -1
- data/test/vagrant/action/vm/modify_test.rb +38 -0
- data/test/vagrant/action/vm/provision_test.rb +13 -38
- data/test/vagrant/action/vm/provisioner_cleanup_test.rb +56 -0
- data/test/vagrant/action/vm/share_folders_test.rb +10 -5
- data/test/vagrant/action/warden_test.rb +13 -7
- data/test/vagrant/config/vm_test.rb +0 -22
- data/test/vagrant/downloaders/http_test.rb +2 -0
- data/test/vagrant/environment_test.rb +110 -20
- data/test/vagrant/provisioners/{chef_server_test.rb → chef_client_test.rb} +2 -2
- data/test/vagrant/provisioners/chef_solo_test.rb +16 -173
- data/test/vagrant/ssh_test.rb +8 -43
- data/test/vagrant/systems/linux_test.rb +9 -19
- data/test/vagrant/util/counter_test.rb +29 -0
- data/test/vagrant/util/platform_test.rb +2 -2
- data/vagrant.gemspec +1 -2
- metadata +114 -84
- data/lib/vagrant/util/plain_logger.rb +0 -25
- data/lib/vagrant/util/resource_logger.rb +0 -63
- data/test/vagrant/util/plain_logger_test.rb +0 -17
- data/test/vagrant/util/resource_logger_test.rb +0 -78
@@ -2,37 +2,30 @@ module Vagrant
|
|
2
2
|
class Action
|
3
3
|
module VM
|
4
4
|
class Provision
|
5
|
-
attr_reader :provisioners
|
6
|
-
|
7
5
|
def initialize(app, env)
|
8
6
|
@app = app
|
9
7
|
@env = env
|
10
8
|
@env["provision.enabled"] = true if !@env.has_key?("provision.enabled")
|
11
|
-
@provisioners = []
|
12
|
-
|
13
|
-
load_provisioners if provisioning_enabled?
|
14
9
|
end
|
15
10
|
|
16
11
|
def call(env)
|
12
|
+
# Instantiate and prepare the provisioners. Preparation must happen here
|
13
|
+
# so that shared folders and such can properly take effect.
|
14
|
+
provisioners = enabled_provisioners
|
15
|
+
provisioners.map { |p| p.prepare }
|
16
|
+
|
17
17
|
@app.call(env)
|
18
18
|
|
19
|
-
|
19
|
+
# Take prepared provisioners and run the provisioning
|
20
|
+
provisioners.each do |instance|
|
20
21
|
@env.ui.info I18n.t("vagrant.actions.vm.provision.beginning", :provisioner => instance.class)
|
21
22
|
instance.provision!
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def load_provisioners
|
30
|
-
@env["config"].vm.provisioners.each do |provisioner|
|
31
|
-
@env.ui.info I18n.t("vagrant.actions.vm.provision.enabled", :provisioner => provisioner.shortcut)
|
32
|
-
|
33
|
-
instance = provisioner.provisioner.new(@env, provisioner.config)
|
34
|
-
instance.prepare
|
35
|
-
@provisioners << instance
|
26
|
+
def enabled_provisioners
|
27
|
+
@env["config"].vm.provisioners.map do |provisioner|
|
28
|
+
provisioner.provisioner.new(@env, provisioner.config)
|
36
29
|
end
|
37
30
|
end
|
38
31
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Vagrant
|
2
|
+
class Action
|
3
|
+
module VM
|
4
|
+
class ProvisionerCleanup
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@env = env
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
enabled_provisioners.each do |instance|
|
12
|
+
instance.cleanup
|
13
|
+
end
|
14
|
+
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
|
18
|
+
def enabled_provisioners
|
19
|
+
@env["config"].vm.provisioners.map do |provisioner|
|
20
|
+
provisioner.provisioner.new(@env, provisioner.config)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -33,16 +33,18 @@ module Vagrant
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def create_metadata
|
36
|
-
|
36
|
+
proc = lambda do |vm|
|
37
|
+
@env.ui.info I18n.t("vagrant.actions.vm.share_folders.creating")
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
shared_folders.each do |name, data|
|
40
|
+
folder = VirtualBox::SharedFolder.new
|
41
|
+
folder.name = name
|
42
|
+
folder.host_path = File.expand_path(data[:hostpath], @env.env.root_path)
|
43
|
+
vm.shared_folders << folder
|
44
|
+
end
|
43
45
|
end
|
44
46
|
|
45
|
-
@env["vm"].
|
47
|
+
@env["vm.modify"].call(proc)
|
46
48
|
end
|
47
49
|
|
48
50
|
def mount_shared_folders
|
@@ -55,7 +57,13 @@ module Vagrant
|
|
55
57
|
@env.ui.info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
|
56
58
|
:name => name,
|
57
59
|
:guest_path => data[:guestpath]))
|
58
|
-
|
60
|
+
|
61
|
+
# Calculate the owner and group
|
62
|
+
owner = data[:owner] || @env["config"].ssh.username
|
63
|
+
group = data[:group] || @env["config"].ssh.username
|
64
|
+
|
65
|
+
# Mount the actual folder
|
66
|
+
@env["vm"].system.mount_shared_folder(ssh, name, data[:guestpath], owner, group)
|
59
67
|
else
|
60
68
|
# If no guest path is specified, then automounting is disabled
|
61
69
|
@env.ui.info(I18n.t("vagrant.actions.vm.share_folders.nomount_entry",
|
@@ -25,13 +25,16 @@ module Vagrant
|
|
25
25
|
# Call the next middleware in the sequence, appending to the stack
|
26
26
|
# of "recoverable" middlewares in case something goes wrong!
|
27
27
|
raise Errors::VagrantInterrupt if env.interrupted?
|
28
|
-
@
|
28
|
+
action = @actions.shift
|
29
|
+
env["logger"].info("warden") { "Calling action: #{action}" }
|
30
|
+
@stack.unshift(action).first.call(env)
|
29
31
|
raise Errors::VagrantInterrupt if env.interrupted?
|
30
32
|
rescue SystemExit
|
31
33
|
# This means that an "exit" or "abort" was called. In these cases,
|
32
34
|
# we just exit immediately.
|
33
35
|
raise
|
34
36
|
rescue Exception => e
|
37
|
+
env["logger"].info("warden") { "Error occurred: #{e}" }
|
35
38
|
env["vagrant.error"] = e
|
36
39
|
|
37
40
|
# Something went horribly wrong. Start the rescue chain then
|
@@ -46,7 +49,10 @@ module Vagrant
|
|
46
49
|
# which has already run, in reverse order.
|
47
50
|
def begin_rescue(env)
|
48
51
|
@stack.each do |act|
|
49
|
-
|
52
|
+
if act.respond_to?(:recover)
|
53
|
+
env["logger"].info("warden") { "Calling recover: #{act}" }
|
54
|
+
act.recover(env)
|
55
|
+
end
|
50
56
|
end
|
51
57
|
|
52
58
|
# Clear stack so that warden down the middleware chain doesn't
|
data/lib/vagrant/command/ssh.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Vagrant
|
2
2
|
module Command
|
3
3
|
class SSHCommand < NamedBase
|
4
|
-
class_option :
|
4
|
+
class_option :command, :type => :string, :default => false, :aliases => "-c"
|
5
5
|
register "ssh", "SSH into the currently running Vagrant environment."
|
6
6
|
|
7
7
|
def execute
|
8
|
-
if options[:
|
8
|
+
if options[:command]
|
9
9
|
ssh_execute
|
10
10
|
else
|
11
11
|
ssh_connect
|
@@ -16,8 +16,8 @@ module Vagrant
|
|
16
16
|
|
17
17
|
def ssh_execute
|
18
18
|
ssh_vm.ssh.execute do |ssh|
|
19
|
-
ssh_vm.env.ui.info I18n.t("vagrant.commands.ssh.
|
20
|
-
ssh.exec!(options[:
|
19
|
+
ssh_vm.env.ui.info I18n.t("vagrant.commands.ssh.command", :command => options[:command])
|
20
|
+
ssh.exec!(options[:command]) do |channel, type, data|
|
21
21
|
ssh_vm.env.ui.info "#{data}"
|
22
22
|
end
|
23
23
|
end
|
@@ -14,11 +14,13 @@ module Vagrant
|
|
14
14
|
vm.ssh.check_key_permissions(vm.env.config.ssh.private_key_path)
|
15
15
|
|
16
16
|
$stdout.puts(Util::TemplateRenderer.render("ssh_config", {
|
17
|
-
:host_key => options[:host] || "vagrant",
|
17
|
+
:host_key => options[:host] || vm.name || "vagrant",
|
18
18
|
:ssh_host => vm.env.config.ssh.host,
|
19
19
|
:ssh_user => vm.env.config.ssh.username,
|
20
20
|
:ssh_port => vm.ssh.port,
|
21
|
-
:private_key_path => vm.env.config.ssh.private_key_path
|
21
|
+
:private_key_path => vm.env.config.ssh.private_key_path,
|
22
|
+
:forward_agent => vm.env.config.ssh.forward_agent,
|
23
|
+
:forward_x11 => vm.env.config.ssh.forward_x11
|
22
24
|
}))
|
23
25
|
end
|
24
26
|
end
|
data/lib/vagrant/config/ssh.rb
CHANGED
@@ -6,6 +6,7 @@ module Vagrant
|
|
6
6
|
attr_accessor :username
|
7
7
|
attr_accessor :host
|
8
8
|
attr_accessor :forwarded_port_key
|
9
|
+
attr_accessor :forwarded_port_destination
|
9
10
|
attr_accessor :max_tries
|
10
11
|
attr_accessor :timeout
|
11
12
|
attr_writer :private_key_path
|
@@ -17,6 +18,8 @@ module Vagrant
|
|
17
18
|
def initialize
|
18
19
|
@sudo_shell = "bash"
|
19
20
|
@port = nil
|
21
|
+
@forward_agent = false
|
22
|
+
@forward_x11 = false
|
20
23
|
end
|
21
24
|
|
22
25
|
def private_key_path
|
data/lib/vagrant/config/vm.rb
CHANGED
@@ -20,8 +20,6 @@ module Vagrant
|
|
20
20
|
attr_reader :network_options
|
21
21
|
attr_reader :provisioners
|
22
22
|
attr_accessor :disk_image_format
|
23
|
-
attr_writer :shared_folder_uid
|
24
|
-
attr_writer :shared_folder_gid
|
25
23
|
attr_accessor :system
|
26
24
|
|
27
25
|
def initialize
|
@@ -46,7 +44,10 @@ module Vagrant
|
|
46
44
|
def share_folder(name, guestpath, hostpath, opts=nil)
|
47
45
|
@shared_folders[name] = {
|
48
46
|
:guestpath => guestpath,
|
49
|
-
:hostpath => hostpath
|
47
|
+
:hostpath => hostpath,
|
48
|
+
:owner => nil,
|
49
|
+
:group => nil,
|
50
|
+
:nfs => false
|
50
51
|
}.merge(opts || {})
|
51
52
|
end
|
52
53
|
|
@@ -73,14 +74,6 @@ module Vagrant
|
|
73
74
|
raise Errors::VagrantError, :_key => :provisioner_equals_not_supported
|
74
75
|
end
|
75
76
|
|
76
|
-
def shared_folder_uid
|
77
|
-
@shared_folder_uid || env.config.ssh.username
|
78
|
-
end
|
79
|
-
|
80
|
-
def shared_folder_gid
|
81
|
-
@shared_folder_gid || env.config.ssh.username
|
82
|
-
end
|
83
|
-
|
84
77
|
def customize(&block)
|
85
78
|
push_proc(&block)
|
86
79
|
end
|
@@ -125,11 +118,22 @@ module Vagrant
|
|
125
118
|
:name => name,
|
126
119
|
:path => options[:hostpath]))
|
127
120
|
end
|
121
|
+
|
122
|
+
if options[:nfs] && (options[:owner] || options[:group])
|
123
|
+
# Owner/group don't work with NFS
|
124
|
+
errors.add(I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group",
|
125
|
+
:name => name))
|
126
|
+
end
|
128
127
|
end
|
129
128
|
|
130
129
|
# Each provisioner can validate itself
|
131
130
|
provisioners.each do |prov|
|
132
|
-
|
131
|
+
# TODO: Remove at some point
|
132
|
+
if prov.shortcut == :chef_server
|
133
|
+
errors.add(I18n.t("vagrant.config.vm.provisioner_chef_server_changed"))
|
134
|
+
else
|
135
|
+
prov.validate(errors)
|
136
|
+
end
|
133
137
|
end
|
134
138
|
end
|
135
139
|
end
|
@@ -33,6 +33,8 @@ module Vagrant
|
|
33
33
|
# TODO: Error on some redirect limit
|
34
34
|
download!(response["Location"], destination_file)
|
35
35
|
return
|
36
|
+
elsif !response.is_a?(Net::HTTPOK)
|
37
|
+
raise Errors::DownloaderHTTPStatusError, :status => response.code
|
36
38
|
end
|
37
39
|
|
38
40
|
total = response.content_length
|
data/lib/vagrant/environment.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'fileutils'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
module Vagrant
|
5
6
|
# Represents a single Vagrant environment. A "Vagrant environment" is
|
6
7
|
# defined as basically a folder with a "Vagrantfile." This class allows
|
7
8
|
# access to the VMs, CLI, etc. all in the scope of this environment.
|
8
9
|
class Environment
|
9
|
-
ROOTFILE_NAME = "Vagrantfile"
|
10
10
|
HOME_SUBDIRS = ["tmp", "boxes", "logs"]
|
11
11
|
DEFAULT_VM = :default
|
12
|
-
DEFAULT_HOME = "~/.vagrant"
|
12
|
+
DEFAULT_HOME = "~/.vagrant.d"
|
13
13
|
|
14
14
|
# Parent environment (in the case of multi-VMs)
|
15
15
|
attr_reader :parent
|
@@ -17,6 +17,9 @@ module Vagrant
|
|
17
17
|
# The `cwd` that this environment represents
|
18
18
|
attr_reader :cwd
|
19
19
|
|
20
|
+
# The valid name for a Vagrantfile for this environment.
|
21
|
+
attr_reader :vagrantfile_name
|
22
|
+
|
20
23
|
# The single VM that this environment represents, in the case of
|
21
24
|
# multi-VM.
|
22
25
|
attr_accessor :vm
|
@@ -36,7 +39,7 @@ module Vagrant
|
|
36
39
|
def check_virtualbox!
|
37
40
|
version = VirtualBox.version
|
38
41
|
raise Errors::VirtualBoxNotDetected if version.nil?
|
39
|
-
raise Errors::VirtualBoxInvalidVersion, :version => version.to_s if version.to_f < 4.
|
42
|
+
raise Errors::VirtualBoxInvalidVersion, :version => version.to_s if version.to_f < 4.1 || version.to_f >= 4.2
|
40
43
|
rescue Errors::VirtualBoxNotDetected
|
41
44
|
# On 64-bit Windows, show a special error. This error is a subclass
|
42
45
|
# of VirtualBoxNotDetected, so libraries which use Vagrant can just
|
@@ -58,16 +61,30 @@ module Vagrant
|
|
58
61
|
:parent => nil,
|
59
62
|
:vm => nil,
|
60
63
|
:cwd => nil,
|
64
|
+
:vagrantfile_name => nil,
|
65
|
+
:lock_path => nil
|
61
66
|
}.merge(opts || {})
|
62
67
|
|
68
|
+
# Set the default working directory to look for the vagrantfile
|
63
69
|
opts[:cwd] ||= Dir.pwd
|
64
70
|
opts[:cwd] = Pathname.new(opts[:cwd])
|
65
71
|
|
72
|
+
# Set the default vagrantfile name, which can be either Vagrantfile
|
73
|
+
# or vagrantfile (capital for backwards compatibility)
|
74
|
+
opts[:vagrantfile_name] ||= ["Vagrantfile", "vagrantfile"]
|
75
|
+
opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if !opts[:vagrantfile_name].is_a?(Array)
|
76
|
+
|
66
77
|
opts.each do |key, value|
|
67
78
|
instance_variable_set("@#{key}".to_sym, opts[key])
|
68
79
|
end
|
69
80
|
|
70
81
|
@loaded = false
|
82
|
+
@lock_acquired = false
|
83
|
+
|
84
|
+
logger.info("environment") { "Environment initialized (#{self})" }
|
85
|
+
logger.info("environment") { " - cwd: #{cwd}" }
|
86
|
+
logger.info("environment") { " - parent: #{parent}" }
|
87
|
+
logger.info("environment") { " - vm: #{vm}" }
|
71
88
|
end
|
72
89
|
|
73
90
|
#---------------------------------------------------------------
|
@@ -86,7 +103,33 @@ module Vagrant
|
|
86
103
|
#
|
87
104
|
# @return [Pathname]
|
88
105
|
def home_path
|
106
|
+
return parent.home_path if parent
|
107
|
+
return @_home_path if defined?(@_home_path)
|
108
|
+
|
89
109
|
@_home_path ||= Pathname.new(File.expand_path(ENV["VAGRANT_HOME"] || DEFAULT_HOME))
|
110
|
+
logger.info("environment") { "Home path: #{@_home_path}" }
|
111
|
+
|
112
|
+
# This is the old default that Vagrant used to be put things into
|
113
|
+
# up until Vagrant 0.8.0. We keep around an automatic migration
|
114
|
+
# script here in case any old users upgrade.
|
115
|
+
old_home = File.expand_path("~/.vagrant")
|
116
|
+
if File.exists?(old_home) && File.directory?(old_home)
|
117
|
+
logger.info("environment") { "Found both an old and new Vagrantfile. Migration initiated." }
|
118
|
+
|
119
|
+
# We can't migrate if the home directory already exists
|
120
|
+
if File.exists?(@_home_path)
|
121
|
+
ui.warn I18n.t("vagrant.general.home_dir_migration_failed",
|
122
|
+
:old => old_home,
|
123
|
+
:new => @_home_path.to_s)
|
124
|
+
else
|
125
|
+
# If the new home path doesn't exist, simply transition to it
|
126
|
+
ui.info I18n.t("vagrant.general.moving_home_dir", :directory => @_home_path)
|
127
|
+
FileUtils.mv(old_home, @_home_path)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Return the home path
|
132
|
+
@_home_path
|
90
133
|
end
|
91
134
|
|
92
135
|
# The path to the Vagrant tmp directory
|
@@ -249,7 +292,27 @@ module Vagrant
|
|
249
292
|
# @return [Logger]
|
250
293
|
def logger
|
251
294
|
return parent.logger if parent
|
252
|
-
@logger
|
295
|
+
return @logger if @logger
|
296
|
+
|
297
|
+
# Figure out where the output should go to.
|
298
|
+
output = nil
|
299
|
+
if ENV["VAGRANT_LOG"] == "STDOUT"
|
300
|
+
output = STDOUT
|
301
|
+
elsif ENV["VAGRANT_LOG"] == "NULL"
|
302
|
+
output = nil
|
303
|
+
elsif ENV["VAGRANT_LOG"]
|
304
|
+
output = ENV["VAGRANT_LOG"]
|
305
|
+
else
|
306
|
+
output = nil #log_path.join("#{Time.now.to_i}.log")
|
307
|
+
end
|
308
|
+
|
309
|
+
# Create the logger and custom formatter
|
310
|
+
@logger = Logger.new(output)
|
311
|
+
@logger.formatter = Proc.new do |severity, datetime, progname, msg|
|
312
|
+
"#{datetime} - #{progname} - [#{resource}] #{msg}\n"
|
313
|
+
end
|
314
|
+
|
315
|
+
@logger
|
253
316
|
end
|
254
317
|
|
255
318
|
# The root path is the path where the top-most (loaded last)
|
@@ -261,7 +324,13 @@ module Vagrant
|
|
261
324
|
return @root_path if defined?(@root_path)
|
262
325
|
|
263
326
|
root_finder = lambda do |path|
|
264
|
-
|
327
|
+
# Note: To remain compatible with Ruby 1.8, we have to use
|
328
|
+
# a `find` here instead of an `each`.
|
329
|
+
found = vagrantfile_name.find do |rootfile|
|
330
|
+
File.exist?(File.join(path.to_s, rootfile))
|
331
|
+
end
|
332
|
+
|
333
|
+
return path if found
|
265
334
|
return nil if path.root? || !File.exist?(path)
|
266
335
|
root_finder.call(path.parent)
|
267
336
|
end
|
@@ -269,6 +338,39 @@ module Vagrant
|
|
269
338
|
@root_path = root_finder.call(cwd)
|
270
339
|
end
|
271
340
|
|
341
|
+
# This returns the path which Vagrant uses to determine the location
|
342
|
+
# of the file lock. This is specific to each operating system.
|
343
|
+
def lock_path
|
344
|
+
@lock_path || tmp_path.join("vagrant.lock")
|
345
|
+
end
|
346
|
+
|
347
|
+
# This locks Vagrant for the duration of the block passed to this
|
348
|
+
# method. During this time, any other environment which attempts
|
349
|
+
# to lock which points to the same lock file will fail.
|
350
|
+
def lock
|
351
|
+
# This allows multiple locks in the same process to be nested
|
352
|
+
return yield if @lock_acquired
|
353
|
+
|
354
|
+
File.open(lock_path, "w+") do |f|
|
355
|
+
# The file locking fails only if it returns "false." If it
|
356
|
+
# succeeds it returns a 0, so we must explicitly check for
|
357
|
+
# the proper error case.
|
358
|
+
raise Errors::EnvironmentLockedError if f.flock(File::LOCK_EX | File::LOCK_NB) === false
|
359
|
+
|
360
|
+
begin
|
361
|
+
# Mark that we have a lock
|
362
|
+
@lock_acquired = true
|
363
|
+
|
364
|
+
yield
|
365
|
+
ensure
|
366
|
+
# We need to make sure that no matter what this is always
|
367
|
+
# reset to false so we don't think we have a lock when we
|
368
|
+
# actually don't.
|
369
|
+
@lock_acquired = false
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
272
374
|
#---------------------------------------------------------------
|
273
375
|
# Config Methods
|
274
376
|
#---------------------------------------------------------------
|
@@ -301,7 +403,15 @@ module Vagrant
|
|
301
403
|
def load!
|
302
404
|
if !loaded?
|
303
405
|
@loaded = true
|
304
|
-
|
406
|
+
|
407
|
+
if !parent
|
408
|
+
# We only need to check the virtualbox version once, so do it on
|
409
|
+
# the parent most environment and then forget about it
|
410
|
+
logger.info("environment") { "Environment not loaded. Checking virtual box version..." }
|
411
|
+
self.class.check_virtualbox!
|
412
|
+
end
|
413
|
+
|
414
|
+
logger.info("environment") { "Loading configuration..." }
|
305
415
|
load_config!
|
306
416
|
end
|
307
417
|
|
@@ -327,9 +437,26 @@ module Vagrant
|
|
327
437
|
@config_loader ||= Config.new(parent ? parent.config_loader : nil)
|
328
438
|
@config_loader.load_order = [:default, :box, :home, :root, :sub_vm]
|
329
439
|
@config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
|
330
|
-
|
331
|
-
|
332
|
-
|
440
|
+
|
441
|
+
vagrantfile_name.each do |rootfile|
|
442
|
+
if !first_run && vm && box
|
443
|
+
# We load the box Vagrantfile
|
444
|
+
box_vagrantfile = box.directory.join(rootfile)
|
445
|
+
@config_loader.set(:box, box_vagrantfile) if box_vagrantfile.exist?
|
446
|
+
end
|
447
|
+
|
448
|
+
if !first_run && home_path
|
449
|
+
# Load the home Vagrantfile
|
450
|
+
home_vagrantfile = home_path.join(rootfile)
|
451
|
+
@config_loader.set(:home, home_vagrantfile) if home_vagrantfile.exist?
|
452
|
+
end
|
453
|
+
|
454
|
+
if root_path
|
455
|
+
# Load the Vagrantfile in this directory
|
456
|
+
root_vagrantfile = root_path.join(rootfile)
|
457
|
+
@config_loader.set(:root, root_vagrantfile) if root_vagrantfile.exist?
|
458
|
+
end
|
459
|
+
end
|
333
460
|
|
334
461
|
# If this environment is representing a sub-VM, then we push that
|
335
462
|
# proc on as the last configuration.
|
@@ -342,9 +469,6 @@ module Vagrant
|
|
342
469
|
# value in the config ivar.
|
343
470
|
@config = @config_loader.load(self)
|
344
471
|
|
345
|
-
# (re)load the logger
|
346
|
-
@logger = nil
|
347
|
-
|
348
472
|
if first_run
|
349
473
|
# After the first run we want to load the configuration again since
|
350
474
|
# it can change due to box Vagrantfiles and home directory Vagrantfiles
|