lib/vagrant/vagrantfile.rb in vagrant-unbundled-2.1.2.0 vs lib/vagrant/vagrantfile.rb in vagrant-unbundled-2.1.4.0
- old
+ new
@@ -40,11 +40,11 @@
# can be stored.
# @param [Environment] env The environment running this machine
# @return [Machine]
def machine(name, provider, boxes, data_path, env)
# Load the configuration for the machine
- results = machine_config(name, provider, boxes)
+ results = machine_config(name, provider, boxes, data_path)
box = results[:box]
config = results[:config]
config_errors = results[:config_errors]
config_warnings = results[:config_warnings]
provider_cls = results[:provider_cls]
@@ -105,13 +105,14 @@
# @param [Symbol] name Name of the machine.
# @param [Symbol] provider The provider the machine should
# be backed by (required for provider overrides).
# @param [BoxCollection] boxes BoxCollection to look up the
# box Vagrantfile.
+ # @param [Pathname] data_path Machine data path
# @return [Hash<Symbol, Object>] Various configuration parameters for a
# machine. See the main documentation body for more info.
- def machine_config(name, provider, boxes)
+ def machine_config(name, provider, boxes, data_path=nil)
keys = @keys.dup
sub_machine = @config.vm.defined_vms[name]
if !sub_machine
raise Errors::MachineNotFound,
@@ -168,10 +169,23 @@
# Track the original box so we know if we changed
box = nil
original_box = config.vm.box
original_version = config.vm.box_version
+ # Check if this machine has a local box metadata file
+ # describing the existing guest. If so, load it and
+ # set the box name and version to allow the actual
+ # box in use to be discovered.
+ if data_path
+ meta_file = data_path.join("box_meta")
+ if meta_file.file?
+ box_meta = JSON.parse(meta_file.read)
+ config.vm.box = box_meta["name"]
+ config.vm.box_version = box_meta["version"]
+ end
+ end
+
# The proc below loads the box and provider overrides. This is
# in a proc because it may have to recurse if the provider override
# changes the box.
load_box_proc = lambda do
local_keys = keys.dup
@@ -211,9 +225,14 @@
end
end
# Load the box and provider overrides
load_box_proc.call
+
+ # Ensure box attributes are set to original values in
+ # case they were modified by the local box metadata
+ config.vm.box = original_box
+ config.vm.box_version = original_version
return {
box: box,
provider_cls: provider_cls,
provider_options: provider_options.dup,