Class: Train::Transports::WinRM::Connection

Inherits:
BaseConnection
  • Object
show all
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.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



32
33
34
35
36
37
38
39
40
# File 'lib/train/transports/winrm_connection.rb', line 32

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)
end

Instance Attribute Details

#hostnameObject (readonly)

rubocop:disable Metrics/ClassLength



31
32
33
# File 'lib/train/transports/winrm_connection.rb', line 31

def hostname
  @hostname
end

Instance Method Details

#closeObject



43
44
45
46
47
48
# File 'lib/train/transports/winrm_connection.rb', line 43

def close
  return if @session.nil?
  session.close
ensure
  @session = nil
end

#download(remotes, local) ⇒ Object



71
72
73
74
75
# File 'lib/train/transports/winrm_connection.rb', line 71

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

#login_commandObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/train/transports/winrm_connection.rb', line 51

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

#upload(locals, remote) ⇒ Object



67
68
69
# File 'lib/train/transports/winrm_connection.rb', line 67

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

#uriObject



87
88
89
# File 'lib/train/transports/winrm_connection.rb', line 87

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

#wait_until_readyObject



78
79
80
81
82
83
84
85
# File 'lib/train/transports/winrm_connection.rb', line 78

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