Class: Caterer::Communication::SSH
Instance Method Summary
collapse
#retryable
#remove_ansi_escape_codes
Constructor Details
#initialize(server) ⇒ SSH
Returns a new instance of SSH.
12
13
14
15
16
|
# File 'lib/caterer/communication/ssh.rb', line 12
def initialize(server)
@server = server
@connection = nil
@logger = Log4r::Logger.new("caterer::communication::ssh")
end
|
Instance Method Details
#execute(command, opts = {}, &block) ⇒ Object
35
36
37
38
39
|
# File 'lib/caterer/communication/ssh.rb', line 35
def execute(command, opts={}, &block)
connect do |connection|
shell_execute(connection, command, opts, &block)
end
end
|
#ready? ⇒ Boolean
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/caterer/communication/ssh.rb', line 18
def ready?
@logger.debug("Checking whether SSH is ready...")
Timeout.timeout(30) do
connect
end
@logger.info("SSH is ready!")
true
rescue => e
@logger.info("SSH not up: #{e.inspect}")
return false
end
|
#sudo(command, opts = {}, &block) ⇒ Object
41
42
43
44
|
# File 'lib/caterer/communication/ssh.rb', line 41
def sudo(command, opts={}, &block)
sudo = (@server.username == 'root') ? false : true
execute(command, opts.merge({:sudo => sudo}), &block)
end
|
#upload(from, to) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/caterer/communication/ssh.rb', line 46
def upload(from, to)
@logger.debug("Uploading: #{from} to #{to}")
connect do |connection|
opts = {}
opts[:recursive] = true if from.is_a?(String) and File.directory?(from)
scp = Net::SCP.new(connection)
scp.upload!(from, to, opts)
end
rescue Net::SCP::Error => e
raise "scp unavailable" if e.message =~ /\(127\)/
raise
end
|