Change `vm` attribute to be `runner` on action base to reflect what it now is.
This commit is contained in:
parent
35762a4308
commit
6b705cbe42
|
@ -5,7 +5,7 @@ module Vagrant
|
||||||
# action should define any callbacks that it will call, or
|
# action should define any callbacks that it will call, or
|
||||||
# attach itself to some callbacks on the VM object.
|
# attach itself to some callbacks on the VM object.
|
||||||
class Base
|
class Base
|
||||||
attr_reader :vm
|
attr_reader :runner
|
||||||
|
|
||||||
# Included so subclasses don't need to include it themselves.
|
# Included so subclasses don't need to include it themselves.
|
||||||
include Vagrant::Util
|
include Vagrant::Util
|
||||||
|
@ -17,8 +17,8 @@ module Vagrant
|
||||||
# would be instance_evaling the vm instance to include a module so
|
# would be instance_evaling the vm instance to include a module so
|
||||||
# additionally functionality could be defined on the vm which other
|
# additionally functionality could be defined on the vm which other
|
||||||
# action `prepare` methods may rely on.
|
# action `prepare` methods may rely on.
|
||||||
def initialize(vm, *args)
|
def initialize(runner, *args)
|
||||||
@vm = vm
|
@runner = runner
|
||||||
end
|
end
|
||||||
|
|
||||||
# This method is called once per action, allowing the action
|
# This method is called once per action, allowing the action
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module Box
|
||||||
|
# An action which acts on a box by downloading the box file from
|
||||||
|
# the given URI into a temporary location.
|
||||||
|
class Download < Base
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ module Vagrant
|
||||||
ovf_path = File.join(folder, "#{name}.ovf")
|
ovf_path = File.join(folder, "#{name}.ovf")
|
||||||
|
|
||||||
logger.info "Exporting required VM files to directory: #{folder} ..."
|
logger.info "Exporting required VM files to directory: #{folder} ..."
|
||||||
@vm.export(ovf_path)
|
@runner.export(ovf_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Vagrant
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
logger.info "Deleting any previously set forwarded ports..."
|
logger.info "Deleting any previously set forwarded ports..."
|
||||||
@vm.vm.forwarded_ports.collect { |p| p.destroy(true) }
|
@runner.vm.forwarded_ports.collect { |p| p.destroy(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def forward_ports
|
def forward_ports
|
||||||
|
@ -21,10 +21,10 @@ module Vagrant
|
||||||
port.name = name
|
port.name = name
|
||||||
port.hostport = options[:hostport]
|
port.hostport = options[:hostport]
|
||||||
port.guestport = options[:guestport]
|
port.guestport = options[:guestport]
|
||||||
@vm.vm.forwarded_ports << port
|
@runner.vm.forwarded_ports << port
|
||||||
end
|
end
|
||||||
|
|
||||||
@vm.vm.save(true)
|
@runner.vm.save(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,11 +10,11 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
@vm.invoke_around_callback(:import) do
|
@runner.invoke_around_callback(:import) do
|
||||||
Busy.busy do
|
Busy.busy do
|
||||||
logger.info "Importing base VM (#{@ovf_file})..."
|
logger.info "Importing base VM (#{@ovf_file})..."
|
||||||
# Use the first argument passed to the action
|
# Use the first argument passed to the action
|
||||||
@vm.vm = VirtualBox::VM.import(@ovf_file)
|
@runner.vm = VirtualBox::VM.import(@ovf_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Vagrant
|
||||||
module VM
|
module VM
|
||||||
class MoveHardDrive < Base
|
class MoveHardDrive < Base
|
||||||
def execute!
|
def execute!
|
||||||
unless @vm.powered_off?
|
unless @runner.powered_off?
|
||||||
error_and_exit(<<-error)
|
error_and_exit(<<-error)
|
||||||
The virtual machine must be powered off to move its disk.
|
The virtual machine must be powered off to move its disk.
|
||||||
error
|
error
|
||||||
|
@ -19,7 +19,7 @@ error
|
||||||
|
|
||||||
# TODO won't work if the first disk is not the boot disk or even if there are multiple disks
|
# TODO won't work if the first disk is not the boot disk or even if there are multiple disks
|
||||||
def find_hard_drive
|
def find_hard_drive
|
||||||
@vm.storage_controllers.each do |sc|
|
@runner.storage_controllers.each do |sc|
|
||||||
sc.devices.each do |d|
|
sc.devices.each do |d|
|
||||||
return d if d.image.is_a?(VirtualBox::HardDrive)
|
return d if d.image.is_a?(VirtualBox::HardDrive)
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ error
|
||||||
hard_drive.image = hard_drive.image.clone(new_image_path, Vagrant.config.vm.disk_image_format, true)
|
hard_drive.image = hard_drive.image.clone(new_image_path, Vagrant.config.vm.disk_image_format, true)
|
||||||
|
|
||||||
logger.info "Attaching new disk to VM ..."
|
logger.info "Attaching new disk to VM ..."
|
||||||
@vm.vm.save
|
@runner.vm.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_drive_after
|
def destroy_drive_after
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Vagrant
|
||||||
steps << Provision if Vagrant.config.chef.enabled
|
steps << Provision if Vagrant.config.chef.enabled
|
||||||
|
|
||||||
steps.each do |action_klass|
|
steps.each do |action_klass|
|
||||||
@vm.add_action(action_klass)
|
@runner.add_action(action_klass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Vagrant
|
||||||
module VM
|
module VM
|
||||||
class SharedFolders < Base
|
class SharedFolders < Base
|
||||||
def shared_folders
|
def shared_folders
|
||||||
shared_folders = @vm.invoke_callback(:collect_shared_folders)
|
shared_folders = @runner.invoke_callback(:collect_shared_folders)
|
||||||
|
|
||||||
# Basic filtering of shared folders. Basically only verifies that
|
# Basic filtering of shared folders. Basically only verifies that
|
||||||
# the result is an array of 3 elements. In the future this should
|
# the result is an array of 3 elements. In the future this should
|
||||||
|
@ -25,10 +25,10 @@ module Vagrant
|
||||||
folder = VirtualBox::SharedFolder.new
|
folder = VirtualBox::SharedFolder.new
|
||||||
folder.name = name
|
folder.name = name
|
||||||
folder.hostpath = hostpath
|
folder.hostpath = hostpath
|
||||||
@vm.vm.shared_folders << folder
|
@runner.vm.shared_folders << folder
|
||||||
end
|
end
|
||||||
|
|
||||||
@vm.vm.save(true)
|
@runner.vm.save(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_boot
|
def after_boot
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Vagrant
|
||||||
module VM
|
module VM
|
||||||
class Start < Base
|
class Start < Base
|
||||||
def execute!
|
def execute!
|
||||||
@vm.invoke_around_callback(:boot) do
|
@runner.invoke_around_callback(:boot) do
|
||||||
# Startup the VM
|
# Startup the VM
|
||||||
boot
|
boot
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ error
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
logger.info "Booting VM..."
|
logger.info "Booting VM..."
|
||||||
@vm.vm.start(:headless, true)
|
@runner.vm.start(:headless, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def wait_for_boot(sleeptime=5)
|
def wait_for_boot(sleeptime=5)
|
||||||
|
|
|
@ -4,7 +4,7 @@ module Vagrant
|
||||||
class Stop < Base
|
class Stop < Base
|
||||||
def execute!
|
def execute!
|
||||||
logger.info "Forcing shutdown of VM..."
|
logger.info "Forcing shutdown of VM..."
|
||||||
@vm.vm.stop(true)
|
@runner.vm.stop(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,14 +11,14 @@ module Vagrant
|
||||||
def prepare
|
def prepare
|
||||||
# Up is a "meta-action" so it really just queues up a bunch
|
# Up is a "meta-action" so it really just queues up a bunch
|
||||||
# of other actions in its place:
|
# of other actions in its place:
|
||||||
@vm.add_action(Import, @ovf_file)
|
@runner.add_action(Import, @ovf_file)
|
||||||
|
|
||||||
steps = [ForwardPorts, SharedFolders, Start]
|
steps = [ForwardPorts, SharedFolders, Start]
|
||||||
steps << Provision if Vagrant.config.chef.enabled
|
steps << Provision if Vagrant.config.chef.enabled
|
||||||
steps.insert(0, MoveHardDrive) if Vagrant.config.vm.hd_location
|
steps.insert(0, MoveHardDrive) if Vagrant.config.vm.hd_location
|
||||||
|
|
||||||
steps.each do |action_klass|
|
steps.each do |action_klass|
|
||||||
@vm.add_action(action_klass)
|
@runner.add_action(action_klass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,14 +33,14 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def persist
|
def persist
|
||||||
logger.info "Persisting the VM UUID (#{@vm.vm.uuid})..."
|
logger.info "Persisting the VM UUID (#{@runner.vm.uuid})..."
|
||||||
Env.persist_vm(@vm.vm)
|
Env.persist_vm(@runner.vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_mac_address
|
def setup_mac_address
|
||||||
logger.info "Matching MAC addresses..."
|
logger.info "Matching MAC addresses..."
|
||||||
@vm.vm.nics.first.macaddress = Vagrant.config[:vm][:base_mac]
|
@runner.vm.nics.first.macaddress = Vagrant.config[:vm][:base_mac]
|
||||||
@vm.vm.save(true)
|
@runner.vm.save(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,8 +11,8 @@ class BaseActionTest < Test::Unit::TestCase
|
||||||
@base = Vagrant::Actions::Base.new(@mock_vm)
|
@base = Vagrant::Actions::Base.new(@mock_vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow read-only access to the VM" do
|
should "allow read-only access to the runner" do
|
||||||
assert_equal @mock_vm, @base.vm
|
assert_equal @mock_vm, @base.runner
|
||||||
end
|
end
|
||||||
|
|
||||||
should "implement prepare which does nothing" do
|
should "implement prepare which does nothing" do
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
|
class DownloadBoxActionTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::Box::Download)
|
||||||
|
mock_config
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue