Class: Chake::Backend
- Inherits:
-
Struct
- Object
- Struct
- Chake::Backend
show all
- Defined in:
- lib/chake/backend.rb,
lib/chake/backend/ssh.rb,
lib/chake/backend/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
3
4
5
|
# File 'lib/chake/backend.rb', line 3
def node
@node
end
|
Class Method Details
.backend_name ⇒ Object
59
60
61
|
# File 'lib/chake/backend.rb', line 59
def self.backend_name
name.split("::").last.downcase
end
|
.get(name) ⇒ Object
68
69
70
71
|
# File 'lib/chake/backend.rb', line 68
def self.get(name)
backend = @backends.find { |b| b.backend_name == name }
backend || raise(ArgumentError.new("Invalid backend name: #{name}"))
end
|
.inherited(subclass) ⇒ Object
63
64
65
66
|
# File 'lib/chake/backend.rb', line 63
def self.inherited(subclass)
@backends ||= []
@backends << subclass
end
|
Instance Method Details
#rsync ⇒ Object
16
17
18
|
# File 'lib/chake/backend.rb', line 16
def rsync
['rsync']
end
|
#rsync_dest ⇒ Object
20
21
22
|
# File 'lib/chake/backend.rb', line 20
def rsync_dest
node.path + '/'
end
|
#run(cmd) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/chake/backend.rb', line 24
def run(cmd)
printf "%#{Node.max_node_name_length}s: $ %s\n", node.hostname, cmd
output = IO.popen(command_runner + [cmd])
output.each_line do |line|
printf "%#{Node.max_node_name_length}s: %s\n", node.hostname, line.strip
end
output.close
if $?
status = $?.exitstatus
if status != 0
raise CommandFailed.new([node.hostname, 'FAILED with exit status %d' % status].join(': '))
end
end
end
|
#run_as_root(cmd) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/chake/backend.rb', line 43
def run_as_root(cmd)
if node.remote_username == 'root'
run(cmd)
else
run('sudo ' + cmd)
end
end
|
#run_shell ⇒ Object
39
40
41
|
# File 'lib/chake/backend.rb', line 39
def run_shell
system(*shell_command)
end
|
#scp ⇒ Object
8
9
10
|
# File 'lib/chake/backend.rb', line 8
def scp
['scp']
end
|
#scp_dest ⇒ Object
12
13
14
|
# File 'lib/chake/backend.rb', line 12
def scp_dest
''
end
|
#skip? ⇒ Boolean
55
56
57
|
# File 'lib/chake/backend.rb', line 55
def skip?
false
end
|
#to_s ⇒ Object
51
52
53
|
# File 'lib/chake/backend.rb', line 51
def to_s
self.class.backend_name
end
|