зеркало из https://github.com/Azure/vagrant-azure.git
Synced Folders, Wait for SSH.
This commit is contained in:
Родитель
6c8d407014
Коммит
3cf6c99c04
|
@ -67,7 +67,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
b2.use Provision
|
b2.use Provision
|
||||||
# b2.use SyncFolders
|
b2.use SyncFolders
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -159,8 +159,7 @@ module VagrantPlugins
|
||||||
def self.action_prepare_boot
|
def self.action_prepare_boot
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use Provision
|
b.use Provision
|
||||||
# b.use SyncFolders
|
b.use SyncFolders
|
||||||
# b.use WarnNetworks
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -170,6 +169,7 @@ module VagrantPlugins
|
||||||
b.use HandleBoxUrl
|
b.use HandleBoxUrl
|
||||||
b.use ConfigValidate
|
b.use ConfigValidate
|
||||||
b.use ConnectAzure
|
b.use ConnectAzure
|
||||||
|
|
||||||
b.use Call, IsState, :NotCreated do |env1, b1|
|
b.use Call, IsState, :NotCreated do |env1, b1|
|
||||||
if !env1[:result]
|
if !env1[:result]
|
||||||
b1.use Call, IsState, :StoppedDeallocated do |env2, b2|
|
b1.use Call, IsState, :StoppedDeallocated do |env2, b2|
|
||||||
|
@ -182,6 +182,7 @@ module VagrantPlugins
|
||||||
b3.use Message, I18n.t(
|
b3.use Message, I18n.t(
|
||||||
'vagrant_azure.vm_started', :name => $`
|
'vagrant_azure.vm_started', :name => $`
|
||||||
)
|
)
|
||||||
|
b3.use WaitForCommunicate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -191,6 +192,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
b1.use action_prepare_boot
|
||||||
b1.use RunInstance # Launch a new instance
|
b1.use RunInstance # Launch a new instance
|
||||||
b1.use Call, WaitForState, :ReadyRole do |env2, b2|
|
b1.use Call, WaitForState, :ReadyRole do |env2, b2|
|
||||||
if env2[:result]
|
if env2[:result]
|
||||||
|
@ -198,6 +200,7 @@ module VagrantPlugins
|
||||||
b2.use Message, I18n.t(
|
b2.use Message, I18n.t(
|
||||||
'vagrant_azure.vm_started', :name => $`
|
'vagrant_azure.vm_started', :name => $`
|
||||||
)
|
)
|
||||||
|
b2.use WaitForCommunicate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -240,11 +243,12 @@ module VagrantPlugins
|
||||||
autoload :RunInstance, action_root.join('run_instance')
|
autoload :RunInstance, action_root.join('run_instance')
|
||||||
autoload :StartInstance, action_root.join('start_instance')
|
autoload :StartInstance, action_root.join('start_instance')
|
||||||
autoload :StopInstance, action_root.join('stop_instance')
|
autoload :StopInstance, action_root.join('stop_instance')
|
||||||
# autoload :SyncFolders, action_root.join('sync_folders')
|
autoload :SyncFolders, action_root.join('sync_folders')
|
||||||
autoload :TerminateInstance, action_root.join('terminate_instance')
|
autoload :TerminateInstance, action_root.join('terminate_instance')
|
||||||
# autoload :TimedProvision, action_root.join('timed_provision')
|
# autoload :TimedProvision, action_root.join('timed_provision')
|
||||||
# autoload :WarnNetworks, action_root.join('warn_networks')
|
# autoload :WarnNetworks, action_root.join('warn_networks')
|
||||||
autoload :WaitForState, action_root.join('wait_for_state')
|
autoload :WaitForState, action_root.join('wait_for_state')
|
||||||
|
autoload :WaitForCommunicate, action_root.join('wait_for_communicate')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,10 +17,10 @@ module VagrantPlugins
|
||||||
def call (env)
|
def call (env)
|
||||||
config = env[:machine].provider_config
|
config = env[:machine].provider_config
|
||||||
|
|
||||||
env[:ui].warn "Subscription ID: [#{config.subscription_id}]"
|
env[:ui].info "Subscription ID: [#{config.subscription_id}]"
|
||||||
env[:ui].warn "Mangement Certificate: [#{config.mgmt_certificate}]"
|
env[:ui].info "Mangement Certificate: [#{config.mgmt_certificate}]"
|
||||||
env[:ui].warn "Mangement Endpoint: [#{config.mgmt_endpoint}]"
|
env[:ui].info "Mangement Endpoint: [#{config.mgmt_endpoint}]"
|
||||||
env[:ui].warn "Storage Account Name: [#{config.storage_acct_name}]"
|
env[:ui].info "Storage Account Name: [#{config.storage_acct_name}]"
|
||||||
|
|
||||||
Azure.configure do |c|
|
Azure.configure do |c|
|
||||||
c.subscription_id = config.subscription_id
|
c.subscription_id = config.subscription_id
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
# Copyright (c) 2014 Mitchell Hashimoto
|
||||||
|
# Under The MIT License (MIT)
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
# Copyright (c) Microsoft Open Technologies, Inc.
|
||||||
|
# All Rights Reserved. Licensed under the Apache 2.0 License.
|
||||||
|
#--------------------------------------------------------------------------
|
||||||
|
require "log4r"
|
||||||
|
require "vagrant/util/subprocess"
|
||||||
|
require "vagrant/util/scoped_hash_override"
|
||||||
|
require "vagrant/util/which"
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module WinAzure
|
||||||
|
module Action
|
||||||
|
# This middleware uses `rsync` to sync the folders
|
||||||
|
class SyncFolders
|
||||||
|
include Vagrant::Util::ScopedHashOverride
|
||||||
|
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
@logger = Log4r::Logger.new("vagrant_azure::action::sync_folders")
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
puts 'entered sync folders, call app'
|
||||||
|
@app.call(env)
|
||||||
|
puts 'called app'
|
||||||
|
|
||||||
|
ssh_info = env[:machine].ssh_info
|
||||||
|
|
||||||
|
unless Vagrant::Util::Which.which('rsync')
|
||||||
|
env[:ui].warn(I18n.t('vagrant_azure.rsync_not_found_warning', :side => "host"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
puts 'running which on target'
|
||||||
|
if env[:machine].communicate.execute('which rsync', :error_check => false) != 0
|
||||||
|
env[:ui].warn(I18n.t('vagrant_azure.rsync_not_found_warning', :side => "guest"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
puts 'done running which on target'
|
||||||
|
|
||||||
|
env[:machine].config.vm.synced_folders.each do |id, data|
|
||||||
|
data = scoped_hash_override(data, :azure)
|
||||||
|
|
||||||
|
# Ignore disabled shared folders
|
||||||
|
next if data[:disabled]
|
||||||
|
|
||||||
|
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
||||||
|
guestpath = data[:guestpath]
|
||||||
|
|
||||||
|
# Make sure there is a trailing slash on the host path to
|
||||||
|
# avoid creating an additional directory with rsync
|
||||||
|
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
||||||
|
|
||||||
|
# on windows rsync.exe requires cygdrive-style paths
|
||||||
|
if Vagrant::Util::Platform.windows?
|
||||||
|
hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
|
||||||
|
end
|
||||||
|
|
||||||
|
env[:ui].info(I18n.t("vagrant_azure.rsync_folder",
|
||||||
|
:hostpath => hostpath,
|
||||||
|
:guestpath => guestpath))
|
||||||
|
|
||||||
|
# Create the host path if it doesn't exist and option flag is set
|
||||||
|
if data[:create]
|
||||||
|
begin
|
||||||
|
FileUtils::mkdir_p(hostpath)
|
||||||
|
rescue => err
|
||||||
|
raise Errors::MkdirError,
|
||||||
|
:hostpath => hostpath,
|
||||||
|
:err => err
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create the guest path
|
||||||
|
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
||||||
|
env[:machine].communicate.sudo(
|
||||||
|
"chown -R #{ssh_info[:username]} '#{guestpath}'")
|
||||||
|
|
||||||
|
#collect rsync excludes specified :rsync_excludes=>['path1',...] in synced_folder options
|
||||||
|
excludes = ['.vagrant/', 'Vagrantfile', *Array(data[:rsync_excludes])].uniq
|
||||||
|
|
||||||
|
# Rsync over to the guest path using the SSH info
|
||||||
|
command = [
|
||||||
|
"rsync", "--verbose", "--archive", "-z",
|
||||||
|
*excludes.map{|e|['--exclude', e]}.flatten,
|
||||||
|
"-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}",
|
||||||
|
hostpath,
|
||||||
|
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
||||||
|
|
||||||
|
# we need to fix permissions when using rsync.exe on windows, see
|
||||||
|
# http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
|
||||||
|
if Vagrant::Util::Platform.windows?
|
||||||
|
command.insert(1, "--chmod", "ugo=rwX")
|
||||||
|
end
|
||||||
|
|
||||||
|
puts 'executing rsync'
|
||||||
|
r = Vagrant::Util::Subprocess.execute(*command)
|
||||||
|
if r.exit_code != 0
|
||||||
|
raise Errors::RsyncError,
|
||||||
|
:guestpath => guestpath,
|
||||||
|
:hostpath => hostpath,
|
||||||
|
:stderr => r.stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def ssh_key_options(ssh_info)
|
||||||
|
# Ensure that `private_key_path` is an Array (for Vagrant < 1.4)
|
||||||
|
Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,38 @@
|
||||||
|
#--------------------------------------------------------------------------
|
||||||
|
# Copyright (c) Microsoft Open Technologies, Inc.
|
||||||
|
# All Rights Reserved. Licensed under the Apache 2.0 License.
|
||||||
|
#--------------------------------------------------------------------------
|
||||||
|
require 'log4r'
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module WinAzure
|
||||||
|
module Action
|
||||||
|
class WaitForCommunicate
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
@logger = Log4r::Logger.new("vagrant_azure::action::wait_for_communicate")
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
|
||||||
|
if !env[:interrupted]
|
||||||
|
# Wait for SSH to be ready.
|
||||||
|
env[:ui].info(I18n.t("vagrant_azure.waiting_for_ssh"))
|
||||||
|
while true
|
||||||
|
# If we're interrupted then just back out
|
||||||
|
break if env[:interrupted]
|
||||||
|
break if env[:machine].communicate.ready?
|
||||||
|
sleep 5
|
||||||
|
end
|
||||||
|
|
||||||
|
# Ready and booted!
|
||||||
|
env[:ui].info(I18n.t("vagrant_azure.ssh_ready"))
|
||||||
|
end
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -14,3 +14,12 @@ en:
|
||||||
VM '%{name}' has been started
|
VM '%{name}' has been started
|
||||||
vm_stopped: |-
|
vm_stopped: |-
|
||||||
VM '%{name}' has been stopped
|
VM '%{name}' has been stopped
|
||||||
|
rsync_folder: |-
|
||||||
|
Rsyncing folder: %{hostpath} => %{guestpath}
|
||||||
|
rsync_not_found_warning: |-
|
||||||
|
Warning! Folder sync disabled because the rsync binary is missing in the %{side}.
|
||||||
|
Make sure rsync is installed and the binary can be found in the PATH.
|
||||||
|
waiting_for_ssh: |-
|
||||||
|
Waiting for SSH
|
||||||
|
ssh_ready: |-
|
||||||
|
SSH Ready
|
||||||
|
|
Загрузка…
Ссылка в новой задаче