Class: Chake::Connection
- Inherits:
-
Struct
- Object
- Struct
- Chake::Connection
show all
- Defined in:
- lib/chake/connection.rb,
lib/chake/connection/ssh.rb,
lib/chake/connection/local.rb
Defined Under Namespace
Classes: CommandFailed, Local, Ssh
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node
2
3
4
|
# File 'lib/chake/connection.rb', line 2
def node
@node
end
|
Class Method Details
.connection_name ⇒ Object
63
64
65
|
# File 'lib/chake/connection.rb', line 63
def self.connection_name
name.split('::').last.downcase
end
|
.get(name) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/chake/connection.rb', line 73
def self.get(name)
connection = @connections.find { |b| b.connection_name == name }
raise ArgumentError, "Invalid connection name: #{name}" unless connection
connection
end
|
.inherited(subclass) ⇒ Object
67
68
69
70
71
|
# File 'lib/chake/connection.rb', line 67
def self.inherited(subclass)
super
@connections ||= []
@connections << subclass
end
|
Instance Method Details
#read_output(io) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/chake/connection.rb', line 30
def read_output(io)
io.each_line do |line|
node.log(line.gsub(/\s*$/, ''))
end
io.close
if $CHILD_STATUS
status = $CHILD_STATUS.exitstatus
if status != 0
raise CommandFailed, [node.hostname, 'FAILED with exit status %<status>d' % { status: status }].join(': ')
end
end
end
|
#rsync ⇒ Object
14
15
16
|
# File 'lib/chake/connection.rb', line 14
def rsync
['rsync']
end
|
#rsync_dest ⇒ Object
18
19
20
|
# File 'lib/chake/connection.rb', line 18
def rsync_dest
"#{node.path}/"
end
|
#run(cmd) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/chake/connection.rb', line 22
def run(cmd)
node.log('$ %<command>s' % { command: cmd })
io = IO.popen(command_runner + ['/bin/sh'], 'w+', err: %i[child out])
io.write(cmd)
io.close_write
read_output(io)
end
|
#run_as_root(cmd) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/chake/connection.rb', line 47
def run_as_root(cmd)
if node.remote_username == 'root'
run(cmd)
else
run("sudo #{cmd}")
end
end
|
#run_shell ⇒ Object
43
44
45
|
# File 'lib/chake/connection.rb', line 43
def run_shell
system(*shell_command)
end
|
#scp ⇒ Object
6
7
8
|
# File 'lib/chake/connection.rb', line 6
def scp
['scp']
end
|
#scp_dest ⇒ Object
10
11
12
|
# File 'lib/chake/connection.rb', line 10
def scp_dest
''
end
|
#skip? ⇒ Boolean
59
60
61
|
# File 'lib/chake/connection.rb', line 59
def skip?
false
end
|
#to_s ⇒ Object
55
56
57
|
# File 'lib/chake/connection.rb', line 55
def to_s
self.class.connection_name
end
|