Class: Bcome::Ssh
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(commands) ⇒ Ssh
constructor
A new instance of Ssh.
- #ssh_exec!(ssh, command) ⇒ Object
Constructor Details
#initialize(commands) ⇒ Ssh
Returns a new instance of Ssh.
5 6 7 |
# File 'lib/ssh.rb', line 5 def initialize(commands) @commands = commands end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
3 4 5 |
# File 'lib/ssh.rb', line 3 def commands @commands end |
Instance Method Details
#execute! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ssh.rb', line 9 def execute! @commands.each do |command| instance = command.instance ssh_user = command.ssh_user ssh_keys = command.ssh_keys proxy = command.proxy ::Net::SSH.start(instance.ip_address, ssh_user, :proxy => proxy, :keys => ssh_keys, :paranoid => false) do |ssh| puts "(#{instance.identifier})$ #{command.command}".command ssh_exec!(ssh, command) puts command.output print command.pretty_result print "\n" ssh.close end end end |
#ssh_exec!(ssh, command) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ssh.rb', line 27 def ssh_exec!(ssh, command) ssh.open_channel do |channel| channel.exec(command.command) do |ch, success| unless success abort "FAILED: couldn't execute command (ssh.channel.exec)" end channel.on_data do |ch,data| command.stdout +=data end channel.on_extended_data do |ch,type,data| command.stderr +=data end channel.on_request("exit-status") do |ch,data| command.exit_code = data.read_long end channel.on_request("exit-signal") do |ch, data| command.exit_signal = data.read_long end end end ssh.loop end |