Class: NodeSpec::CommunicationAdapters::SshCommunicator

Inherits:
Object
  • Object
show all
Includes:
RemoteBackend, VerboseOutput
Defined in:
lib/nodespec/communication_adapters/ssh_communicator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RemoteBackend

#backend, #backend_proxy

Methods included from VerboseOutput

#verbose_puts

Constructor Details

#initialize(host, os = nil, options = {}) ⇒ SshCommunicator

Returns a new instance of SshCommunicator.



12
13
14
15
16
17
18
19
20
# File 'lib/nodespec/communication_adapters/ssh_communicator.rb', line 12

def initialize(host, os = nil, options = {})
  @host = host
  @os = os
  @ssh_options = Net::SSH.configuration_for(@host)
  @user = options['user'] || @ssh_options[:user]
  %w[port password keys].each do |param|
    @ssh_options[param.to_sym] = options[param] if options[param]
  end
end

Instance Attribute Details

#osObject (readonly)

Returns the value of attribute os.



10
11
12
# File 'lib/nodespec/communication_adapters/ssh_communicator.rb', line 10

def os
  @os
end

#sessionObject (readonly)

Returns the value of attribute session.



10
11
12
# File 'lib/nodespec/communication_adapters/ssh_communicator.rb', line 10

def session
  @session
end

Instance Method Details

#bind_to(configuration) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nodespec/communication_adapters/ssh_communicator.rb', line 22

def bind_to(configuration)
  configuration.winrm = nil if configuration.winrm
  current_session = configuration.ssh

  close_ssh_session(current_session) if current_session && (current_session.host != @host || current_session.options[:port] != @ssh_options[:port])

  if current_session.nil? || current_session.closed?
    current_session = start_new_ssh_session
    configuration.host = @host
    configuration.ssh = current_session
  end
  @session = current_session
end