Permalink
Browse files

catch timeout for winrm, fusion addshare

  • Loading branch information...
jedi4ever committed Nov 6, 2012
1 parent 3bdd8f1 commit 757c225a8dbeb137f6f4c671447eaa0c870feffc
View
@@ -67,6 +67,9 @@ def initialize(name,path,env)
# Default there is no ISO file mounted
@iso_file = nil, @iso_src = nil ; @iso_md5 = nil ; @iso_download_timeout=1000 ; @iso_download_instructions = nil
# Shares to add
@add_shares = []
# Default is no floppy mounted
@floppy_files = nil
@@ -23,15 +23,17 @@ module Winrm
require 'highline'
def winrm_up?(ip,options)
if not @winrm_up
@httpcli = HTTPClient.new(:agent_name => 'Ruby WinRM Client')
@httpcli.receive_timeout = 10
@httpcli.set_auth(nil, options[:user], options[:pass])
@httpcli.get("http://#{ip}:#{options[:port]}/wsman")
@winrm_up = true
begin
if not @winrm_up
@httpcli = HTTPClient.new(:agent_name => 'Ruby WinRM Client')
@httpcli.receive_timeout = 10
@httpcli.set_auth(nil, options[:user], options[:pass])
@httpcli.get("http://#{ip}:#{options[:port]}/wsman")
@winrm_up = true
end
rescue HTTPClient::ReceiveTimeoutError,HTTPClient::ConnectTimeoutError
@winrm_up = false
end
rescue HTTPClient::ReceiveTimeoutError
@winrm_up = false
end
@@ -48,7 +50,7 @@ def when_winrm_login_works(ip="127.0.0.1", options = {}, &block)
env.ui.info "Waiting for winrm login on #{ip} with user #{options[:user]} to windows on port => #{options[:port]} to work, timeout=#{options[:timeout]} sec"
until @connected do
begin
sleep 1
sleep 1
env.ui.info ".",{:new_line => false}
next if not winrm_up?(ip, options)
winrm_execute(ip,"hostname",options.merge({:progress => nil}))
@@ -59,10 +61,10 @@ def when_winrm_login_works(ip="127.0.0.1", options = {}, &block)
sleep 1
@connected = true
return true
rescue Exception => e
rescue Exception => e
puts e.inspect
puts e.message
puts e.backtrace.inspect
puts e.message
puts e.backtrace.inspect
sleep 5
end
end
@@ -100,7 +102,7 @@ def new_session(host,options)
endpoint = "http://#{host}:#{opts[:port]}/wsman"
client = ::WinRM::WinRMWebService.new(endpoint, :plaintext, opts)
if opts[:operation_timeout]
client.set_timeout(opts[:operation_timeout])
client.set_timeout(opts[:operation_timeout])
end
rescue ::WinRM::WinRMAuthorizationError => error
raise ::WinRM::WinRMAuthorizationError.new("#{error.message}@#{host}")
@@ -129,7 +131,7 @@ def winrm_execute(host,command, options)
command_id = @session.run_command(@remote_id, command)
output = @session.get_command_output(@remote_id, command_id) do |out,error|
if out
stdout += out
stdout += out
env.ui.info out,{:new_line => false} if options[:progress]
end
if error
@@ -3,15 +3,15 @@ module Provider
module Vmfusion
module BoxCommand
# This function 'adds a share' the box based on the definition
def add_share(share_name, share_path)
def add_share(share_name, share_path)
shell_exec("#{(vmrun_cmd).shellescape} -T fusion addSharedFolder #{vmx_file_path.shellescape} '#{share_name}' #{::File.expand_path(share_path).shellescape}")
end
def add_share_from_defn
definition.add_shares.each do |share_name, share_path|
add_share(share_name, share_path)
end
end
end
end
end
end
@@ -0,0 +1,21 @@
module Veewee
module Provider
module Vmfusion
module BoxCommand
def winrm_options
winrm_options={
:user => definition.winrm_user,
:pass => definition.winrm_password,
:port => definition.winrm_host_port,
:basic_auth_only => true,
:timeout => definition.winrm_login_timeout.to_i,
:operation_timeout => 600 # ten minutes
}
return winrm_options
end
end
end
end
end
@@ -0,0 +1,12 @@
module Veewee
module Provider
module Vmfusion
module BoxCommand
def winrm(command,options = {})
super(command,options)
end
end
end
end
end

0 comments on commit 757c225

Please sign in to comment.