oxidized-ssh 0.1.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe298db180b2633f350b7725072152ee36fcd47c
4
- data.tar.gz: a69a0590baa1b41365a5dd18f562aa52e6c2a768
3
+ metadata.gz: 0c45bf726f7d3c22eb878169ae8592d04f34d3b8
4
+ data.tar.gz: 9820acba3c7bad72fc906b83b308c44e02b452d7
5
5
  SHA512:
6
- metadata.gz: 4ee8e960477b6240a4c3bfaffb665feafb26f4f609e487288cef1575b6251ca5f217de4d26dae07e786228a375d6ed57f54007682075a5d50cfafe80b37ba63b
7
- data.tar.gz: f85cd8cd83f1689f67cd738aeb4b93c6a9d176b43cb901a36665d01efa1b2e1c3d2dfc77eb4e668c0e91d4fcdcbb8b702e882ed222f6c3845c9437decdb71531
6
+ metadata.gz: dc2fa8e5687d2bc8ac2d15568dd880de213d97bf28a05354faeaa054a2ff9a96099e62499a46e96a4b25c7f377cbad2c644deb8410758871c902b715027d9032
7
+ data.tar.gz: 63dbb43e27c3e0ab9f1cdf24933f1501cbc517aea7b5b3e53cf0a46ead67e6c544f79c5bd530f507ac6f111d3b08c98ba2ec8dc5e972117d841d2b684dabf40b
data/lib/oxidized/ssh.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require_relative "ssh/version"
2
2
  require 'net/ssh'
3
- require 'timeout'
3
+ require 'timeout'
4
+ require 'awesome_print'
4
5
 
5
6
  module Oxidized
6
- class Ssh
7
-
7
+ class SSH
8
+
8
9
  attr_reader :connection, :ip, :username, :password
9
10
  attr_reader :prompt, :verbosity, :exec, :pty_options
10
11
  attr_reader :port, :output, :session
@@ -18,8 +19,9 @@ module Oxidized
18
19
  @exec = options[:exec]
19
20
  @pty_options = options[:pty_options] ||= { term: "vt100" }
20
21
  @port = options[:port] ||= 22
21
- @output = String.new
22
+ @output = String.new
22
23
  @logger = options[:logger] ||= Logger.new(STDOUT)
24
+ @expectation_handler = options[:expectation_handler]
23
25
  end
24
26
 
25
27
  def start
@@ -32,14 +34,14 @@ module Oxidized
32
34
  def exec!(params)
33
35
  check_for_connection
34
36
  exec(params)
35
- @output.gsub(/\r\n/,/\n/)
37
+ @output.gsub(/\r\n/,"\n")
36
38
  end
37
39
 
38
40
  def check_for_connection
39
41
  prep_connection unless @session
40
42
  end
41
43
 
42
- def exec(params)
44
+ def exec(params)
43
45
  @logger.debug "sending command #{params} with expectation of #{@prompt}"
44
46
  if @exec
45
47
  @connection.exec!(params)
@@ -49,19 +51,24 @@ module Oxidized
49
51
  end
50
52
 
51
53
  def collect_output(params)
52
- send_data(params + "\n")
54
+ send_data((params + "\n"))
53
55
  return @output
54
56
  end
55
57
 
56
58
  def send_data(params)
57
59
  expect @prompt
58
60
  reset_output_buffer
59
- @session.send_data params
61
+ send(params)
60
62
  @session.process
61
63
  expect @prompt
64
+ @output
65
+ end
66
+
67
+ def send(params)
68
+ @session.send_data params
62
69
  end
63
70
 
64
- def expect *regexps
71
+ def expect *regexps
65
72
  regexps = [regexps].flatten
66
73
  @logger.debug "expecting #{regexps.inspect} at #{@ip}"
67
74
  @connection.loop(0.1) do
@@ -94,8 +101,17 @@ module Oxidized
94
101
 
95
102
  def set_data_hook(ch)
96
103
  ch.on_data do |_ch, data|
104
+ @logger.debug "received #{data}"
97
105
  @output << data
106
+ @output = expectation_list_handler(@output) if @expectation_handler
107
+ end
108
+ end
109
+
110
+ def expectation_list_handler(data)
111
+ @expectation_handler.each_slice(2) do |handler, meth|
112
+ handler.method(meth.to_sym).call(self, data)
98
113
  end
114
+ @output
99
115
  end
100
116
 
101
117
  def request_channels(ch)
@@ -1,5 +1,5 @@
1
- module Oxidized
2
- module Ssh
3
- VERSION = "0.1.1.1"
4
- end
5
- end
1
+ module Oxidized
2
+ module Ssh
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxidized-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Schylar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh