Class: TrainPlugins::WinRM::Connection

Inherits:
Train::Plugins::Transport::BaseConnection
  • Object
show all
Defined in:
lib/train-winrm/connection.rb

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/train-winrm/connection.rb', line 46

def initialize(options)
  super(options)
  @hostname               = @options.delete(:hostname)
  @rdp_port               = @options.delete(:rdp_port)
  @connection_retries     = @options.delete(:connection_retries)
  @connection_retry_sleep = @options.delete(:connection_retry_sleep)
  @max_wait_until_ready   = @options.delete(:max_wait_until_ready)
  @operation_timeout      = @options.delete(:operation_timeout)
  @shell_type             = @options.delete(:winrm_shell_type)

  # SOCKS proxy patch for HTTPClient
  apply_socks_proxy_patch if @options[:socks_proxy]
end

Instance Attribute Details

#hostnameObject (readonly)

rubocop:disable Metrics/ClassLength



45
46
47
# File 'lib/train-winrm/connection.rb', line 45

def hostname
  @hostname
end

Instance Method Details

#closeObject



61
62
63
64
65
66
67
# File 'lib/train-winrm/connection.rb', line 61

def close
  return if @session.nil?

  session.close
ensure
  @session = nil
end

#download(remotes, local) ⇒ Object



90
91
92
93
94
# File 'lib/train-winrm/connection.rb', line 90

def download(remotes, local)
  Array(remotes).each do |remote|
    file_manager.download(remote, local)
  end
end

#login_commandObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/train-winrm/connection.rb', line 70

def 
  case RbConfig::CONFIG["host_os"]
  when /darwin/
    
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
    
  when /linux/
    
  else
    raise ActionFailed,
      "Remote login not supported in #{self.class} " \
      "from host OS '#{RbConfig::CONFIG["host_os"]}'."
  end
end

#upload(locals, remote) ⇒ Object



86
87
88
# File 'lib/train-winrm/connection.rb', line 86

def upload(locals, remote)
  file_manager.upload(locals, remote)
end

#uriObject



106
107
108
# File 'lib/train-winrm/connection.rb', line 106

def uri
  "winrm://#{options[:user]}@#{options[:endpoint]}:#{@rdp_port}"
end

#wait_until_readyObject



97
98
99
100
101
102
103
104
# File 'lib/train-winrm/connection.rb', line 97

def wait_until_ready
  delay = 3
  session(
    retry_limit: @max_wait_until_ready / delay,
    retry_delay: delay
  )
  run_command_via_connection(PING_COMMAND.dup)
end