Class: Specinfra::Backend::Ssh

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

Instance Method Summary collapse

Methods inherited from Base

#set_example

Instance Method Details

#build_command(cmd) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/specinfra/backend/ssh.rb', line 36

def build_command(cmd)
  cmd = super(cmd)
  user = Specinfra.configuration.ssh_options[:user]
  disable_sudo = Specinfra.configuration.disable_sudo
  if user != 'root' && !disable_sudo
    cmd = "#{sudo} -p '#{prompt}' #{cmd}"
  end
  cmd
end

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/specinfra/backend/ssh.rb', line 8

def run_command(cmd, opt={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  ret = with_env do
    ssh_exec!(cmd)
  end

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

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

  CommandResult.new ret
end

#send_file(from, to) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/specinfra/backend/ssh.rb', line 25

def send_file(from, to)
  if Specinfra.configuration.scp.nil?
    Specinfra.configuration.scp = create_scp
  end

  tmp = File.join('/tmp', File.basename(to))
  scp = Specinfra.configuration.scp
  scp.upload!(from, tmp)
  run_command(Specinfra.command.get(:move_file, tmp, to))
end