From 36cfc77167f0beb460e592908d6837e5f2b3d877 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 Oct 2015 16:02:37 -0400 Subject: [PATCH] providers/virtualbox: make prepare clone a core thing --- lib/vagrant/action.rb | 1 + .../vagrant/action/builtin}/prepare_clone.rb | 15 ++++++++++----- plugins/providers/virtualbox/action.rb | 7 ++----- 3 files changed, 13 insertions(+), 10 deletions(-) rename {plugins/providers/virtualbox/action => lib/vagrant/action/builtin}/prepare_clone.rb (70%) diff --git a/lib/vagrant/action.rb b/lib/vagrant/action.rb index db4875dbb..91b7959c1 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -24,6 +24,7 @@ module Vagrant 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" diff --git a/plugins/providers/virtualbox/action/prepare_clone.rb b/lib/vagrant/action/builtin/prepare_clone.rb similarity index 70% rename from plugins/providers/virtualbox/action/prepare_clone.rb rename to lib/vagrant/action/builtin/prepare_clone.rb index c306b9b54..696d28bfb 100644 --- a/plugins/providers/virtualbox/action/prepare_clone.rb +++ b/lib/vagrant/action/builtin/prepare_clone.rb @@ -1,8 +1,8 @@ require "log4r" -module VagrantPlugins - module ProviderVirtualBox - module Action +module Vagrant + module Action + module Builtin class PrepareClone def initialize(app, env) @app = app @@ -10,15 +10,20 @@ module VagrantPlugins 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 diff --git a/plugins/providers/virtualbox/action.rb b/plugins/providers/virtualbox/action.rb index d0ef01bff..85f52f887 100644 --- a/plugins/providers/virtualbox/action.rb +++ b/plugins/providers/virtualbox/action.rb @@ -34,7 +34,6 @@ module VagrantPlugins 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__) @@ -385,14 +384,12 @@ module VagrantPlugins 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