зеркало из https://github.com/Azure/vagrant-azure.git
Adding shell provisioning. Supports both inline and script based shell provisioning.
This commit is contained in:
Родитель
909dc7b7ab
Коммит
8da5fa6be6
|
@ -13,6 +13,7 @@ module VagrantPlugins
|
|||
autoload :Driver, lib_path.join('driver')
|
||||
|
||||
require lib_path.join('provisioner/puppet')
|
||||
require lib_path.join('provisioner/shell')
|
||||
|
||||
# This returns the path to the source of this plugin.
|
||||
#
|
||||
|
|
|
@ -24,6 +24,10 @@ module VagrantPlugins
|
|||
|
||||
# TODO: Add Shell, Chef-solo and other provisioners
|
||||
case env[:provisioner].class.to_s
|
||||
when "VagrantPlugins::Shell::Provisioner"
|
||||
VagrantPlugins::WinAzure::Provisioner::Shell.new(
|
||||
env
|
||||
).provision_for_windows
|
||||
when "VagrantPlugins::Puppet::Provisioner::Puppet"
|
||||
VagrantPlugins::WinAzure::Provisioner::Puppet.new(
|
||||
env
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#---------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Open Technologies, Inc.
|
||||
# All Rights Reserved. Licensed under the Apache 2.0 License.
|
||||
#---------------------------------------------------------------------------
|
||||
module VagrantPlugins
|
||||
module WinAzure
|
||||
module Provisioner
|
||||
class Shell
|
||||
attr_reader :provisioner
|
||||
|
||||
def initialize(env)
|
||||
@env = env
|
||||
@provisioner = env[:provisioner]
|
||||
end
|
||||
|
||||
def provision_for_windows
|
||||
arguments = ''
|
||||
arguments = "#{config.args}" if config.args
|
||||
|
||||
with_windows_script_file do |path|
|
||||
guest_path = if File.extname(config.upload_path) == ''
|
||||
"#{config.upload_path}#{File.extname(path.to_s)}"
|
||||
else
|
||||
config.upload_path
|
||||
end
|
||||
|
||||
@env[:ui].detail "Uploading [#{path}] to [#{guest_path}]"
|
||||
|
||||
response = @env[:machine].provider.driver.upload(path, guest_path)
|
||||
|
||||
command = "powershell.exe #{guest_path} #{arguments}"
|
||||
@env[:machine].provider.driver.run_remote_ps(
|
||||
command
|
||||
) do |type, data|
|
||||
if type == :stdout || type == :stderr
|
||||
@env[:ui].detail data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def config
|
||||
provisioner.config
|
||||
end
|
||||
|
||||
def with_windows_script_file
|
||||
if config.remote?
|
||||
download_path = @env[:machine].env.tmp_path.join(
|
||||
"#{env[:mahine].id}-remote-script#{File.extname(config.path)}"
|
||||
)
|
||||
|
||||
download_path.delete if download_path.file?
|
||||
|
||||
begin
|
||||
Vagrant::Util::Downloader.new(
|
||||
config.path, download_path
|
||||
).download!
|
||||
yield download_path
|
||||
ensure
|
||||
download_path.delete
|
||||
end
|
||||
elsif config.path
|
||||
yield config.path
|
||||
else
|
||||
# We have an inline script. Create a temp file and handle it.
|
||||
file = Tempfile.new(['vagrant-powershell', '.ps1'])
|
||||
|
||||
begin
|
||||
file.write(config.inline)
|
||||
file.fsync
|
||||
file.close
|
||||
yield file.path
|
||||
ensure
|
||||
file.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Загрузка…
Ссылка в новой задаче