Loading VMs and created VMs now point back to the environment they belong to
This commit is contained in:
parent
2661845b5d
commit
689f69bd4c
|
@ -161,6 +161,7 @@ module Vagrant
|
|||
|
||||
File.open(dotfile_path) do |f|
|
||||
@vm = Vagrant::VM.find(f.read)
|
||||
@vm.env = self
|
||||
end
|
||||
rescue Errno::ENOENT
|
||||
@vm = nil
|
||||
|
@ -170,10 +171,17 @@ module Vagrant
|
|||
# Methods to manage VM
|
||||
#---------------------------------------------------------------
|
||||
|
||||
# Sets the VM to a new VM. This is not too useful but is used
|
||||
# in {Command.up}. This will very likely be refactored at a later
|
||||
# time.
|
||||
def create_vm
|
||||
@vm = VM.new
|
||||
@vm.env = self
|
||||
@vm
|
||||
end
|
||||
|
||||
# Persists this environment's VM to the dotfile so it can be
|
||||
# re-loaded at a later time.
|
||||
def persist_vm
|
||||
# Save to the dotfile for this project
|
||||
File.open(dotfile_path, 'w+') do |f|
|
||||
|
@ -184,6 +192,7 @@ module Vagrant
|
|||
ActiveList.add(vm)
|
||||
end
|
||||
|
||||
# Removes this environment's VM from the dotfile.
|
||||
def depersist_vm
|
||||
# Delete the dotfile if it exists
|
||||
File.delete(dotfile_path) if File.exist?(dotfile_path)
|
||||
|
|
|
@ -2,6 +2,7 @@ module Vagrant
|
|||
class VM < Actions::Runner
|
||||
include Vagrant::Util
|
||||
|
||||
attr_accessor :env
|
||||
attr_accessor :vm
|
||||
attr_accessor :from
|
||||
|
||||
|
|
|
@ -338,6 +338,7 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
|
||||
should "loading of the uuid from the dotfile" do
|
||||
vm = mock("vm")
|
||||
vm.expects(:env=).with(@env)
|
||||
|
||||
filemock = mock("filemock")
|
||||
filemock.expects(:read).returns("foo")
|
||||
|
@ -450,6 +451,16 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
assert !@env.vm.nil?
|
||||
assert @env.vm.is_a?(Vagrant::VM)
|
||||
end
|
||||
|
||||
should "set the new VM's environment to the env" do
|
||||
@env.create_vm
|
||||
assert_equal @env, @env.vm.env
|
||||
end
|
||||
|
||||
should "return the new VM" do
|
||||
result = @env.create_vm
|
||||
assert result.is_a?(Vagrant::VM)
|
||||
end
|
||||
end
|
||||
|
||||
context "persisting the VM into a file" do
|
||||
|
|
Loading…
Reference in New Issue