Class: EventMachine::WinRM::Shell
- Inherits:
-
Object
- Object
- EventMachine::WinRM::Shell
- Includes:
- EM::Deferrable
- Defined in:
- lib/em-winrm/shell.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#remote_id ⇒ Object
Returns the value of attribute remote_id.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
-
#close ⇒ Object
Close and cleanup a shell.
-
#initialize(client, server) ⇒ Shell
constructor
A new instance of Shell.
-
#on_close(&block) ⇒ Object
called whenever the shell is closed.
-
#on_error(&block) ⇒ Object
called whenever the shell has error output.
-
#on_output(&block) ⇒ Object
called whenever the shell has output.
-
#run_command(command) ⇒ Object
Open a shell and run a comamnd.
Constructor Details
#initialize(client, server) ⇒ Shell
Returns a new instance of Shell.
26 27 28 29 30 31 32 33 |
# File 'lib/em-winrm/shell.rb', line 26 def initialize(client, server) @client = client @server = server @remote_id = client.open_shell WinRM::Log.debug("#{server.host}[#{@remote_id}] => :shell_open") @out_channel = EM::Channel.new @err_channel = EM::Channel.new end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
24 25 26 |
# File 'lib/em-winrm/shell.rb', line 24 def client @client end |
#remote_id ⇒ Object
Returns the value of attribute remote_id.
24 25 26 |
# File 'lib/em-winrm/shell.rb', line 24 def remote_id @remote_id end |
#server ⇒ Object
Returns the value of attribute server.
24 25 26 |
# File 'lib/em-winrm/shell.rb', line 24 def server @server end |
Instance Method Details
#close ⇒ Object
Close and cleanup a shell
76 77 78 79 80 |
# File 'lib/em-winrm/shell.rb', line 76 def close r = client.close_shell(@remote_id) WinRM::Log.debug("#{server.host}[#{@remote_id}] => :shell_close") @on_close.call(r,@last_exit_code) if @on_close end |
#on_close(&block) ⇒ Object
called whenever the shell is closed
52 53 54 |
# File 'lib/em-winrm/shell.rb', line 52 def on_close(&block) @on_close = block end |
#on_error(&block) ⇒ Object
called whenever the shell has error output
45 46 47 |
# File 'lib/em-winrm/shell.rb', line 45 def on_error(&block) @err_channel.subscribe block end |
#on_output(&block) ⇒ Object
called whenever the shell has output
38 39 40 |
# File 'lib/em-winrm/shell.rb', line 38 def on_output(&block) @out_channel.subscribe block end |
#run_command(command) ⇒ Object
Open a shell and run a comamnd
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/em-winrm/shell.rb', line 59 def run_command(command) command_id = client.run_command(@remote_id, command) WinRM::Log.debug("#{server.host}[#{@remote_id}] => :run_command[#{command}]") output=client.get_command_output(@remote_id, command_id) do |out,error| @out_channel.push(out) if out @err_channel.push(error) if error end client.cleanup_command(@remote_id, command_id) WinRM::Log.debug("#{server.host}[#{@remote_id}] => :command_cleanup[#{command}]") @last_exit_code = output[:exitcode] close output[:exitcode] end |