Class: Octosh::Worker
- Inherits:
-
Object
- Object
- Octosh::Worker
- Defined in:
- lib/octosh/worker/worker.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#ssh ⇒ Object
readonly
Returns the value of attribute ssh.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #exec(command) ⇒ Object
- #exec_script(script_path) ⇒ Object
- #get(remote_path, local_path) ⇒ Object
-
#initialize(host, user, pass) ⇒ Worker
constructor
A new instance of Worker.
- #put(local_path, remote_path) ⇒ Object
- #read(remote_path) ⇒ Object
Constructor Details
#initialize(host, user, pass) ⇒ Worker
Returns a new instance of Worker.
11 12 13 14 15 16 17 |
# File 'lib/octosh/worker/worker.rb', line 11 def initialize(host, user, pass) @host = host @user = user @password = pass @ssh = Net::SSH.start(@host, @user, :password => @password) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/octosh/worker/worker.rb', line 9 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/octosh/worker/worker.rb', line 9 def password @password end |
#ssh ⇒ Object (readonly)
Returns the value of attribute ssh.
9 10 11 |
# File 'lib/octosh/worker/worker.rb', line 9 def ssh @ssh end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
9 10 11 |
# File 'lib/octosh/worker/worker.rb', line 9 def user @user end |
Instance Method Details
#exec(command) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/octosh/worker/worker.rb', line 19 def exec(command) channel = @ssh.open_channel do |ch| ch.exec(command) do |ch, success| raise "Error executing #{command}" unless success ch.on_data do |c, data| puts "#{@host} -- #{data.to_s}" end ch.on_extended_data do |c, type, data| puts "#{@host} -- #{data}" end ch.on_close do #puts "Octosh execution complete!" end end end channel.wait end |
#exec_script(script_path) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/octosh/worker/worker.rb', line 53 def exec_script(script_path) tmp_script_name = "octosh-#{Pathname.new(script_path).basename.to_s}-#{UUID.new.generate}" self.put(script_path, "/tmp/#{tmp_script_name}") self.exec("chmod +x /tmp/#{tmp_script_name}") return self.exec("/tmp/#{tmp_script_name}") end |
#get(remote_path, local_path) ⇒ Object
45 46 47 |
# File 'lib/octosh/worker/worker.rb', line 45 def get(remote_path, local_path) @ssh.scp.download!(remote_path, local_path) end |
#put(local_path, remote_path) ⇒ Object
41 42 43 |
# File 'lib/octosh/worker/worker.rb', line 41 def put(local_path, remote_path) @ssh.scp.upload!(local_path, remote_path) end |
#read(remote_path) ⇒ Object
49 50 51 |
# File 'lib/octosh/worker/worker.rb', line 49 def read(remote_path) return @ssh.scp.download!(remote_path) end |