Class: NodeSpec::CommunicationAdapters::SshCommunicator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VerboseOutput

#verbose_puts

Constructor Details

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

Returns a new instance of SshCommunicator.



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

def initialize(host, options = {})
  @host = host
  @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

#sessionObject (readonly)

Returns the value of attribute session.



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

def session
  @session
end

Instance Method Details

#backendObject



36
37
38
# File 'lib/nodespec/communication_adapters/ssh_communicator.rb', line 36

def backend
  :ssh
end

#backend_proxyObject



32
33
34
# File 'lib/nodespec/communication_adapters/ssh_communicator.rb', line 32

def backend_proxy
  BackendProxy.create(:ssh, @session)
end

#init_session(configuration) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nodespec/communication_adapters/ssh_communicator.rb', line 20

def init_session(configuration)
  configuration.unbind_winrm_session

  @session = configuration.bind_ssh_session_for({host: @host, port: @ssh_options[:port]}) do
    msg = "\nConnecting to #{@host}"
    msg << ":#{@ssh_options[:port]}" if @ssh_options[:port]
    msg << " as #{@user}..."
    verbose_puts msg
    Net::SSH.start(@host, @user, @ssh_options)
  end
end