VM customization through Vagrantfile (modifying RAM, name, etc.)
This commit is contained in:
parent
83ddfa6695
commit
dcbfe709f3
|
@ -0,0 +1,15 @@
|
|||
module Vagrant
|
||||
module Actions
|
||||
module VM
|
||||
class Customize < Base
|
||||
def execute!
|
||||
# Run the customization procs over the VM
|
||||
Vagrant.config.vm.run_procs!(@runner.vm)
|
||||
|
||||
# Save the vm
|
||||
@runner.vm.save(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ module Vagrant
|
|||
module VM
|
||||
class Reload < Base
|
||||
def prepare
|
||||
steps = [ForwardPorts, SharedFolders, Boot]
|
||||
steps = [Customize, ForwardPorts, SharedFolders, Boot]
|
||||
steps.unshift(Halt) if @runner.vm.running?
|
||||
steps << Provision if !Vagrant.config.vm.provisioner.nil?
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ msg
|
|||
|
||||
# Up is a "meta-action" so it really just queues up a bunch
|
||||
# of other actions in its place:
|
||||
steps = [Import, ForwardPorts, SharedFolders, Boot]
|
||||
steps = [Import, Customize, ForwardPorts, SharedFolders, Boot]
|
||||
steps << Provision if !Vagrant.config.vm.provisioner.nil?
|
||||
steps.insert(0, MoveHardDrive) if Vagrant.config.vm.hd_location
|
||||
|
||||
|
|
|
@ -66,6 +66,8 @@ module Vagrant
|
|||
end
|
||||
|
||||
class VMConfig < Base
|
||||
include StackedProcRunner
|
||||
|
||||
attr_accessor :box
|
||||
attr_accessor :box_ovf
|
||||
attr_accessor :base_mac
|
||||
|
@ -111,6 +113,10 @@ module Vagrant
|
|||
def shared_folder_gid
|
||||
@shared_folder_gid || Vagrant.config.ssh.username
|
||||
end
|
||||
|
||||
def customize(&block)
|
||||
push_proc(&block)
|
||||
end
|
||||
end
|
||||
|
||||
class PackageConfig < Base
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||
|
||||
class CustomizeActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Customize)
|
||||
mock_config
|
||||
end
|
||||
|
||||
context "executing" do
|
||||
should "run the VM customization procs then save the VM" do
|
||||
Vagrant.config.vm.expects(:run_procs!).with(@vm)
|
||||
@vm.expects(:save).with(true).once
|
||||
@action.execute!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,7 +8,7 @@ class ReloadActionTest < Test::Unit::TestCase
|
|||
|
||||
context "sub-actions" do
|
||||
setup do
|
||||
@default_order = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
||||
@default_order = [Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
||||
@vm.stubs(:running?).returns(false)
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ class UpActionTest < Test::Unit::TestCase
|
|||
setup do
|
||||
File.stubs(:file?).returns(true)
|
||||
File.stubs(:exist?).returns(true)
|
||||
@default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
||||
@default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
|
||||
end
|
||||
|
||||
def setup_action_expectations
|
||||
|
|
|
@ -204,24 +204,36 @@ class ConfigTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
should "return the shared folder UID if set" do
|
||||
@config.shared_folder_uid = "foo"
|
||||
assert_equal "foo", @config.shared_folder_uid
|
||||
should "include the stacked proc runner module" do
|
||||
assert @config.class.included_modules.include?(Vagrant::StackedProcRunner)
|
||||
end
|
||||
|
||||
should "return the SSH username if UID not set" do
|
||||
@config.shared_folder_uid = nil
|
||||
assert_equal @username, @config.shared_folder_uid
|
||||
should "add the customize proc to the proc stack" do
|
||||
proc = Proc.new {}
|
||||
@config.customize(&proc)
|
||||
assert_equal [proc], @config.proc_stack
|
||||
end
|
||||
|
||||
should "return the shared folder GID if set" do
|
||||
@config.shared_folder_gid = "foo"
|
||||
assert_equal "foo", @config.shared_folder_gid
|
||||
end
|
||||
context "uid/gid" do
|
||||
should "return the shared folder UID if set" do
|
||||
@config.shared_folder_uid = "foo"
|
||||
assert_equal "foo", @config.shared_folder_uid
|
||||
end
|
||||
|
||||
should "return the SSH username if GID not set" do
|
||||
@config.shared_folder_gid = nil
|
||||
assert_equal @username, @config.shared_folder_gid
|
||||
should "return the SSH username if UID not set" do
|
||||
@config.shared_folder_uid = nil
|
||||
assert_equal @username, @config.shared_folder_uid
|
||||
end
|
||||
|
||||
should "return the shared folder GID if set" do
|
||||
@config.shared_folder_gid = "foo"
|
||||
assert_equal "foo", @config.shared_folder_gid
|
||||
end
|
||||
|
||||
should "return the SSH username if GID not set" do
|
||||
@config.shared_folder_gid = nil
|
||||
assert_equal @username, @config.shared_folder_gid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue