vagrantup 0.6.9 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +37 -0
  4. data/Gemfile +0 -8
  5. data/README.md +5 -0
  6. data/config/default.rb +1 -3
  7. data/contrib/README.md +12 -0
  8. data/contrib/emacs/vagrant.el +8 -0
  9. data/contrib/vim/vagrantfile.vim +9 -0
  10. data/lib/vagrant/action/box/download.rb +0 -1
  11. data/lib/vagrant/action/box.rb +11 -0
  12. data/lib/vagrant/action/builtin.rb +1 -2
  13. data/lib/vagrant/action/env.rb +7 -0
  14. data/lib/vagrant/action/general.rb +8 -0
  15. data/lib/vagrant/action/vm/boot.rb +3 -2
  16. data/lib/vagrant/action/vm/check_box.rb +1 -0
  17. data/lib/vagrant/action/vm/clean_machine_folder.rb +1 -1
  18. data/lib/vagrant/action/vm/destroy.rb +1 -1
  19. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +7 -12
  20. data/lib/vagrant/action/vm/network.rb +1 -1
  21. data/lib/vagrant/action/vm/nfs.rb +3 -1
  22. data/lib/vagrant/action/vm/provision.rb +14 -25
  23. data/lib/vagrant/action/vm/share_folders.rb +11 -4
  24. data/lib/vagrant/action/vm.rb +30 -0
  25. data/lib/vagrant/action.rb +12 -0
  26. data/lib/vagrant/command.rb +25 -0
  27. data/lib/vagrant/config/base.rb +17 -3
  28. data/lib/vagrant/config/ssh.rb +2 -2
  29. data/lib/vagrant/config/top.rb +61 -0
  30. data/lib/vagrant/config/vagrant.rb +1 -6
  31. data/lib/vagrant/config/vm/provisioner.rb +56 -0
  32. data/lib/vagrant/config/vm/sub_vm.rb +17 -0
  33. data/lib/vagrant/config/vm.rb +34 -20
  34. data/lib/vagrant/config.rb +78 -128
  35. data/lib/vagrant/downloaders/file.rb +1 -0
  36. data/lib/vagrant/downloaders/http.rb +9 -0
  37. data/lib/vagrant/downloaders.rb +7 -0
  38. data/lib/vagrant/environment.rb +26 -14
  39. data/lib/vagrant/errors.rb +5 -15
  40. data/lib/vagrant/hosts.rb +7 -0
  41. data/lib/vagrant/provisioners/base.rb +19 -1
  42. data/lib/vagrant/provisioners/chef.rb +31 -52
  43. data/lib/vagrant/provisioners/chef_server.rb +34 -10
  44. data/lib/vagrant/provisioners/chef_solo.rb +31 -9
  45. data/lib/vagrant/provisioners/puppet.rb +111 -60
  46. data/lib/vagrant/provisioners/puppet_server.rb +57 -0
  47. data/lib/vagrant/provisioners.rb +8 -0
  48. data/lib/vagrant/ssh/session.rb +81 -0
  49. data/lib/vagrant/ssh.rb +6 -76
  50. data/lib/vagrant/systems/base.rb +16 -1
  51. data/lib/vagrant/systems/debian.rb +26 -0
  52. data/lib/vagrant/systems/gentoo.rb +27 -0
  53. data/lib/vagrant/systems/linux/config.rb +21 -0
  54. data/lib/vagrant/systems/linux/error.rb +9 -0
  55. data/lib/vagrant/systems/linux.rb +14 -56
  56. data/lib/vagrant/systems/redhat.rb +31 -0
  57. data/lib/vagrant/systems.rb +9 -0
  58. data/lib/vagrant/test_helpers.rb +1 -1
  59. data/lib/vagrant/version.rb +1 -1
  60. data/lib/vagrant/vm.rb +25 -5
  61. data/lib/vagrant.rb +14 -18
  62. data/templates/chef_solo_solo.erb +11 -3
  63. data/templates/commands/init/Vagrantfile.erb +13 -11
  64. data/templates/locales/en.yml +76 -26
  65. data/templates/{network_entry.erb → network_entry_debian.erb} +0 -0
  66. data/templates/network_entry_gentoo.erb +7 -0
  67. data/templates/network_entry_redhat.erb +8 -0
  68. data/templates/ssh_config.erb +1 -1
  69. data/test/vagrant/action/vm/check_box_test.rb +1 -0
  70. data/test/vagrant/action/vm/clean_machine_folder_test.rb +6 -4
  71. data/test/vagrant/action/vm/destroy_test.rb +1 -1
  72. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +10 -7
  73. data/test/vagrant/action/vm/nfs_test.rb +7 -1
  74. data/test/vagrant/action/vm/provision_test.rb +24 -79
  75. data/test/vagrant/action/vm/share_folders_test.rb +6 -1
  76. data/test/vagrant/command/helpers_test.rb +2 -2
  77. data/test/vagrant/config/base_test.rb +0 -6
  78. data/test/vagrant/config/vagrant_test.rb +0 -8
  79. data/test/vagrant/config/vm/provisioner_test.rb +92 -0
  80. data/test/vagrant/config/vm_test.rb +8 -0
  81. data/test/vagrant/config_test.rb +49 -89
  82. data/test/vagrant/downloaders/file_test.rb +18 -4
  83. data/test/vagrant/environment_test.rb +36 -12
  84. data/test/vagrant/provisioners/base_test.rb +28 -1
  85. data/test/vagrant/provisioners/chef_server_test.rb +50 -41
  86. data/test/vagrant/provisioners/chef_solo_test.rb +39 -16
  87. data/test/vagrant/provisioners/chef_test.rb +11 -81
  88. data/test/vagrant/provisioners/puppet_server_test.rb +69 -0
  89. data/test/vagrant/provisioners/puppet_test.rb +116 -69
  90. data/test/vagrant/{ssh_session_test.rb → ssh/session_test.rb} +0 -0
  91. data/test/vagrant/ssh_test.rb +20 -7
  92. data/test/vagrant/systems/base_test.rb +18 -0
  93. data/test/vagrant/systems/linux_test.rb +2 -2
  94. data/test/vagrant/vm_test.rb +33 -5
  95. data/vagrant.gemspec +6 -5
  96. metadata +38 -14
  97. data/lib/vagrant/action/vm/disable_networks.rb +0 -34
  98. data/lib/vagrant/util/glob_loader.rb +0 -24
  99. data/test/vagrant/action/vm/disable_networks_test.rb +0 -48
@@ -0,0 +1,56 @@
1
+ module Vagrant
2
+ class Config
3
+ class VMConfig < Base
4
+ # Represents a single configured provisioner for a VM.
5
+ class Provisioner
6
+ attr_reader :top
7
+ attr_reader :shortcut
8
+ attr_reader :provisioner
9
+ attr_reader :config
10
+
11
+ def initialize(top, shortcut, options=nil, &block)
12
+ @top = top
13
+ @shortcut = shortcut
14
+ @provisioner = shortcut
15
+ @provisioner = Provisioners::Base.registered[shortcut] if shortcut.is_a?(Symbol)
16
+ @config = nil
17
+
18
+ configure(options, &block)
19
+ end
20
+
21
+ # Configures the provisioner if it can (if it is valid).
22
+ def configure(options=nil, &block)
23
+ # We don't want ancestors to be searched. This is the default in 1.8,
24
+ # but not in 1.9, hence this hackery.
25
+ const_args = ["Config"]
26
+ const_args << false if RUBY_VERSION >= "1.9"
27
+
28
+ # We assume that every provisioner has a `Config` class beneath
29
+ # it for configuring.
30
+ return if !@provisioner || !@provisioner.const_defined?(*const_args)
31
+
32
+ # Instantiate the config class and configure it
33
+ @config = @provisioner.const_get(*const_args).new
34
+ @config.top = top
35
+ @config.set_options(options) if options
36
+ block.call(@config) if block
37
+ end
38
+
39
+ def validate(errors)
40
+ if !provisioner
41
+ # If we don't have a provisioner then the whole thing is invalid.
42
+ errors.add(I18n.t("vagrant.config.vm.provisioner_not_found", :shortcut => shortcut))
43
+ return
44
+ end
45
+
46
+ if !(provisioner <= Provisioners::Base)
47
+ errors.add(I18n.t("vagrant.config.vm.provisioner_invalid_class", :shortcut => shortcut))
48
+ end
49
+
50
+ # Pass on validation to the provisioner config
51
+ config.validate(errors) if config
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ module Vagrant
2
+ class Config
3
+ class VMConfig < Base
4
+ # Represents a single sub-VM in a multi-VM environment.
5
+ class SubVM
6
+ include Util::StackedProcRunner
7
+
8
+ attr_reader :options
9
+
10
+ def initialize
11
+ @options = {}
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -1,3 +1,6 @@
1
+ require 'vagrant/config/vm/sub_vm'
2
+ require 'vagrant/config/vm/provisioner'
3
+
1
4
  module Vagrant
2
5
  class Config
3
6
  class VMConfig < Base
@@ -14,28 +17,17 @@ module Vagrant
14
17
  attr_reader :forwarded_ports
15
18
  attr_reader :shared_folders
16
19
  attr_reader :network_options
17
- attr_reader :hd_location
20
+ attr_reader :provisioners
18
21
  attr_accessor :disk_image_format
19
- attr_accessor :provisioner
20
22
  attr_writer :shared_folder_uid
21
23
  attr_writer :shared_folder_gid
22
24
  attr_accessor :system
23
25
 
24
- # Represents a SubVM. This class is only used here in the VMs
25
- # hash.
26
- class SubVM
27
- include Util::StackedProcRunner
28
-
29
- def options
30
- @options ||= {}
31
- end
32
- end
33
-
34
26
  def initialize
35
27
  @forwarded_ports = {}
36
28
  @shared_folders = {}
37
- @provisioner = nil
38
29
  @network_options = []
30
+ @provisioners = []
39
31
  end
40
32
 
41
33
  def forward_port(name, guestport, hostport, options=nil)
@@ -68,6 +60,17 @@ module Vagrant
68
60
  @network_options[options[:adapter]] = options
69
61
  end
70
62
 
63
+ def provision(name, options=nil, &block)
64
+ @provisioners << Provisioner.new(top, name, options, &block)
65
+ end
66
+
67
+ # This shows an error message to smooth the transition for the
68
+ # backwards incompatible provisioner syntax change introduced
69
+ # in Vagrant 0.7.0.
70
+ def provisioner=(_value)
71
+ raise Errors::VagrantError, :_key => :provisioner_equals_not_supported
72
+ end
73
+
71
74
  def shared_folder_uid
72
75
  @shared_folder_uid || env.config.ssh.username
73
76
  end
@@ -95,14 +98,25 @@ module Vagrant
95
98
  end
96
99
 
97
100
  def define(name, options=nil, &block)
101
+ name = name.to_sym
98
102
  options ||= {}
103
+
104
+ # Add the name to the array of VM keys. This array is used to
105
+ # preserve the order in which VMs are defined.
99
106
  defined_vm_keys << name
100
- defined_vms[name.to_sym] ||= SubVM.new
101
- defined_vms[name.to_sym].options.merge!(options)
102
- defined_vms[name.to_sym].push_proc(&block)
107
+
108
+ # Add the SubVM to the hash of defined VMs
109
+ defined_vms[name] ||= SubVM.new
110
+ defined_vms[name].options.merge!(options)
111
+ defined_vms[name].push_proc(&block)
103
112
  end
104
113
 
105
114
  def validate(errors)
115
+ errors.add(I18n.t("vagrant.config.vm.box_missing")) if !box
116
+ errors.add(I18n.t("vagrant.config.vm.box_not_found", :name => box)) if box && !box_url && !env.box
117
+ errors.add(I18n.t("vagrant.config.vm.boot_mode_invalid")) if ![:vrdp, :gui].include?(boot_mode.to_sym)
118
+ errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if env.box && !base_mac
119
+
106
120
  shared_folders.each do |name, options|
107
121
  if !File.directory?(File.expand_path(options[:hostpath].to_s, env.root_path))
108
122
  errors.add(I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",
@@ -111,10 +125,10 @@ module Vagrant
111
125
  end
112
126
  end
113
127
 
114
- errors.add(I18n.t("vagrant.config.vm.box_missing")) if !box
115
- errors.add(I18n.t("vagrant.config.vm.box_not_found", :name => box)) if box && !box_url && !env.box
116
- errors.add(I18n.t("vagrant.config.vm.boot_mode_invalid")) if ![:vrdp, :gui].include?(boot_mode.to_sym)
117
- errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if env.box && !base_mac
128
+ # Each provisioner can validate itself
129
+ provisioners.each do |prov|
130
+ prov.validate(errors)
131
+ end
118
132
  end
119
133
  end
120
134
  end
@@ -1,5 +1,13 @@
1
1
  require 'vagrant/config/base'
2
2
  require 'vagrant/config/error_recorder'
3
+ require 'vagrant/config/top'
4
+
5
+ # The built-in configuration classes
6
+ require 'vagrant/config/vagrant'
7
+ require 'vagrant/config/ssh'
8
+ require 'vagrant/config/nfs'
9
+ require 'vagrant/config/vm'
10
+ require 'vagrant/config/package'
3
11
 
4
12
  module Vagrant
5
13
  # The config class is responsible for loading Vagrant configurations, which
@@ -17,157 +25,99 @@ module Vagrant
17
25
  # class you are looking for. Loading configuration is quite easy. The following
18
26
  # example assumes `env` is already a loaded instance of {Environment}:
19
27
  #
20
- # config = Vagrant::Config.new(env)
21
- # config.queue << "/path/to/some/Vagrantfile"
22
- # result = config.load!
28
+ # config = Vagrant::Config.new
29
+ # config.set(:first, "/path/to/some/Vagrantfile")
30
+ # config.set(:second, "/path/to/another/Vagrantfile")
31
+ # config.load_order = [:first, :second]
32
+ # result = config.load(env)
23
33
  #
24
34
  # p "Your box is: #{result.vm.box}"
25
35
  #
36
+ # The load order determines what order the config files specified are loaded.
37
+ # If a key is not mentioned (for example if above the load order was set to
38
+ # `[:first]`, therefore `:second` was not mentioned), then that config file
39
+ # won't be loaded.
26
40
  class Config
27
- extend Util::StackedProcRunner
28
-
29
- @@config = nil
30
-
31
- attr_reader :queue
32
-
33
- class << self
34
- # Resets the current loaded config object to the specified environment.
35
- # This clears the proc stack and initializes a new {Top} for loading.
36
- # This method shouldn't be called directly, instead use an instance of this
37
- # class for config loading.
38
- #
39
- # @param [Environment] env
40
- def reset!(env=nil)
41
- @@config = nil
42
- proc_stack.clear
41
+ # An array of symbols specifying the load order for the procs.
42
+ attr_accessor :load_order
43
+ attr_reader :procs
43
44
 
44
- # Reset the configuration to the specified environment
45
- config(env)
46
- end
47
-
48
- # Returns the current {Top} configuration object. While this is still
49
- # here for implementation purposes, it shouldn't be called directly. Instead,
50
- # use an instance of this class.
51
- def config(env=nil)
52
- @@config ||= Config::Top.new(env)
53
- end
54
-
55
- # Adds the given proc/block to the stack of config procs which are all
56
- # run later on a single config object. This is the main way to configure
57
- # Vagrant, and is how all Vagrantfiles are formatted:
58
- #
59
- # Vagrant::Config.run do |config|
60
- # # ...
61
- # end
62
- #
63
- def run(&block)
64
- push_proc(&block)
65
- end
66
-
67
- # Executes all the config procs onto the currently loaded {Top} object,
68
- # and returns the final configured object. This also validates the
69
- # configuration by calling {Top#validate!} on every configuration
70
- # class.
71
- def execute!
72
- config_object ||= config
73
- run_procs!(config_object)
74
- config_object
75
- end
45
+ # This is the method which is called by all Vagrantfiles to configure Vagrant.
46
+ # This method expects a block which accepts a single argument representing
47
+ # an instance of the {Config::Top} class.
48
+ #
49
+ # Note that the block is not run immediately. Instead, it's proc is stored
50
+ # away for execution later.
51
+ def self.run(&block)
52
+ # Store it for later
53
+ @last_procs ||= []
54
+ @last_procs << block
76
55
  end
77
56
 
78
- # Initialize a {Config} object for the given {Environment}.
57
+ # Returns the last proc which was activated for the class via {run}. This
58
+ # also sets the last proc to `nil` so that calling this method multiple times
59
+ # will not return duplicates.
79
60
  #
80
- # @param [Environment] env Environment which config object will be part
81
- # of.
82
- def initialize(env)
83
- @env = env
84
- @queue = []
61
+ # @return [Proc]
62
+ def self.last_proc
63
+ value = @last_procs
64
+ @last_procs = nil
65
+ value
85
66
  end
86
67
 
87
- # Loads the queue of files/procs, executes them in the proper
88
- # sequence, and returns the resulting configuration object.
89
- def load!
90
- self.class.reset!(@env)
68
+ def initialize(parent=nil)
69
+ @procs = {}
70
+ @load_order = []
91
71
 
92
- queue.flatten.each do |item|
93
- if item.is_a?(String) && File.exist?(item)
94
- begin
95
- load item
96
- rescue SyntaxError => e
97
- # Report syntax errors in a nice way for Vagrantfiles
98
- raise Errors::VagrantfileSyntaxError, :file => e.message
99
- end
100
- elsif item.is_a?(Proc)
101
- self.class.run(&item)
102
- end
72
+ if parent
73
+ # Shallow copy the procs and load order from parent if given
74
+ @procs = parent.procs.dup
75
+ @load_order = parent.load_order.dup
103
76
  end
77
+ end
104
78
 
105
- return self.class.execute!
79
+ # Adds a Vagrantfile to be loaded to the queue of config procs. Note
80
+ # that this causes the Vagrantfile file to be loaded at this point,
81
+ # and it will never be loaded again.
82
+ def set(key, path)
83
+ return if @procs.has_key?(key)
84
+ @procs[key] = [path].flatten.map(&method(:proc_for)).flatten
106
85
  end
107
- end
108
86
 
109
- class Config
110
- # This class is the "top" configure class, which handles registering
111
- # other configuration classes as well as validation of all configured
112
- # classes. This is the object which is returned by {Environment#config}
113
- # and has accessors to all other configuration classes.
87
+ # Loads the added procs using the set `load_order` attribute and returns
88
+ # the {Config::Top} object result. The configuration is loaded for the
89
+ # given {Environment} object.
114
90
  #
115
- # If you're looking to create your own configuration class, see {Base}.
116
- class Top < Base
117
- @@configures = {} if !defined?(@@configures)
118
-
119
- class << self
120
- # The list of registered configuration classes as well as the key
121
- # they're registered under.
122
- def configures_list
123
- @@configures ||= {}
124
- end
125
-
126
- # Registers a configuration class with the given key. This method shouldn't
127
- # be called. Instead, inherit from {Base} and call {Base.configures}.
128
- def configures(key, klass)
129
- configures_list[key] = klass
130
- attr_reader key.to_sym
91
+ # @param [Environment] env
92
+ def load(env)
93
+ config = Top.new(env)
94
+
95
+ # Only run the procs specified in the load order, in the order
96
+ # specified.
97
+ load_order.each do |key|
98
+ if @procs[key]
99
+ @procs[key].each do |proc|
100
+ proc.call(config) if proc
101
+ end
131
102
  end
132
103
  end
133
104
 
134
- def initialize(env=nil)
135
- self.class.configures_list.each do |key, klass|
136
- config = klass.new
137
- config.env = env
138
- config.top = self
139
- instance_variable_set("@#{key}".to_sym, config)
140
- end
105
+ config
106
+ end
141
107
 
142
- @env = env
143
- end
108
+ protected
144
109
 
145
- # Validates the configuration classes of this instance and raises an
146
- # exception if they are invalid. If you are implementing a custom configuration
147
- # class, the method you want to implement is {Base#validate}. This is
148
- # the method that checks all the validation, not one which defines
149
- # validation rules.
150
- def validate!
151
- # Validate each of the configured classes and store the results into
152
- # a hash.
153
- errors = self.class.configures_list.inject({}) do |container, data|
154
- key, _ = data
155
- recorder = ErrorRecorder.new
156
- send(key.to_sym).validate(recorder)
157
- container[key.to_sym] = recorder if !recorder.errors.empty?
158
- container
159
- end
110
+ def proc_for(path)
111
+ return nil if !path
112
+ return path if path.is_a?(Proc)
160
113
 
161
- return if errors.empty?
162
- raise Errors::ConfigValidationFailed, :messages => Util::TemplateRenderer.render("config/validation_failed", :errors => errors)
114
+ begin
115
+ Kernel.load path if File.exist?(path)
116
+ return self.class.last_proc
117
+ rescue SyntaxError => e
118
+ # Report syntax errors in a nice way for Vagrantfiles
119
+ raise Errors::VagrantfileSyntaxError, :file => e.message
163
120
  end
164
121
  end
165
122
  end
166
123
  end
167
-
168
- # The built-in configuration classes
169
- require 'vagrant/config/vagrant'
170
- require 'vagrant/config/ssh'
171
- require 'vagrant/config/nfs'
172
- require 'vagrant/config/vm'
173
- require 'vagrant/config/package'
@@ -14,6 +14,7 @@ module Vagrant
14
14
  end
15
15
 
16
16
  def download!(source_url, destination_file)
17
+ env.ui.info I18n.t("vagrant.downloaders.file.download")
17
18
  FileUtils.cp(source_url, destination_file.path)
18
19
  end
19
20
  end
@@ -25,7 +25,16 @@ module Vagrant
25
25
  end
26
26
 
27
27
  http.start do |h|
28
+ env.ui.info I18n.t("vagrant.downloaders.http.download", :url => source_url)
29
+
28
30
  h.request_get(uri.request_uri) do |response|
31
+ if response.is_a?(Net::HTTPRedirection)
32
+ # Follow the HTTP redirect.
33
+ # TODO: Error on some redirect limit
34
+ download!(response["Location"], destination_file)
35
+ return
36
+ end
37
+
29
38
  total = response.content_length
30
39
  progress = 0
31
40
  segment_count = 0
@@ -0,0 +1,7 @@
1
+ module Vagrant
2
+ module Downloaders
3
+ autoload :Base, 'vagrant/downloaders/base'
4
+ autoload :File, 'vagrant/downloaders/file'
5
+ autoload :HTTP, 'vagrant/downloaders/http'
6
+ end
7
+ end
@@ -9,6 +9,7 @@ module Vagrant
9
9
  ROOTFILE_NAME = "Vagrantfile"
10
10
  HOME_SUBDIRS = ["tmp", "boxes", "logs"]
11
11
  DEFAULT_VM = :default
12
+ DEFAULT_HOME = "~/.vagrant"
12
13
 
13
14
  # Parent environment (in the case of multi-VMs)
14
15
  attr_reader :parent
@@ -23,6 +24,9 @@ module Vagrant
23
24
  # The {UI} object to communicate with the outside world.
24
25
  attr_writer :ui
25
26
 
27
+ # The {Config} object representing the Vagrantfile loader
28
+ attr_reader :config_loader
29
+
26
30
  #---------------------------------------------------------------
27
31
  # Class Methods
28
32
  #---------------------------------------------------------------
@@ -32,8 +36,7 @@ module Vagrant
32
36
  def check_virtualbox!
33
37
  version = VirtualBox.version
34
38
  raise Errors::VirtualBoxNotDetected if version.nil?
35
- raise Errors::VirtualBoxInvalidVersion, :version => version.to_s if version.to_f < 3.2
36
- raise Errors::VirtualBoxInvalidOSE, :version => version.to_s if version.to_s.downcase.include?("ose")
39
+ raise Errors::VirtualBoxInvalidVersion, :version => version.to_s if version.to_f < 4.0
37
40
  rescue Errors::VirtualBoxNotDetected
38
41
  # On 64-bit Windows, show a special error. This error is a subclass
39
42
  # of VirtualBoxNotDetected, so libraries which use Vagrant can just
@@ -79,12 +82,11 @@ module Vagrant
79
82
  root_path.join(config.vagrant.dotfile_name) rescue nil
80
83
  end
81
84
 
82
- # The path to the home directory, expanded relative to the root path,
83
- # and converted into a Pathname object.
85
+ # The path to the home directory and converted into a Pathname object.
84
86
  #
85
87
  # @return [Pathname]
86
88
  def home_path
87
- @_home_path ||= Pathname.new(File.expand_path(config.vagrant.home, root_path))
89
+ @_home_path ||= Pathname.new(File.expand_path(ENV["VAGRANT_HOME"] || DEFAULT_HOME))
88
90
  end
89
91
 
90
92
  # The path to the Vagrant tmp directory
@@ -114,7 +116,8 @@ module Vagrant
114
116
  #
115
117
  # @return [String]
116
118
  def resource
117
- vm.name rescue "vagrant"
119
+ result = vm.name rescue nil
120
+ result || "vagrant"
118
121
  end
119
122
 
120
123
  # Returns the collection of boxes for the environment.
@@ -146,7 +149,7 @@ module Vagrant
146
149
  #
147
150
  # @return [Array<VM>]
148
151
  def vms_ordered
149
- @vms_enum ||= config.vm.defined_vm_keys.map {|name| @vms[name]}
152
+ @vms_enum ||= config.vm.defined_vm_keys.map { |name| @vms[name] }
150
153
  end
151
154
 
152
155
  # Returns the primary VM associated with this environment. This
@@ -305,6 +308,14 @@ module Vagrant
305
308
  self
306
309
  end
307
310
 
311
+ # Reloads the configuration of this environment.
312
+ def reload_config!
313
+ @config = nil
314
+ @config_loader = nil
315
+ load_config!
316
+ self
317
+ end
318
+
308
319
  # Loads this environment's configuration and stores it in the {#config}
309
320
  # variable. The configuration loaded by this method is specified to
310
321
  # this environment, meaning that it will use the given root directory
@@ -313,22 +324,23 @@ module Vagrant
313
324
  first_run = @config.nil?
314
325
 
315
326
  # First load the initial, non config-dependent Vagrantfiles
316
- loader = Config.new(self)
317
- loader.queue << File.expand_path("config/default.rb", Vagrant.source_root)
318
- loader.queue << File.join(box.directory, ROOTFILE_NAME) if !first_run && box
319
- loader.queue << File.join(home_path, ROOTFILE_NAME) if !first_run && home_path
320
- loader.queue << File.join(root_path, ROOTFILE_NAME) if root_path
327
+ @config_loader ||= Config.new(parent ? parent.config_loader : nil)
328
+ @config_loader.load_order = [:default, :box, :home, :root, :sub_vm]
329
+ @config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
330
+ @config_loader.set(:box, File.join(box.directory, ROOTFILE_NAME)) if !first_run && vm && box
331
+ @config_loader.set(:home, File.join(home_path, ROOTFILE_NAME)) if !first_run && home_path
332
+ @config_loader.set(:root, File.join(root_path, ROOTFILE_NAME)) if root_path
321
333
 
322
334
  # If this environment is representing a sub-VM, then we push that
323
335
  # proc on as the last configuration.
324
336
  if vm
325
337
  subvm = parent.config.vm.defined_vms[vm.name]
326
- loader.queue << subvm.proc_stack if subvm
338
+ @config_loader.set(:sub_vm, subvm.proc_stack) if subvm
327
339
  end
328
340
 
329
341
  # Execute the configuration stack and store the result as the final
330
342
  # value in the config ivar.
331
- @config = loader.load!
343
+ @config = @config_loader.load(self)
332
344
 
333
345
  # (re)load the logger
334
346
  @logger = nil
@@ -230,16 +230,6 @@ module Vagrant
230
230
  error_key(:dotfile_error, "vagrant.actions.vm.persist")
231
231
  end
232
232
 
233
- class ProvisionInvalidClass < VagrantError
234
- status_code(35)
235
- error_key(:invalid_class, "vagrant.actions.vm.provision")
236
- end
237
-
238
- class ProvisionUnknownType < VagrantError
239
- status_code(36)
240
- error_key(:unknown_type, "vagrant.actions.vm.provision")
241
- end
242
-
243
233
  class SSHAuthenticationFailed < VagrantError
244
234
  status_code(11)
245
235
  error_key(:ssh_authentication_failed)
@@ -255,6 +245,11 @@ module Vagrant
255
245
  error_key(:ssh_key_bad_permissions)
256
246
  end
257
247
 
248
+ class SSHPortNotDetected < VagrantError
249
+ status_code(50)
250
+ error_key(:ssh_port_not_detected)
251
+ end
252
+
258
253
  class SSHUnavailable < VagrantError
259
254
  status_code(45)
260
255
  error_key(:ssh_unavailable)
@@ -275,11 +270,6 @@ module Vagrant
275
270
  error_key(:vagrantfile_syntax_error)
276
271
  end
277
272
 
278
- class VirtualBoxInvalidOSE < VagrantError
279
- status_code(9)
280
- error_key(:virtualbox_invalid_ose)
281
- end
282
-
283
273
  class VirtualBoxInvalidVersion < VagrantError
284
274
  status_code(17)
285
275
  error_key(:virtualbox_invalid_version)
@@ -0,0 +1,7 @@
1
+ module Vagrant
2
+ module Hosts
3
+ autoload :Base, 'vagrant/hosts/base'
4
+ autoload :BSD, 'vagrant/hosts/bsd'
5
+ autoload :Linux, 'vagrant/hosts/linux'
6
+ end
7
+ end
@@ -11,8 +11,26 @@ module Vagrant
11
11
  # {Vagrant::Action::Environment}
12
12
  attr_reader :action_env
13
13
 
14
- def initialize(env)
14
+ # The configuration for this provisioner. This will be an instance of
15
+ # the `Config` class which is part of the provisioner.
16
+ attr_reader :config
17
+
18
+ # Registers a provisioner with a given shortcut. This allows that provisioner
19
+ # to be referenced with the shortcut.
20
+ #
21
+ # @param [Symbol] shortcut
22
+ def self.register(shortcut)
23
+ registered[shortcut] = self
24
+ end
25
+
26
+ # Returns the provisioner associated with the given shortcut.
27
+ def self.registered
28
+ @@registered ||= {}
29
+ end
30
+
31
+ def initialize(env, config)
15
32
  @action_env = env
33
+ @config = config
16
34
  end
17
35
 
18
36
  # Returns the actual {Vagrant::Environment} which this provisioner