From c158b4aff46578d9fe4eb6259b35f95ebdf2fda2 Mon Sep 17 00:00:00 2001 From: Mark Peek Date: Tue, 3 Sep 2013 11:01:12 -0700 Subject: [PATCH] Add a file provisioner Add a provisioner which will upload host files and directories to the guest via the scp channel. This is useful for populating user specific files into the guest. This is a rename from scpupload to file and updated against master. [GH-1357] --- plugins/provisioners/file/config.rb | 29 ++++++++++++++++++++++++ plugins/provisioners/file/plugin.rb | 23 +++++++++++++++++++ plugins/provisioners/file/provisioner.rb | 16 +++++++++++++ templates/locales/en.yml | 5 ++++ 4 files changed, 73 insertions(+) create mode 100644 plugins/provisioners/file/config.rb create mode 100644 plugins/provisioners/file/plugin.rb create mode 100644 plugins/provisioners/file/provisioner.rb diff --git a/plugins/provisioners/file/config.rb b/plugins/provisioners/file/config.rb new file mode 100644 index 000000000..f7eb6d3ec --- /dev/null +++ b/plugins/provisioners/file/config.rb @@ -0,0 +1,29 @@ +require "vagrant" + +module VagrantPlugins + module FileUpload + class Config < Vagrant.plugin("2", :config) + attr_accessor :source + attr_accessor :destination + + def validate(machine) + errors = [] + if !source + errors << I18n.t("vagrant.provisioners.file.no_source_file") + end + if !destination + errors << I18n.t("vagrant.provisioners.file.no_dest_file") + end + if source + s = File.expand_path(source) + if ! File.exist?(s) + errors << I18n.t("vagrant.provisioners.file.path_invalid", + :path => s) + end + end + + { "File provisioner" => errors } + end + end + end +end diff --git a/plugins/provisioners/file/plugin.rb b/plugins/provisioners/file/plugin.rb new file mode 100644 index 000000000..9d7e6f2a8 --- /dev/null +++ b/plugins/provisioners/file/plugin.rb @@ -0,0 +1,23 @@ +require "vagrant" + +module VagrantPlugins + module FileUpload + class Plugin < Vagrant.plugin("2") + name "file" + description <<-DESC + Provides support for provisioning your virtual machines with + uploaded files. + DESC + + config(:file, :provisioner) do + require File.expand_path("../config", __FILE__) + Config + end + + provisioner(:file) do + require File.expand_path("../provisioner", __FILE__) + Provisioner + end + end + end +end diff --git a/plugins/provisioners/file/provisioner.rb b/plugins/provisioners/file/provisioner.rb new file mode 100644 index 000000000..237e32043 --- /dev/null +++ b/plugins/provisioners/file/provisioner.rb @@ -0,0 +1,16 @@ +module VagrantPlugins + module FileUpload + class Provisioner < Vagrant.plugin("2", :provisioner) + def provision + @machine.communicate.tap do |comm| + # Make sure the remote path exists + command = "mkdir -p %s" % File.dirname(config.destination) + comm.execute(command) + + # now upload the file + comm.upload(File.expand_path(config.source), config.destination) + end + end + end + end +end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 484d4ebdd..f562240da 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1194,6 +1194,11 @@ en: file needs to exist so it can be uploaded to the virtual machine. deleting_from_server: "Deleting %{deletable} \"%{name}\" from Chef server..." + file: + no_dest_file: "File destination must be specified." + no_source_file: "File source must be specified." + path_invalid: "File upload source file %{path} must exist" + puppet: not_detected: |- The `%{binary}` binary appears to not be in the PATH of the guest. This