providers/virtualbox: copy SSH key

This commit is contained in:
Mitchell Hashimoto 2015-10-08 12:58:06 -04:00
parent e9922d1754
commit 4908cd9cd9
3 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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)