Class: Train::Transports::WinRM::Connection
- Inherits:
-
BaseConnection
- Object
- BaseConnection
- Train::Transports::WinRM::Connection
- Defined in:
- lib/train/transports/winrm_connection.rb
Overview
A Connection instance can be generated and re-generated, given new connection details such as connection port, hostname, credentials, etc. This object is responsible for carrying out the actions on the remote host such as executing commands, transferring files, etc.
Defined Under Namespace
Classes: OS
Instance Method Summary collapse
- #close ⇒ Object
- #file(path) ⇒ Object
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #login_command ⇒ Object
- #os ⇒ Object
- #run_command(command) ⇒ Object
- #upload(locals, remote) ⇒ Object
- #uri ⇒ Object
- #wait_until_ready ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
31 32 33 34 35 36 37 |
# File 'lib/train/transports/winrm_connection.rb', line 31 def initialize() super() @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) end |
Instance Method Details
#close ⇒ Object
40 41 42 43 44 45 |
# File 'lib/train/transports/winrm_connection.rb', line 40 def close return if @session.nil? session.close ensure @session = nil end |
#file(path) ⇒ Object
51 52 53 |
# File 'lib/train/transports/winrm_connection.rb', line 51 def file(path) @files[path] ||= WindowsFile.new(self, path) end |
#login_command ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/train/transports/winrm_connection.rb', line 68 def login_command case RbConfig::CONFIG['host_os'] when /darwin/ login_command_for_mac when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ login_command_for_windows when /linux/ login_command_for_linux else fail ActionFailed, "Remote login not supported in #{self.class} " \ "from host OS '#{RbConfig::CONFIG['host_os']}'." end end |
#os ⇒ Object
47 48 49 |
# File 'lib/train/transports/winrm_connection.rb', line 47 def os @os ||= OS.new(self) end |
#run_command(command) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/train/transports/winrm_connection.rb', line 55 def run_command(command) return if command.nil? logger.debug("[WinRM] #{self} (#{command})") out = '' response = session.run(command) do |stdout, _| out << stdout if stdout end CommandResult.new(out, response.stderr, response.exitcode) end |
#upload(locals, remote) ⇒ Object
84 85 86 |
# File 'lib/train/transports/winrm_connection.rb', line 84 def upload(locals, remote) file_transporter.upload(locals, remote) end |
#uri ⇒ Object
98 99 100 |
# File 'lib/train/transports/winrm_connection.rb', line 98 def uri "winrm://#{[:user]}@#{[:endpoint]}:#{@rdp_port}" end |
#wait_until_ready ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/train/transports/winrm_connection.rb', line 89 def wait_until_ready delay = 3 session( retry_limit: @max_wait_until_ready / delay, retry_delay: delay, ) execute(PING_COMMAND.dup) end |