providers/virtualbox: ability to customize linked clone snapshot

This commit is contained in:
Mitchell Hashimoto 2015-10-08 11:58:47 -04:00
parent e45ba11e14
commit 44d484e2e0
3 changed files with 31 additions and 6 deletions

View File

@ -12,9 +12,18 @@ module VagrantPlugins
def call(env)
@logger.info("Creating linked clone from master '#{env[:master_id]}'")
env[:ui].info I18n.t("vagrant.actions.vm.clone.creating", name: env[:machine].box.name)
# Get the snapshot to base the linked clone on. This defaults
# to "base" which is automatically setup with linked clones.
snapshot = "base"
if env[:machine].provider_config.linked_clone_snapshot
snapshot = env[:machine].provider_config.linked_clone_snapshot
end
# Do the actual clone
env[:ui].info I18n.t(
"vagrant.actions.vm.clone.creating", name: env[:machine].box.name)
env[:machine].id = env[:machine].provider.driver.clonevm(
env[:master_id], env[:machine].box.name, "base") do |progress|
env[:master_id], env[:machine].box.name, snapshot) do |progress|
env[:ui].clear_line
env[:ui].report_progress(progress, 100, false)
end

View File

@ -59,10 +59,16 @@ module VagrantPlugins
"Imported box #{env[:machine].box.name} as master vm " +
"with id #{env[:master_id]}")
@logger.info("Creating base snapshot for master VM.")
env[:machine].provider.driver.create_snapshot(env[:master_id], "base") do |progress|
env[:ui].clear_line
env[:ui].report_progress(progress, 100, false)
if !env[:machine].provider_config.linked_clone_snapshot
snapshots = env[:machine].provider.driver.list_snapshots(env[:master_id])
if !snapshots.include?("base")
@logger.info("Creating base snapshot for master VM.")
env[:machine].provider.driver.create_snapshot(
env[:master_id], "base") do |progress|
env[:ui].clear_line
env[:ui].report_progress(progress, 100, false)
end
end
end
@logger.debug("Writing id of master VM '#{env[:master_id]}' to #{master_id_file}")

View File

@ -38,6 +38,14 @@ module VagrantPlugins
# @return [Boolean]
attr_accessor :linked_clone
# The snapshot to base the linked clone from. If this isn't set
# a snapshot will be made with the name of "base" which will be used.
#
# If this is set, then the snapshot must already exist.
#
# @return [String]
attr_accessor :linked_clone_snapshot
# This should be set to the name of the machine in the VirtualBox
# GUI.
#
@ -66,6 +74,7 @@ module VagrantPlugins
@network_adapters = {}
@gui = UNSET_VALUE
@linked_clone = UNSET_VALUE
@linked_clone_snapshot = UNSET_VALUE
# We require that network adapter 1 is a NAT device.
network_adapter(1, :nat)
@ -145,6 +154,7 @@ module VagrantPlugins
# Do not create linked clone by default
@linked_clone = false if @linked_clone == UNSET_VALUE
@linked_clone_snapshot = nil if @linked_clone_snapshot == UNSET_VALUE
# The default name is just nothing, and we default it
@name = nil if @name == UNSET_VALUE