diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 27c072902..c3dcf37ad 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -302,7 +302,7 @@ module Vagrant # Create the machine and cache it for future calls. This will also # return the machine from this method. - @machines[cache_key] = Machine.new(name, provider_cls, provider_config, + @machines[cache_key] = Machine.new(name, provider, provider_cls, provider_config, config, machine_data_path, box, self) end diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index cc7802790..2729edab6 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -47,6 +47,11 @@ module Vagrant # @return [Object] attr_reader :provider_config + # The name of the provider. + # + # @return [Symbol] + attr_reader :provider_name + # Initialize a new machine. # # @param [String] name Name of the virtual machine. @@ -60,7 +65,7 @@ module Vagrant # @param [Box] box The box that is backing this virtual machine. # @param [Environment] env The environment that this machine is a # part of. - def initialize(name, provider_cls, provider_config, config, data_dir, box, env, base=false) + def initialize(name, provider_name, provider_cls, provider_config, config, data_dir, box, env, base=false) @logger = Log4r::Logger.new("vagrant::machine") @logger.info("Initializing machine: #{name}") @logger.info(" - Provider: #{provider_cls}") @@ -73,6 +78,7 @@ module Vagrant @env = env @name = name @provider_config = provider_config + @provider_name = provider_name # Read the ID, which is usually in local storage @id = nil diff --git a/plugins/providers/virtualbox/action/check_box.rb b/plugins/providers/virtualbox/action/check_box.rb index 02c6fa866..e3e4346b2 100644 --- a/plugins/providers/virtualbox/action/check_box.rb +++ b/plugins/providers/virtualbox/action/check_box.rb @@ -17,12 +17,15 @@ module VagrantPlugins # Add the box then reload the box collection so that it becomes # aware of it. env[:ui].info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name) - env[:box_collection].add(box_name, box_url) - env[:box_collection].reload! + env[:action_runner].run(Vagrant::Action.action_box_add, { + :box_name => box_name, + :box_provider => env[:machine].provider_name, + :box_url => box_url + }) # Reload the environment and set the VM to be the new loaded VM. - env[:machine].env.reload! - env[:machine] = env[:machine].env.vms[env[:machine].name] + env[:machine] = env[:machine].env.machine( + env[:machine].name, env[:machine].provider_name) end @app.call(env) diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 1009fbfb9..c7abb48b8 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -13,6 +13,7 @@ describe Vagrant::Machine do obj end let(:provider_config) { Object.new } + let(:provider_name) { :test } let(:box) { Object.new } let(:config) { env.config_global } let(:data_dir) { Pathname.new(Tempdir.new.path) } @@ -31,7 +32,7 @@ describe Vagrant::Machine do # Returns a new instance with the test data def new_instance - described_class.new(name, provider_cls, provider_config, + described_class.new(name, provider_name, provider_cls, provider_config, config, data_dir, box, env) end @@ -61,7 +62,7 @@ describe Vagrant::Machine do # Initialize a new machine and verify that we properly receive # the machine we expect. - instance = described_class.new(name, provider_cls, provider_config, + instance = described_class.new(name, provider_name, provider_cls, provider_config, config, data_dir, box, env) received_machine.should eql(instance) end