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
rubocop:disable Metrics/ClassLength.
- #login_command ⇒ Object
- #os ⇒ Object
- #run_command(command) ⇒ Object
- #upload(locals, remote) ⇒ Object
- #wait_until_ready ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
rubocop:disable Metrics/ClassLength
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/train/transports/winrm_connection.rb', line 31 def initialize() super() @endpoint = .delete(:endpoint) @rdp_port = .delete(:rdp_port) @winrm_transport = .delete(:winrm_transport) @connection_retries = .delete(:connection_retries) @connection_retry_sleep = .delete(:connection_retry_sleep) @max_wait_until_ready = .delete(:max_wait_until_ready) @files = {} end |
Instance Method Details
#close ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/train/transports/winrm_connection.rb', line 43 def close return if @session.nil? shell_id = session.shell logger.debug("[WinRM] closing remote shell #{shell_id} on #{self}") session.close logger.debug("[WinRM] remote shell #{shell_id} closed") ensure @session = nil end |
#file(path) ⇒ Object
57 58 59 |
# File 'lib/train/transports/winrm_connection.rb', line 57 def file(path) @files[path] ||= WindowsFile.new(self, path) end |
#login_command ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/train/transports/winrm_connection.rb', line 74 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
53 54 55 |
# File 'lib/train/transports/winrm_connection.rb', line 53 def os @os ||= OS.new(self) end |
#run_command(command) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/train/transports/winrm_connection.rb', line 61 def run_command(command) return if command.nil? logger.debug("[WinRM] #{self} (#{command})") out = '' response = session.run_powershell_script(command) do |stdout, _| out << stdout if stdout end CommandResult.new(out, response.stderr, response[:exitcode]) end |
#upload(locals, remote) ⇒ Object
90 91 92 |
# File 'lib/train/transports/winrm_connection.rb', line 90 def upload(locals, remote) file_transporter.upload(locals, remote) end |
#wait_until_ready ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/train/transports/winrm_connection.rb', line 95 def wait_until_ready delay = 3 session( retries: @max_wait_until_ready / delay, delay: delay, message: "Waiting for WinRM service on #{endpoint}, "\ "retrying in #{delay} seconds", ) execute(PING_COMMAND.dup) end |