From 4908cd9cd956f1179b956787d3f4b7b043a7fe30 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 Oct 2015 12:58:06 -0400 Subject: [PATCH] providers/virtualbox: copy SSH key --- plugins/providers/virtualbox/action.rb | 6 +++--- .../action/{create_clone.rb => clone.rb} | 14 +++++++++++++- .../providers/virtualbox/action/prepare_clone.rb | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) rename plugins/providers/virtualbox/action/{create_clone.rb => clone.rb} (78%) diff --git a/plugins/providers/virtualbox/action.rb b/plugins/providers/virtualbox/action.rb index e102625dc..f7984dca4 100644 --- a/plugins/providers/virtualbox/action.rb +++ b/plugins/providers/virtualbox/action.rb @@ -12,7 +12,7 @@ module VagrantPlugins autoload :CleanMachineFolder, File.expand_path("../action/clean_machine_folder", __FILE__) autoload :ClearForwardedPorts, File.expand_path("../action/clear_forwarded_ports", __FILE__) autoload :ClearNetworkInterfaces, File.expand_path("../action/clear_network_interfaces", __FILE__) - autoload :CreateClone, File.expand_path("../action/create_clone", __FILE__) + autoload :Clone, File.expand_path("../action/clone", __FILE__) autoload :Created, File.expand_path("../action/created", __FILE__) autoload :Customize, File.expand_path("../action/customize", __FILE__) autoload :Destroy, File.expand_path("../action/destroy", __FILE__) @@ -390,13 +390,13 @@ module VagrantPlugins # We are cloning from another Vagrant environment b2.use PrepareClone b2.use PrepareCloneSnapshot - b2.use CreateClone + b2.use Clone b2.use DiscardState elsif env[:machine].provider_config.linked_clone # We are cloning from the box b2.use ImportMaster b2.use PrepareCloneSnapshot - b2.use CreateClone + b2.use Clone b2.use DiscardState else # We are just doing a normal import from a box diff --git a/plugins/providers/virtualbox/action/create_clone.rb b/plugins/providers/virtualbox/action/clone.rb similarity index 78% rename from plugins/providers/virtualbox/action/create_clone.rb rename to plugins/providers/virtualbox/action/clone.rb index 526b5a5c1..6b389d4f1 100644 --- a/plugins/providers/virtualbox/action/create_clone.rb +++ b/plugins/providers/virtualbox/action/clone.rb @@ -1,9 +1,11 @@ require "log4r" +require "fileutils" + module VagrantPlugins module ProviderVirtualBox module Action - class CreateClone + class Clone def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::action::vm::clone") @@ -25,6 +27,16 @@ module VagrantPlugins # Flag as erroneous and return if clone failed raise Vagrant::Errors::VMCloneFailure if !env[:machine].id + # Copy the SSH key from the clone machine if we can + if env[:clone_machine] + key_path = env[:clone_machine].data_dir.join("private_key") + if key_path.file? + FileUtils.cp( + key_path, + env[:machine].data_dir.join("private_key")) + end + end + # Continue @app.call(env) end diff --git a/plugins/providers/virtualbox/action/prepare_clone.rb b/plugins/providers/virtualbox/action/prepare_clone.rb index 6b3bf34dd..c306b9b54 100644 --- a/plugins/providers/virtualbox/action/prepare_clone.rb +++ b/plugins/providers/virtualbox/action/prepare_clone.rb @@ -22,6 +22,7 @@ module VagrantPlugins # Set the ID of the master so we know what to clone from env[:clone_id] = clone_machine.id + env[:clone_machine] = clone_machine # Continue @app.call(env)