Base boxes can now be packaged with `vagrant package` by specifying the `--base` parameter.
This commit is contained in:
parent
677b3b05cc
commit
f8dee9adf9
|
@ -21,9 +21,10 @@ Package the current vagrant environment into a box.
|
||||||
|
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
|
opt :base, "name of the VM to create a base package", :type => :string
|
||||||
opt :include, "files to include in the package", :type => :strings
|
opt :include, "files to include in the package", :type => :strings
|
||||||
|
|
||||||
run do |command|
|
run do |command|
|
||||||
Vagrant::Commands.execute(:package, command.argv[0], command.opts[:include])
|
Vagrant::Commands.execute(:package, command.argv[0], command.opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,11 +96,24 @@ module Vagrant
|
||||||
# Export and package the current vm
|
# Export and package the current vm
|
||||||
#
|
#
|
||||||
# This command requires that an instance be powered off
|
# This command requires that an instance be powered off
|
||||||
def package(out_path=nil, include_files=[])
|
def package(out_path=nil, opts={})
|
||||||
env.require_persisted_vm
|
opts[:include] ||= []
|
||||||
error_and_exit(:vm_power_off_to_package) unless env.vm.powered_off?
|
|
||||||
|
|
||||||
env.vm.package(out_path, include_files)
|
if !opts[:base]
|
||||||
|
# Packaging a pre-existing environment
|
||||||
|
env.require_persisted_vm
|
||||||
|
else
|
||||||
|
# Packaging a base box; that is a VM not tied to a specific
|
||||||
|
# vagrant environment
|
||||||
|
vm = VM.find(opts[:base])
|
||||||
|
vm.env = env if vm
|
||||||
|
env.vm = vm
|
||||||
|
|
||||||
|
error_and_exit(:vm_base_not_found, :name => opts[:base]) unless vm
|
||||||
|
end
|
||||||
|
|
||||||
|
error_and_exit(:vm_power_off_to_package) unless env.vm.powered_off?
|
||||||
|
env.vm.package(out_path, opts[:include])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Manages the `vagrant box` command, allowing the user to add
|
# Manages the `vagrant box` command, allowing the user to add
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Vagrant
|
||||||
attr_reader :root_path
|
attr_reader :root_path
|
||||||
attr_reader :config
|
attr_reader :config
|
||||||
attr_reader :box
|
attr_reader :box
|
||||||
attr_reader :vm
|
attr_accessor :vm
|
||||||
attr_reader :ssh
|
attr_reader :ssh
|
||||||
attr_reader :active_list
|
attr_reader :active_list
|
||||||
attr_reader :commands
|
attr_reader :commands
|
||||||
|
|
|
@ -111,6 +111,8 @@
|
||||||
only supports VirtualBox 3.1.x. Please install the proper version to continue.
|
only supports VirtualBox 3.1.x. Please install the proper version to continue.
|
||||||
:vm_failed_to_boot: |-
|
:vm_failed_to_boot: |-
|
||||||
Failed to connect to VM! Failed to boot?
|
Failed to connect to VM! Failed to boot?
|
||||||
|
:vm_base_not_found: |-
|
||||||
|
The specified base VM "<%= name %>" was not found.
|
||||||
:vm_not_running: |-
|
:vm_not_running: |-
|
||||||
VM is not running! Nothing to shut down!
|
VM is not running! Nothing to shut down!
|
||||||
:vm_not_running_for_suspend: |-
|
:vm_not_running_for_suspend: |-
|
||||||
|
|
|
@ -148,34 +148,67 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
@persisted_vm.stubs(:powered_off?).returns(true)
|
@persisted_vm.stubs(:powered_off?).returns(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "require a persisted vm" do
|
context "with no base specified" do
|
||||||
@env.expects(:require_persisted_vm).once
|
should "require a persisted vm" do
|
||||||
@commands.package
|
@env.expects(:require_persisted_vm).once
|
||||||
|
@commands.package
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "error and exit if the VM is not powered off" do
|
context "with base specified" do
|
||||||
@persisted_vm.stubs(:powered_off?).returns(false)
|
setup do
|
||||||
@commands.expects(:error_and_exit).with(:vm_power_off_to_package).once
|
@vm = mock("vm")
|
||||||
@persisted_vm.expects(:package).never
|
|
||||||
@commands.package
|
Vagrant::VM.stubs(:find).with(@name).returns(@vm)
|
||||||
|
@vm.stubs(:env=).with(@env)
|
||||||
|
@env.stubs(:vm=)
|
||||||
|
|
||||||
|
@name = :bar
|
||||||
|
end
|
||||||
|
|
||||||
|
should "find the given base and set it on the env" do
|
||||||
|
Vagrant::VM.expects(:find).with(@name).returns(@vm)
|
||||||
|
@vm.expects(:env=).with(@env)
|
||||||
|
@env.expects(:vm=).with(@vm)
|
||||||
|
|
||||||
|
@commands.package("foo", { :base => @name })
|
||||||
|
end
|
||||||
|
|
||||||
|
should "error if the VM is not found" do
|
||||||
|
Vagrant::VM.expects(:find).with(@name).returns(nil)
|
||||||
|
@commands.expects(:error_and_exit).with(:vm_base_not_found, :name => @name).once
|
||||||
|
|
||||||
|
@commands.package("foo", { :base => @name })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call package on the persisted VM" do
|
context "shared (with and without base specified)" do
|
||||||
@persisted_vm.expects(:package).once
|
should "error and exit if the VM is not powered off" do
|
||||||
@commands.package
|
@persisted_vm.stubs(:powered_off?).returns(false)
|
||||||
end
|
@commands.expects(:error_and_exit).with(:vm_power_off_to_package).once
|
||||||
|
@persisted_vm.expects(:package).never
|
||||||
|
@commands.package
|
||||||
|
end
|
||||||
|
|
||||||
should "pass the out path and include_files to the package method" do
|
should "call package on the persisted VM" do
|
||||||
out_path = mock("out_path")
|
@persisted_vm.expects(:package).once
|
||||||
include_files = mock("include_files")
|
@commands.package
|
||||||
@persisted_vm.expects(:package).with(out_path, include_files).once
|
end
|
||||||
@commands.package(out_path, include_files)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "default to an empty array when not include_files are specified" do
|
should "pass the out path and include_files to the package method" do
|
||||||
out_path = mock("out_path")
|
out_path = mock("out_path")
|
||||||
@persisted_vm.expects(:package).with(out_path, []).once
|
include_files = mock("include_files")
|
||||||
@commands.package(out_path)
|
@persisted_vm.expects(:package).with(out_path, include_files).once
|
||||||
|
@commands.package(out_path, {
|
||||||
|
:include => include_files
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
should "default to an empty array when not include_files are specified" do
|
||||||
|
out_path = mock("out_path")
|
||||||
|
@persisted_vm.expects(:package).with(out_path, []).once
|
||||||
|
@commands.package(out_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue