Skip to content

Commit

Permalink
providers/virtualbox: make prepare clone a core thing
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Oct 8, 2015
1 parent be58cc0 commit 36cfc77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/vagrant/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Builtin
autoload :IsState, "vagrant/action/builtin/is_state"
autoload :Lock, "vagrant/action/builtin/lock"
autoload :Message, "vagrant/action/builtin/message"
autoload :PrepareClone, "vagrant/action/builtin/prepare_clone"
autoload :Provision, "vagrant/action/builtin/provision"
autoload :ProvisionerCleanup, "vagrant/action/builtin/provisioner_cleanup"
autoload :SetHostname, "vagrant/action/builtin/set_hostname"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
require "log4r"

module VagrantPlugins
module ProviderVirtualBox
module Action
module Vagrant
module Action
module Builtin
class PrepareClone
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::action::vm::prepare_clone")
end

def call(env)
# If we aren't cloning, then do nothing
if !env[:machine].config.vm.clone
return @app.call(env)
end

# We need to get the machine ID from this Vagrant environment
clone_env = env[:machine].env.environment(
env[:machine].config.vm.clone)
raise Vagrant::Errors::CloneNotFound if !clone_env.root_path
raise Errors::CloneNotFound if !clone_env.root_path

# Get the machine itself
clone_machine = clone_env.machine(
clone_env.primary_machine_name, env[:machine].provider_name)
raise Vagrant::Errors::CloneMachineNotFound if !clone_machine.id
raise Errors::CloneMachineNotFound if !clone_machine.id

# Set the ID of the master so we know what to clone from
env[:clone_id] = clone_machine.id
Expand Down
7 changes: 2 additions & 5 deletions plugins/providers/virtualbox/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module Action
autoload :NetworkFixIPv6, File.expand_path("../action/network_fix_ipv6", __FILE__)
autoload :Package, File.expand_path("../action/package", __FILE__)
autoload :PackageVagrantfile, File.expand_path("../action/package_vagrantfile", __FILE__)
autoload :PrepareClone, File.expand_path("../action/prepare_clone", __FILE__)
autoload :PrepareCloneSnapshot, File.expand_path("../action/prepare_clone_snapshot", __FILE__)
autoload :PrepareNFSSettings, File.expand_path("../action/prepare_nfs_settings", __FILE__)
autoload :PrepareNFSValidIds, File.expand_path("../action/prepare_nfs_valid_ids", __FILE__)
Expand Down Expand Up @@ -385,14 +384,12 @@ def self.action_up
b2.use CheckAccessible
b2.use Customize, "pre-import"

if env[:machine].config.vm.clone
# We are cloning from another Vagrant environment
b2.use PrepareClone
elsif env[:machine].provider_config.linked_clone
if env[:machine].provider_config.linked_clone
# We are cloning from the box
b2.use ImportMaster
end

b2.use PrepareClone
b2.use PrepareCloneSnapshot
b2.use Import
b2.use DiscardState
Expand Down

0 comments on commit 36cfc77

Please sign in to comment.