Class: Specinfra::Backend::Ssh

Inherits:
Exec
  • Object
show all
Defined in:
lib/specinfra/backend/ssh.rb

Instance Method Summary collapse

Methods inherited from Base

clear, #command, #get_config, #host_inventory, #initialize, instance, #os_info, #set_config, #set_example, #stderr_handler=, #stdout_handler=

Constructor Details

This class inherits a constructor from Specinfra::Backend::Base

Instance Method Details

#build_command(cmd) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/specinfra/backend/ssh.rb', line 40

def build_command(cmd)
  cmd = super(cmd)
  if sudo?
    cmd = "#{sudo} -p '#{prompt}' #{cmd}"
  end
  cmd
end

#run_command(cmd, opt = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/specinfra/backend/ssh.rb', line 9

def run_command(cmd, opt={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)

  if get_config(:ssh_without_env)
    ret = ssh_exec!(cmd)
  else
    ret = with_env do
      ssh_exec!(cmd)
    end
  end

  ret[:stdout].gsub!(/\r\n/, "\n")
  ret[:stdout].gsub!(/\A\n/, "") if sudo?

  if @example
    @example.[:command] = cmd
    @example.[:stdout]  = ret[:stdout]
  end

  CommandResult.new ret
end

#send_directory(from, to) ⇒ Object



36
37
38
# File 'lib/specinfra/backend/ssh.rb', line 36

def send_directory(from, to)
  scp_upload!(from, to, :recursive => true)
end

#send_file(from, to) ⇒ Object



32
33
34
# File 'lib/specinfra/backend/ssh.rb', line 32

def send_file(from, to)
  scp_upload!(from, to)
end