Class: Chake::Connection
- Inherits:
-
Struct
- Object
- Struct
- Chake::Connection
show all
- Defined in:
- lib/chake/connection.rb,
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
64
65
66
|
# File 'lib/chake/connection.rb', line 64
def self.connection_name
name.split('::').last.downcase
end
|
.get(name) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/chake/connection.rb', line 74
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
68
69
70
71
72
|
# File 'lib/chake/connection.rb', line 68
def self.inherited(subclass)
super
@connections ||= []
@connections << subclass
end
|
Instance Method Details
#read_output(io) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/chake/connection.rb', line 31
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
15
16
17
|
# File 'lib/chake/connection.rb', line 15
def rsync
['rsync']
end
|
#rsync_dest ⇒ Object
19
20
21
|
# File 'lib/chake/connection.rb', line 19
def rsync_dest
"#{node.path}/"
end
|
#run(cmd) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/chake/connection.rb', line 23
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
48
49
50
51
52
53
54
|
# File 'lib/chake/connection.rb', line 48
def run_as_root(cmd)
if node.remote_username == 'root'
run(cmd)
else
run("sudo #{cmd}")
end
end
|
#run_shell ⇒ Object
44
45
46
|
# File 'lib/chake/connection.rb', line 44
def run_shell
system(*shell_command)
end
|
#scp ⇒ Object
7
8
9
|
# File 'lib/chake/connection.rb', line 7
def scp
['scp']
end
|
#scp_dest ⇒ Object
11
12
13
|
# File 'lib/chake/connection.rb', line 11
def scp_dest
''
end
|
#skip? ⇒ Boolean
60
61
62
|
# File 'lib/chake/connection.rb', line 60
def skip?
false
end
|
#to_s ⇒ Object
56
57
58
|
# File 'lib/chake/connection.rb', line 56
def to_s
self.class.connection_name
end
|