Class: Kitchen::Transport::Winrm::Connection
- Inherits:
-
Base::Connection
- Object
- Base::Connection
- Kitchen::Transport::Winrm::Connection
- Defined in:
- lib/kitchen/transport/winrm.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.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the session connection, if it is still active.
-
#execute(command) ⇒ Object
Execute a command on the remote host.
-
#login_command ⇒ LoginCommand
Builds a LoginCommand which can be used to open an interactive session on the remote host.
-
#upload(locals, remote) ⇒ Object
Uploads local files or directories to remote host.
-
#wait_until_ready ⇒ Object
Block and return only when the remote host is prepared and ready to execute command and upload files.
Methods inherited from Base::Connection
Methods included from Logging
#banner, #debug, #error, #fatal, #info, #warn
Constructor Details
This class inherits a constructor from Kitchen::Transport::Base::Connection
Instance Method Details
#close ⇒ Object
Closes the session connection, if it is still active.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kitchen/transport/winrm.rb', line 75 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 |
#execute(command) ⇒ Object
Execute a command on the remote host.
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/kitchen/transport/winrm.rb', line 87 def execute(command) return if command.nil? logger.debug("[WinRM] #{self} (#{command})") exit_code, stderr = execute_with_exit_code(command) if logger.debug? && exit_code == 0 log_stderr_on_warn(stderr) elsif exit_code != 0 log_stderr_on_warn(stderr) raise Transport::WinrmFailed, "WinRM exited (#{exit_code}) for command: [#{command}]" end end |
#login_command ⇒ LoginCommand
Builds a LoginCommand which can be used to open an interactive session on the remote host.
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/kitchen/transport/winrm.rb', line 102 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 raise ActionFailed, "Remote login not supported in #{self.class} " \ "from host OS '#{RbConfig::CONFIG["host_os"]}'." end end |
#upload(locals, remote) ⇒ Object
Uploads local files or directories to remote host.
117 118 119 |
# File 'lib/kitchen/transport/winrm.rb', line 117 def upload(locals, remote) file_transporter.upload(locals, remote) end |
#wait_until_ready ⇒ Object
Block and return only when the remote host is prepared and ready to execute command and upload files. The semantics and details will vary by implementation, but a round trip through the hosted service is preferred to simply waiting on a socket to become available.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/kitchen/transport/winrm.rb', line 122 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 |