Begin working on the #guest method for Machine instances

This commit is contained in:
Mitchell Hashimoto 2012-08-12 16:46:00 -07:00
parent 7efee573b8
commit 28f341ec75
4 changed files with 37 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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: |-

View File

@ -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