diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 9d2597d36..69d6c5163 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -226,6 +226,10 @@ module Vagrant error_key(:port_collision_resume) end + class MachineGuestNotReady < VagrantError + error_key(:machine_guest_not_ready) + end + class MultiVMEnvironmentRequired < VagrantError status_code(5) error_key(:multi_vm_required) diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 2f3173901..43abe1b5e 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -123,6 +123,16 @@ module Vagrant @communicator end + # Returns a guest implementation for this machine. The guest implementation + # knows how to do guest-OS specific tasks, such as configuring networks, + # mounting folders, etc. + # + # @return [Object] + def guest + raise Errors::MachineGuestNotReady if !communicator.ready? + # XXX: Todo + end + # This sets the unique ID associated with this machine. This will # persist this ID so that in the future Vagrant will be able to find # this machine again. The unique ID must be absolutely unique to the diff --git a/templates/locales/en.yml b/templates/locales/en.yml index eb9b04165..36c17aa3c 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -85,6 +85,10 @@ en: You specified: %{home_path} interrupted: |- Vagrant exited after cleanup due to external interrupt. + machine_guest_not_ready: |- + Guest-specific operations were attempted on a machine that is not + ready for guest communication. This should not happen and a bug + should be reported. multi_vm_required: |- A multi-vm environment is required for name specification to this command. multi_vm_target_required: |- diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 06275f31c..a8ccc5ab8 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -191,6 +191,25 @@ describe Vagrant::Machine do end end + describe "guest implementation" do + let(:communicator) do + result = double("communicator") + result.stub(:ready?).and_return(true) + result + end + + before(:each) do + instance.stub(:communicator).and_return(communicator) + end + + it "should raise an exception if communication is not ready" do + communicator.should_receive(:ready?).and_return(false) + + expect { instance.guest }. + to raise_error(Vagrant::Errors::MachineGuestNotReady) + end + end + describe "setting the ID" do it "should not have an ID by default" do instance.id.should be_nil