Merge pull request #2112 from markpeek/markpeek-file

Add a file provisioner
This commit is contained in:
Mitchell Hashimoto 2013-09-03 14:09:10 -07:00
commit 51bdae3b90
4 changed files with 73 additions and 0 deletions

View File

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

View File

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

View File

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

View File

@ -1194,6 +1194,11 @@ en:
file needs to exist so it can be uploaded to the virtual machine. file needs to exist so it can be uploaded to the virtual machine.
deleting_from_server: "Deleting %{deletable} \"%{name}\" from Chef server..." 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: puppet:
not_detected: |- not_detected: |-
The `%{binary}` binary appears to not be in the PATH of the guest. This The `%{binary}` binary appears to not be in the PATH of the guest. This