ruby-eql 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,7 +1,12 @@
1
- === 0.0.1 / 2008-05-28
1
+ === 0.0.2 / 2008-06-06
2
+
3
+ * 1 change
4
+ * net-ssh-telnet becomes its own gem
5
+ * 1 minor enhancement
6
+ * added output_log option
2
7
 
3
- * Initial release
8
+ === 0.0.1 / 2008-05-28
4
9
 
10
+ * 1 major enhancement
5
11
  * Birthday!
6
12
  * Test release.
7
-
data/Manifest.txt CHANGED
@@ -7,5 +7,4 @@ examples/ssh_show_members_with_volumes.rb
7
7
  examples/telnet_options_file_show_version.rb
8
8
  lib/eql.rb
9
9
  lib/eql/cli.rb
10
- lib/netsshtelnet.rb
11
10
  test/test_eql.rb
data/README.txt CHANGED
@@ -21,7 +21,7 @@ series arrays.
21
21
 
22
22
  == REQUIREMENTS:
23
23
 
24
- * net-ssh
24
+ * net-ssh-telnet
25
25
 
26
26
  == INSTALL:
27
27
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'eql'
7
7
 
8
8
  Hoe.new('ruby-eql', Eql::VERSION) do |p|
9
9
  p.developer('Matthew Kent', 'matt@bravenet.com')
10
- p.extra_deps << ['net-ssh', '>= 2.0.1']
10
+ p.extra_deps << ['net-ssh-telnet', '>= 0.0.1']
11
11
  p.remote_rdoc_dir = ''
12
12
  end
13
13
 
@@ -10,9 +10,10 @@ san = Eql::GroupManager.open(
10
10
  :username => 'grpadmin',
11
11
  :password => 'pass',
12
12
  :timeout => 3,
13
- # nb: In telnet mode will print your user/password into the log, though
14
- # in ssh it won't.
15
- :session_log => "debug.log"
13
+ # nb: In telnet mode this will print your user/password into the log,
14
+ # though in ssh it won't.
15
+ :session_log => "session.log",
16
+ :output_log => "output.log"
16
17
  )
17
18
 
18
19
  begin
data/lib/eql.rb CHANGED
@@ -3,11 +3,11 @@
3
3
  require 'net/telnet'
4
4
  require 'yaml'
5
5
 
6
- require 'netsshtelnet'
6
+ require 'net/ssh/telnet'
7
7
  require 'eql/cli'
8
8
 
9
9
  module Eql
10
- VERSION = '0.0.1'
10
+ VERSION = '0.0.2'
11
11
  COMPAT_VERSION = 'V3.3.1 (R68703)'
12
12
 
13
13
  class GroupManager
@@ -63,6 +63,7 @@ module Eql
63
63
  "Username" => args[:username] || DEFAULT_USERNAME,
64
64
  "Password" => args[:password] || DEFAULT_PASSWORD,
65
65
  "Dump_log" => args[:session_log] || nil,
66
+ "Output_log" => args[:output_log] || nil,
66
67
  "Prompt" => PROMPT,
67
68
  # nb: Just net::ssh, net::telnet is autodetected
68
69
  "Terminator" => TERMINATOR,
@@ -70,6 +71,7 @@ module Eql
70
71
 
71
72
  # Don't pass it at all if undefined, they will try to open it
72
73
  @ops.delete("Dump_log") if @ops["Dump_log"].nil?
74
+ @ops.delete("Output_log") if @ops["Output_log"].nil?
73
75
 
74
76
  if @ops["Method"] == "ssh"
75
77
  @ops["Port"] = DEFAULT_SSH_PORT if @ops["Port"].nil?
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ruby-eql
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2008-05-30 00:00:00 -07:00
6
+ version: 0.0.2
7
+ date: 2008-06-06 00:00:00 -07:00
8
8
  summary: Ruby module to make interacting with the Equallogic PSxxxE series command line interface a breeze
9
9
  require_paths:
10
10
  - lib
@@ -61,7 +61,6 @@ files:
61
61
  - examples/telnet_options_file_show_version.rb
62
62
  - lib/eql.rb
63
63
  - lib/eql/cli.rb
64
- - lib/netsshtelnet.rb
65
64
  - test/test_eql.rb
66
65
  test_files:
67
66
  - test/test_eql.rb
@@ -81,13 +80,13 @@ requirements: []
81
80
 
82
81
  dependencies:
83
82
  - !ruby/object:Gem::Dependency
84
- name: net-ssh
83
+ name: net-ssh-telnet
85
84
  version_requirement:
86
85
  version_requirements: !ruby/object:Gem::Version::Requirement
87
86
  requirements:
88
87
  - - ">="
89
88
  - !ruby/object:Gem::Version
90
- version: 2.0.1
89
+ version: 0.0.1
91
90
  version:
92
91
  - !ruby/object:Gem::Dependency
93
92
  name: hoe
metadata.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- 綛��� ޴XV7x�ނ5��u�K!�Z8�c����|��a�����l�%x���!��A;���
2
- .|�yF����1=sDCN��>���_���n�VǞ�҃w���X�]��aMO LHJ;ԟ��Ps�3�s����MY!��'� ���"�\�w�d�+����_����;�\��f�E�P ��%��l�{-�p�Z���i��t�#7=�u%42I�zu�!��aUM�l�3����3�QA�
1
+ �����jEo��� ���Mx��Y)k�@���W��Y�=Lm������ИOB�ξ.�Ud\�
2
+ E����H��qC���Dyx������g�n�MeT$NT9��{Ã���.^�*�O���̓� ��Rÿ A1`��>ȇ�(��]eA���)"ݥK��D�%-�1���Awcz5V��Ff�^�@���y &G��y˙FFG% Zy��/�k_Mʂ�!��g+�>��J*Gȶ�Q�t��'��P���
data/lib/netsshtelnet.rb DELETED
@@ -1,433 +0,0 @@
1
- # Based on code in net/telnet.rb by Wakou Aoyama <wakou@ruby-lang.org>
2
- # Modified to work with Net::SSH by Brian Candler <b.candler@pobox.com>
3
-
4
- require 'rubygems'
5
- require 'net/ssh'
6
-
7
- module Net
8
- module SSH
9
-
10
- # == Net::SSH::Telnet
11
- #
12
- # Provides a simple send/expect interface with an API almost
13
- # identical to Net::Telnet. Please see Net::Telnet for main documentation.
14
- # Only the differences are documented here.
15
-
16
- class Telnet
17
-
18
- CR = "\015"
19
- LF = "\012"
20
- EOL = CR + LF
21
- REVISION = '$Id$'
22
-
23
- # Wrapper to emulate the behaviour of Net::Telnet "Proxy" option, where
24
- # the user passes in an already-open socket
25
-
26
- class TinyFactory
27
- def initialize(sock)
28
- @sock = sock
29
- end
30
- def open(host, port)
31
- s = @sock
32
- @sock = nil
33
- s
34
- end
35
- end
36
-
37
- # Creates a new Net::SSH::Telnet object.
38
- #
39
- # The API is similar to Net::Telnet, although you will need to pass in
40
- # either an existing Net::SSH::Session object or a Username and Password,
41
- # as shown below.
42
- #
43
- # Note that unlike Net::Telnet there is no preprocess method automatically
44
- # setting up options related to proper character translations, so if your
45
- # remote ptty is configured differently than the typical linux one you may
46
- # need to pass in a different terminator or call 'stty' remotely to set it
47
- # into an expected mode. This is better explained by the author of perl's
48
- # Net::SSH::Expect here:
49
- #
50
- # http://search.cpan.org/~bnegrao/Net-SSH-Expect-1.04/lib/Net/SSH/Expect.pod
51
- # #IMPORTANT_NOTES_ABOUT_DEALING_WITH_SSH_AND_PSEUDO-TERMINALS
52
- #
53
- # though for most installs the default LF should be fine. See example 5
54
- # below.
55
- #
56
- # A new option is added to correct a misfeature of Net::Telnet. If you
57
- # pass "FailEOF" => true, then if the remote end disconnects while you
58
- # are still waiting for your match pattern then an EOFError is raised.
59
- # Otherwise, it reverts to the same behaviour as Net::Telnet, which is
60
- # just to return whatever data was sent so far, or nil if no data was
61
- # returned so far. (This is a poor design because you can't tell whether
62
- # the expected pattern was successfully matched or the remote end
63
- # disconnected unexpectedly, unless you perform a second match on the
64
- # return string). See
65
- # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/11373
66
- # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/11380
67
- #
68
- # Example 1 - pass existing Net::SSH::Session object
69
- #
70
- # ssh = Net::SSH.start("127.0.0.1",
71
- # :username=>"test123",
72
- # :password=>"pass456"
73
- # )
74
- # s = Net::SSH::Telnet.new(
75
- # "Dump_log" => "/dev/stdout",
76
- # "Session" => ssh
77
- # )
78
- # puts "Logged in"
79
- # p s.cmd("echo hello")
80
- #
81
- # This is the most flexible way as it allows you to set up the SSH
82
- # session using whatever authentication system you like. When done this
83
- # way, calling Net::SSH::Telnet.new multiple times will create
84
- # multiple channels, and #close will only close one channel.
85
- #
86
- # In all later examples, calling #close will close the entire
87
- # Net::SSH::Session object (and therefore drop the TCP connection)
88
- #
89
- # Example 2 - pass host, username and password
90
- #
91
- # s = Net::SSH::Telnet.new(
92
- # "Dump_log" => "/dev/stdout",
93
- # "Host" => "127.0.0.1",
94
- # "Username" => "test123",
95
- # "Password" => "pass456"
96
- # )
97
- # puts "Logged in"
98
- # puts s.cmd("echo hello")
99
- #
100
- # Example 3 - pass open IO object, username and password (this is really
101
- # just for compatibility with Net::Telnet Proxy feature)
102
- #
103
- # require 'socket'
104
- # sock = TCPSocket.open("127.0.0.1",22)
105
- # s = Net::SSH::Telnet.new(
106
- # "Dump_log" => "/dev/stdout",
107
- # "Proxy" => sock,
108
- # "Username" => "test123",
109
- # "Password" => "pass456"
110
- # )
111
- # puts "Logged in"
112
- # puts s.cmd("echo hello")
113
- #
114
- # Example 4 - pass a connection factory, host, username and password;
115
- # Net::SSH will call #open(host,port) on this object. Included just
116
- # because it was easy :-)
117
- #
118
- # require 'socket'
119
- # s = Net::SSH::Telnet.new(
120
- # "Dump_log" => "/dev/stdout",
121
- # "Factory" => TCPSocket,
122
- # "Host" => "127.0.0.1",
123
- # "Username" => "test123",
124
- # "Password" => "pass456"
125
- # )
126
- # puts "Logged in"
127
- # puts s.cmd("echo hello")
128
- #
129
- # Example 5 - connection to a SAN device running a customized NetBSD with
130
- # different ptty defaults, it doesn't convert LF -> CR+LF (see the man
131
- # page for 'stty')
132
- #
133
- # require 'socket'
134
- # s = Net::SSH::Telnet.new(
135
- # "Dump_log" => "/dev/stdout",
136
- # "Factory" => TCPSocket,
137
- # "Host" => "192.168.1.1",
138
- # "Username" => "test123",
139
- # "Password" => "pass456",
140
- # "Terminator" => "\r"
141
- # )
142
- # puts "Logged in"
143
- # puts s.cmd("show alerts")
144
-
145
- def initialize(options, &blk) # :yield: mesg
146
- @options = options
147
- @options["Host"] = "localhost" unless @options.has_key?("Host")
148
- @options["Port"] = 22 unless @options.has_key?("Port")
149
- @options["Prompt"] = /[$%#>] \z/n unless @options.has_key?("Prompt")
150
- @options["Timeout"] = 10 unless @options.has_key?("Timeout")
151
- @options["Waittime"] = 0 unless @options.has_key?("Waittime")
152
- @options["Terminator"] = LF unless @options.has_key?("Terminator")
153
-
154
- unless @options.has_key?("Binmode")
155
- @options["Binmode"] = false
156
- else
157
- unless (true == @options["Binmode"] or false == @options["Binmode"])
158
- raise ArgumentError, "Binmode option must be true or false"
159
- end
160
- end
161
-
162
- if @options.has_key?("Output_log")
163
- @log = File.open(@options["Output_log"], 'a+')
164
- @log.sync = true
165
- @log.binmode
166
- end
167
-
168
- if @options.has_key?("Dump_log")
169
- @dumplog = File.open(@options["Dump_log"], 'a+')
170
- @dumplog.sync = true
171
- @dumplog.binmode
172
- def @dumplog.log_dump(dir, x) # :nodoc:
173
- len = x.length
174
- addr = 0
175
- offset = 0
176
- while 0 < len
177
- if len < 16
178
- line = x[offset, len]
179
- else
180
- line = x[offset, 16]
181
- end
182
- hexvals = line.unpack('H*')[0]
183
- hexvals += ' ' * (32 - hexvals.length)
184
- hexvals = format("%s %s %s %s " * 4, *hexvals.unpack('a2' * 16))
185
- line = line.gsub(/[\000-\037\177-\377]/n, '.')
186
- printf "%s 0x%5.5x: %s%s\n", dir, addr, hexvals, line
187
- addr += 16
188
- offset += 16
189
- len -= 16
190
- end
191
- print "\n"
192
- end
193
- end
194
-
195
- if @options.has_key?("Session")
196
- @ssh = @options["Session"]
197
- @close_all = false
198
- elsif @options.has_key?("Proxy")
199
- @ssh = Net::SSH.start(@options["Host"], # ignored
200
- :port => @options["Port"], # ignored
201
- :username => @options["Username"],
202
- :password => @options["Password"],
203
- :timeout => @options["Timeout"],
204
- :proxy => TinyFactory.new(@options["Proxy"]),
205
- :log => (@log ? @log : STDERR)
206
- )
207
- @close_all = true
208
- else
209
- message = "Trying " + @options["Host"] + "...\n"
210
- yield(message) if block_given?
211
- @log.write(message) if @options.has_key?("Output_log")
212
- @dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
213
-
214
- begin
215
- @ssh = Net::SSH.start(@options["Host"],
216
- :port => @options["Port"],
217
- :username => @options["Username"],
218
- :password => @options["Password"],
219
- :timeout => @options["Timeout"],
220
- :proxy => @options["Factory"],
221
- :log => (@log ? @log : STDERR)
222
- )
223
- @close_all = true
224
- rescue TimeoutError
225
- raise TimeoutError, "timed out while opening a connection to the host"
226
- rescue
227
- @log.write($ERROR_INFO.to_s + "\n") if @options.has_key?("Output_log")
228
- @dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.has_key?("Dump_log")
229
- raise
230
- end
231
-
232
- message = "Connected to " + @options["Host"] + ".\n"
233
- yield(message) if block_given?
234
- @log.write(message) if @options.has_key?("Output_log")
235
- @dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
236
- end
237
-
238
- @buf = ""
239
- @eof = false
240
- @channel = nil
241
- state = nil
242
- @ssh.open_channel do |channel|
243
- channel.on_success { |ch|
244
- case state
245
- when :pty
246
- state = :shell
247
- channel.send_request "shell", nil, true
248
- when :shell
249
- state = :prompt
250
- @channel = ch
251
- waitfor(@options['Prompt'], &blk)
252
- return
253
- end
254
- }
255
- channel.on_failure { |ch|
256
- case state
257
- when :pty
258
- state = :shell
259
- channel.send_request "shell", nil, true
260
- else
261
- ch.close
262
- raise "Failed to open ssh #{state}"
263
- end
264
- }
265
- channel.on_data { |ch,data| @buf << data }
266
- channel.on_extended_data { |ch,type,data| @buf << data if type == 1 }
267
- channel.on_close { @eof = true }
268
- state = :pty
269
- channel.request_pty(:want_reply => true)
270
- end
271
- @ssh.loop
272
- end # initialize
273
-
274
- # Close the ssh channel, and also the entire ssh session if we
275
- # opened it.
276
-
277
- def close
278
- @channel.close if @channel
279
- @channel = nil
280
- @ssh.close if @close_all and @ssh
281
- end
282
-
283
- # The ssh session and channel we are using.
284
- attr_reader :ssh, :channel
285
-
286
- # Turn newline conversion on (+mode+ == false) or off (+mode+ == true),
287
- # or return the current value (+mode+ is not specified).
288
- def binmode(mode = nil)
289
- case mode
290
- when nil
291
- @options["Binmode"]
292
- when true, false
293
- @options["Binmode"] = mode
294
- else
295
- raise ArgumentError, "argument must be true or false"
296
- end
297
- end
298
-
299
- # Turn newline conversion on (false) or off (true).
300
- def binmode=(mode)
301
- if (true == mode or false == mode)
302
- @options["Binmode"] = mode
303
- else
304
- raise ArgumentError, "argument must be true or false"
305
- end
306
- end
307
-
308
- # Read data from the host until a certain sequence is matched.
309
-
310
- def waitfor(options) # :yield: recvdata
311
- time_out = @options["Timeout"]
312
- waittime = @options["Waittime"]
313
- fail_eof = @options["FailEOF"]
314
-
315
- if options.kind_of?(Hash)
316
- prompt = if options.has_key?("Match")
317
- options["Match"]
318
- elsif options.has_key?("Prompt")
319
- options["Prompt"]
320
- elsif options.has_key?("String")
321
- Regexp.new( Regexp.quote(options["String"]) )
322
- end
323
- time_out = options["Timeout"] if options.has_key?("Timeout")
324
- waittime = options["Waittime"] if options.has_key?("Waittime")
325
- fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
326
- else
327
- prompt = options
328
- end
329
-
330
- if time_out == false
331
- time_out = nil
332
- end
333
-
334
- line = ''
335
- buf = ''
336
- rest = ''
337
- # We want to use #read_ready?(maxwait) but it's not available
338
- sock = @ssh.connection.instance_variable_get(:@session).instance_variable_get(:@socket)
339
-
340
- until prompt === line and ((@eof and @buf == "") or not IO::select([sock], nil, nil, waittime))
341
- while @buf == "" and !@eof
342
- unless IO::select([sock], nil, nil, time_out)
343
- raise TimeoutError, "timed out while waiting for more data"
344
- end
345
- # Note: this could hang if partial message received. Should we
346
- # wrap with timeout { ... } instead?
347
- @channel.connection.process
348
- end
349
- if @buf != ""
350
- c = @buf; @buf = ""
351
- @dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
352
- buf = c
353
- buf.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
354
- rest = ''
355
- @log.print(buf) if @options.has_key?("Output_log")
356
- line += buf
357
- yield buf if block_given?
358
- elsif @eof # End of file reached
359
- break if prompt === line
360
- raise EOFError if fail_eof
361
- if line == ''
362
- line = nil
363
- yield nil if block_given?
364
- end
365
- break
366
- end
367
- end
368
- line
369
- end
370
-
371
- # Write +string+ to the host.
372
- #
373
- # Does not perform any conversions on +string+. Will log +string+ to the
374
- # dumplog, if the Dump_log option is set.
375
- def write(string)
376
- @dumplog.log_dump('>', string) if @options.has_key?("Dump_log")
377
- @channel.send_data string
378
- @channel.connection.process true
379
- end
380
-
381
- # Sends a string to the host.
382
- #
383
- # This does _not_ automatically append a newline to the string. Embedded
384
- # newlines may be converted depending upon the values of binmode or
385
- # terminator.
386
- def print(string)
387
- terminator = @options["Terminator"]
388
-
389
- if @options["Binmode"]
390
- self.write(string)
391
- else
392
- self.write(string.gsub(/\n/n, terminator))
393
- end
394
- end
395
-
396
- # Sends a string to the host.
397
- #
398
- # Same as #print(), but appends a newline to the string.
399
- def puts(string)
400
- self.print(string + "\n")
401
- end
402
-
403
- # Send a command to the host.
404
- #
405
- # More exactly, sends a string to the host, and reads in all received
406
- # data until is sees the prompt or other matched sequence.
407
- #
408
- # The command or other string will have the newline sequence appended
409
- # to it.
410
-
411
- def cmd(options) # :yield: recvdata
412
- match = @options["Prompt"]
413
- time_out = @options["Timeout"]
414
-
415
- if options.kind_of?(Hash)
416
- string = options["String"]
417
- match = options["Match"] if options.has_key?("Match")
418
- time_out = options["Timeout"] if options.has_key?("Timeout")
419
- else
420
- string = options
421
- end
422
-
423
- self.puts(string)
424
- if block_given?
425
- waitfor({"Prompt" => match, "Timeout" => time_out}){|c| yield c }
426
- else
427
- waitfor({"Prompt" => match, "Timeout" => time_out})
428
- end
429
- end
430
-
431
- end # class Telnet
432
- end # module SSH
433
- end # module Net