Class: RemoteCommand
- Inherits:
-
Object
- Object
- RemoteCommand
- Defined in:
- lib/script_executor/remote_command.rb
Instance Attribute Summary collapse
-
#capture_output ⇒ Object
readonly
Returns the value of attribute capture_output.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output_stream ⇒ Object
readonly
Returns the value of attribute output_stream.
-
#simulate ⇒ Object
readonly
Returns the value of attribute simulate.
-
#suppress_output ⇒ Object
readonly
Returns the value of attribute suppress_output.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #execute(commands, line_action) ⇒ Object
-
#initialize(params) ⇒ RemoteCommand
constructor
A new instance of RemoteCommand.
Constructor Details
#initialize(params) ⇒ RemoteCommand
Returns a new instance of RemoteCommand.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/script_executor/remote_command.rb', line 8 def initialize(params) params = sanitize_parameters params @host = params.delete(:domain) @host = params.delete(:host) if host.nil? and params[:host] @user = params.delete(:user) @suppress_output = params.delete(:suppress_output) @capture_output = params.delete(:capture_output) @output_stream = params[:output_stream] @simulate = params.delete(:simulate) @options = params end |
Instance Attribute Details
#capture_output ⇒ Object (readonly)
Returns the value of attribute capture_output.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def capture_output @capture_output end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def @options end |
#output_stream ⇒ Object (readonly)
Returns the value of attribute output_stream.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def output_stream @output_stream end |
#simulate ⇒ Object (readonly)
Returns the value of attribute simulate.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def simulate @simulate end |
#suppress_output ⇒ Object (readonly)
Returns the value of attribute suppress_output.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def suppress_output @suppress_output end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/script_executor/remote_command.rb', line 6 def user @user end |
Instance Method Details
#execute(commands, line_action) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/script_executor/remote_command.rb', line 23 def execute(commands, line_action) [:password] = HighLine.new.ask("Enter password for #{user}: ") {|q| q.echo = '*'} if [:password].nil? [:user] = user print commands, $stdout unless simulate storage = capture_output ? OutputBuffer.new : nil output = if output_stream output_stream else suppress_output ? nil : $stdout end Net::SSH.start(host, user, ) do |session| session.exec(commands) do |channel, _, line| if ask_password?(line) channel.request_pty channel.send_data [:password] + "\n" else if output output.write(line) output.flush end if storage storage.save(line.chomp) end line_action.call(line) if line_action end end session.loop # run the aggregated event loop end storage.buffer.join("\n") if storage end end |