Class: Orca::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/orca/node.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, host, options = {}) ⇒ Node
Returns a new instance of Node.
18
19
20
21
22
23
24
25
|
# File 'lib/orca/node.rb', line 18
def initialize(name, host, options={})
@name = name
@host = host
@options = options
@connection = nil
@history = []
Orca::Node.register(self)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
31
32
33
|
# File 'lib/orca/node.rb', line 31
def method_missing(meth, *args)
get(meth)
end
|
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5
6
7
|
# File 'lib/orca/node.rb', line 5
def host
@host
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/orca/node.rb', line 5
def name
@name
end
|
Class Method Details
.find(name) ⇒ Object
7
8
9
10
|
# File 'lib/orca/node.rb', line 7
def self.find(name)
return name if name.is_a?(Orca::Node)
@nodes[name]
end
|
.register(node) ⇒ Object
12
13
14
15
16
|
# File 'lib/orca/node.rb', line 12
def self.register(node)
@nodes ||= {}
Orca::Group.from_node(node)
@nodes[node.name] = node
end
|
Instance Method Details
#connection ⇒ Object
88
89
90
91
|
# File 'lib/orca/node.rb', line 88
def connection
return @connection if @connection
@connection = Net::SSH.start(@host, (@options[:user] || 'root'), options_for_ssh)
end
|
#disconnect ⇒ Object
93
94
95
|
# File 'lib/orca/node.rb', line 93
def disconnect
@connection.close if @connection && !@connection.closed?
end
|
#download(from, to) ⇒ Object
40
41
42
43
|
# File 'lib/orca/node.rb', line 40
def download(from, to)
log.sftp("DOWLOAD: #{from} => #{to}")
sftp.download!(from, to)
end
|
#execute(cmd, opts = {}) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/orca/node.rb', line 68
def execute(cmd, opts={})
if should_execute?(cmd, opts)
really_execute(cmd, opts)
else
cached_execute(cmd, opts)
end
end
|
#get(option) ⇒ Object
27
28
29
|
# File 'lib/orca/node.rb', line 27
def get(option)
@options[option]
end
|
#log ⇒ Object
80
81
82
|
# File 'lib/orca/node.rb', line 80
def log
@log
end
|
#log_to(log) ⇒ Object
84
85
86
|
# File 'lib/orca/node.rb', line 84
def log_to(log)
@log = log
end
|
#remove(path) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/orca/node.rb', line 45
def remove(path)
log.sftp("REMOVE: #{path}")
begin
sftp.remove!(path)
rescue Net::SFTP::StatusException
sudo("rm #{path}")
end
end
|
#setstat(path, opts) ⇒ Object
59
60
61
62
|
# File 'lib/orca/node.rb', line 59
def setstat(path, opts)
log.sftp("SET: #{path} - #{opts.inspect}")
sftp.setstat!(path, opts)
end
|
#sftp ⇒ Object
64
65
66
|
# File 'lib/orca/node.rb', line 64
def sftp
@sftp ||= connection.sftp.connect
end
|
#stat(path) ⇒ Object
54
55
56
57
|
# File 'lib/orca/node.rb', line 54
def stat(path)
log.sftp("STAT: #{path}")
sftp.stat!(path)
end
|
#sudo(cmd, opts = {}) ⇒ Object
76
77
78
|
# File 'lib/orca/node.rb', line 76
def sudo(cmd, opts={})
execute("sudo #{cmd}", opts)
end
|
#to_s ⇒ Object
97
98
99
|
# File 'lib/orca/node.rb', line 97
def to_s
"#{name}(#{host})"
end
|
#upload(from, to) ⇒ Object
35
36
37
38
|
# File 'lib/orca/node.rb', line 35
def upload(from, to)
log.sftp("UPLOAD: #{from} => #{to}")
sftp.upload!(from, to)
end
|