core: Machine#reload

This commit is contained in:
Mitchell Hashimoto 2014-08-06 16:46:31 -07:00
parent 8fb3971f18
commit 7f5f720e0a
2 changed files with 35 additions and 4 deletions

View File

@ -115,10 +115,7 @@ module Vagrant
if base if base
@id = name @id = name
else else
# Read the id file from the data directory if it exists as the reload
# ID for the pre-existing physical representation of this machine.
id_file = @data_dir.join("id")
@id = id_file.read.chomp if id_file.file?
end end
# Keep track of where our UUID should be placed # Keep track of where our UUID should be placed
@ -340,6 +337,18 @@ module Vagrant
"#<#{self.class}: #{@name} (#{@provider.class})>" "#<#{self.class}: #{@name} (#{@provider.class})>"
end end
# This reloads the ID of the underlying machine.
def reload
@id = nil
if @data_dir
# Read the id file from the data directory if it exists as the
# ID for the pre-existing physical representation of this machine.
id_file = @data_dir.join("id")
@id = id_file.read.chomp if id_file.file?
end
end
# This returns the SSH info for accessing this machine. This SSH info # This returns the SSH info for accessing this machine. This SSH info
# is queried from the underlying provider. This method returns `nil` if # is queried from the underlying provider. This method returns `nil` if
# the machine is not ready for SSH communication. # the machine is not ready for SSH communication.

View File

@ -448,6 +448,28 @@ describe Vagrant::Machine do
end end
end end
describe "#reload" do
before do
allow(provider).to receive(:machine_id_changed)
subject.id = "foo"
end
it "should read the ID" do
subject.reload
expect(subject.id).to eq("foo")
end
it "should read the updated ID" do
new_instance.id = "bar"
subject.reload
expect(subject.id).to eq("bar")
end
end
describe "ssh info" do describe "ssh info" do
describe "with the provider returning nil" do describe "with the provider returning nil" do
it "should return nil if the provider returns nil" do it "should return nil if the provider returns nil" do