expect4r 0.0.10 → 0.0.11
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.
- checksums.yaml +4 -4
- data/CHANGELOG +128 -0
- data/README.rdoc +36 -5
- data/Rakefile +93 -0
- data/VERSION.yml +5 -0
- data/lib/expect/io.rb +45 -14
- data/lib/misc/base.rb +19 -2
- metadata +18 -24
- data/examples/jex1.rb +0 -104
- data/examples/jex2.rb +0 -88
- data/lib/router/cisco/iox/ping.rb +0 -55
- data/test/misc/rspec.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5aa5393e09b5722f0282f34ca2b5934cf2ec1a18
|
4
|
+
data.tar.gz: 3f2ce75b6fdd1ce11a1361486b6bbe888a5beaf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c625dcbaaaf07ea6dbc25e3c66c46e243fe43b8071a9fea075f23816892c5a2a4d86e92e54bcdd6c62c4f8af0afce0f185721b2e5e2ab0ba8d370662120bc94
|
7
|
+
data.tar.gz: 03190a168deefeb21efe1d8100425b0cd38f67e170201e8952939d6b641d70524d9287a8c94023f952186da7f13492b1d6841b153039794c699e38028961eeee
|
data/CHANGELOG
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
=== 0.0.11 Thu Sep 18, 2014
|
2
|
+
|
3
|
+
* Adding connection retry mechanism.
|
4
|
+
When enabled, instead of getting an IO error when attempting to read or write from a disconnected session,
|
5
|
+
the connection will get re-established and the read or write command retried.
|
6
|
+
|
7
|
+
s = Expect4r::Ios.new_ssh ...
|
8
|
+
s.connect_retry
|
9
|
+
s.connect_retry=
|
10
|
+
s.login
|
11
|
+
|
12
|
+
Connection retry is disabled by default:
|
13
|
+
irb > s.connect_retry
|
14
|
+
=> 0
|
15
|
+
to enable it, set then number of connection retry attemtpts:
|
16
|
+
irb > s.connect_retry= 10
|
17
|
+
=> 10
|
18
|
+
|
19
|
+
* Stopped using jeweler to generate Gemfile.
|
20
|
+
|
21
|
+
=== 0.0.10 Tue Aug 6, 2013
|
22
|
+
|
23
|
+
* Adding support ios enable password
|
24
|
+
|
25
|
+
* Fix an issue reported by Gael Leonet where the ios default login banner
|
26
|
+
is getting in the way of matching the username.
|
27
|
+
|
28
|
+
=== 0.0.9 Sat Feb 9, 2013
|
29
|
+
|
30
|
+
* Fix few issues when telnetting to ios
|
31
|
+
send \r instead of \n to get to enabled mode
|
32
|
+
don't try and derive enable_password from password if no password
|
33
|
+
|
34
|
+
* Vyatta:
|
35
|
+
add on_error block for ping
|
36
|
+
|
37
|
+
* moved Base class out of io.rb to misc/base.rb
|
38
|
+
|
39
|
+
* Update gem file
|
40
|
+
add misc/base.rb
|
41
|
+
|
42
|
+
|
43
|
+
=== 0.0.8 Mon Feb 20, 2012
|
44
|
+
|
45
|
+
* add V (vyatta) class
|
46
|
+
|
47
|
+
V.new :ssh, :user=>'vyatta', :pwd=>'vyatta', :host=>'hostname'
|
48
|
+
V.new_ssh 'hostname' (default user to vyatta and pwd to vyatta)
|
49
|
+
V.new_ssh :host=> 'hostname', :user=>'root', :pwd=>'123'
|
50
|
+
|
51
|
+
V.new :telnet, :user=>'vyatta', :pwd=>'vyatta', :host=>'hostname'
|
52
|
+
V.new_telnet 'hostname' (default user to vyatta and pwd to vyatta)
|
53
|
+
V.new_telnet :host=> 'hostname', :user=>'root', :pwd=>'123'
|
54
|
+
|
55
|
+
v.ping '10.0.0.1'
|
56
|
+
v.ping('10.0.0.1', :count=>5) { |r| r.interact }
|
57
|
+
v.ping('10.0.0.1', :count=>5, :size=>512, ...) { |r| r.interact }
|
58
|
+
|
59
|
+
* modify ping to accept a block to be exececuted on error
|
60
|
+
eg,
|
61
|
+
r.ping('10.0.0.1', :count=> 100, :size=>512) { |r| r.interact }
|
62
|
+
|
63
|
+
=== 0.0.7.dev Thu Dec 16, 2010
|
64
|
+
|
65
|
+
* fix _io_save bug when no_echo
|
66
|
+
* add matches to expect()
|
67
|
+
* readline return empty string when timeout
|
68
|
+
|
69
|
+
=== 0.0.6.dev Sun Nov 28, 2010
|
70
|
+
|
71
|
+
* bug fix in Base class
|
72
|
+
* matches to accept String or Proc
|
73
|
+
|
74
|
+
=== 0.0.5.dev Sat Nov 13, 2010
|
75
|
+
|
76
|
+
* new Expect4r::Base class
|
77
|
+
* Fixes
|
78
|
+
|
79
|
+
=== 0.0.4.dev Sat Oct 30, 2010
|
80
|
+
|
81
|
+
* Fixes
|
82
|
+
|
83
|
+
=== 0.0.3 dev Wed Oct 27, 2010
|
84
|
+
|
85
|
+
* Added a RShell class
|
86
|
+
|
87
|
+
* Added login_via method so as to login to a box from another.
|
88
|
+
|
89
|
+
iox = Iox.new_telnet 'router', 'user'
|
90
|
+
iox.login_via RShell.new_ssh('hostname', 'user')
|
91
|
+
|
92
|
+
=== 0.0.2.dev Tue Oct 26, 2010
|
93
|
+
|
94
|
+
* Added Junos#ping
|
95
|
+
* Numerous fixes and improvements to CisoCommon#ping
|
96
|
+
|
97
|
+
=== 0.0.1.dev Mon Oct 25, 2010
|
98
|
+
|
99
|
+
* Initial release.
|
100
|
+
|
101
|
+
While this is still work in progress and buggy, it already allows to:
|
102
|
+
|
103
|
+
+ login to a Cisco router running IOS or IOS-XR or a Juniper router running Junos.
|
104
|
+
+ push configuration using #config() method
|
105
|
+
+ pull states using #show() method
|
106
|
+
+ check connectivity state using #ping() (not yet implemented for J class)
|
107
|
+
|
108
|
+
Provides following:
|
109
|
+
|
110
|
+
Classes:
|
111
|
+
Expect4r::Ios
|
112
|
+
Expect4r::Iox
|
113
|
+
Expect4r::J
|
114
|
+
|
115
|
+
Class methods:
|
116
|
+
new
|
117
|
+
new_ssh
|
118
|
+
new_telnet
|
119
|
+
|
120
|
+
Instance methods:
|
121
|
+
login
|
122
|
+
logout
|
123
|
+
config
|
124
|
+
show
|
125
|
+
shell
|
126
|
+
exec
|
127
|
+
in?
|
128
|
+
ping
|
data/README.rdoc
CHANGED
@@ -20,6 +20,37 @@ You talk to routers by connecting to them using ssh or telnet and send exec or c
|
|
20
20
|
my_mac = RShell.new_ssh 'mac', 'me'
|
21
21
|
router = Iox.new_telnet 'hostname', 'username'
|
22
22
|
router.login_via my_mac
|
23
|
+
|
24
|
+
* Re-establish connection
|
25
|
+
|
26
|
+
irb> localhost = Expect4r::BaseLoginObject.new_ssh :hostname=>'localhost'
|
27
|
+
irb> localhost.connect_retry=10
|
28
|
+
irb> localhost.login
|
29
|
+
irb> localhost.interact
|
30
|
+
irb> s.interact
|
31
|
+
|
32
|
+
#
|
33
|
+
# ^T to terminate.
|
34
|
+
#
|
35
|
+
|
36
|
+
[jme@localhost ~]$ ps -ax | grep localhost
|
37
|
+
5497 pts/8 Ss+ 0:00 ssh localhost
|
38
|
+
5592 pts/9 S+ 0:00 grep --color=auto localhost
|
39
|
+
[jme@localhost ~]$ kill 5497
|
40
|
+
Killed by signal 15.
|
41
|
+
|
42
|
+
[jme@localhost ~]$
|
43
|
+
[jme@localhost ~]$ ls
|
44
|
+
Desktop Downloads Music Public Videos
|
45
|
+
Documents expect4r-0.0.11.gem Pictures Templates
|
46
|
+
[jme@localhost ~]$ ps -ax | grep localhost
|
47
|
+
5648 pts/9 Ss+ 0:00 ssh localhost
|
48
|
+
5777 pts/10 S+ 0:00 grep --color=auto localhost
|
49
|
+
[jme@localhost ~]$
|
50
|
+
[jme@localhost ~]$ ^T
|
51
|
+
irb>
|
52
|
+
|
53
|
+
|
23
54
|
|
24
55
|
* Push configurations to routers
|
25
56
|
|
@@ -41,7 +72,7 @@ You talk to routers by connecting to them using ssh or telnet and send exec or c
|
|
41
72
|
interface GigabitEthernet0/2/0/0
|
42
73
|
desc to switch port 13'
|
43
74
|
ipv4 address 190.0.0.9 255.255.255.252'
|
44
|
-
no shut
|
75
|
+
no shut
|
45
76
|
|
|
46
77
|
|
47
78
|
j.config %{
|
@@ -69,13 +100,13 @@ You talk to routers by connecting to them using ssh or telnet and send exec or c
|
|
69
100
|
irb> r.interact
|
70
101
|
|
71
102
|
#
|
72
|
-
# ^
|
103
|
+
# ^T to terminate.
|
73
104
|
#
|
74
105
|
|
75
106
|
router#clear line 2
|
76
107
|
[confirm]
|
77
108
|
[OK]
|
78
|
-
router# ^
|
109
|
+
router# ^T
|
79
110
|
=> nil
|
80
111
|
irb>
|
81
112
|
|
@@ -83,7 +114,7 @@ You talk to routers by connecting to them using ssh or telnet and send exec or c
|
|
83
114
|
irb(main):210:0* j.interact
|
84
115
|
|
85
116
|
#
|
86
|
-
# ^
|
117
|
+
# ^T to terminate.
|
87
118
|
#
|
88
119
|
|
89
120
|
jme@router> configure
|
@@ -98,7 +129,7 @@ You talk to routers by connecting to them using ssh or telnet and send exec or c
|
|
98
129
|
jme@router# show | compare
|
99
130
|
|
100
131
|
[edit]
|
101
|
-
jme@router# ^
|
132
|
+
jme@router# ^T
|
102
133
|
=> nil
|
103
134
|
irb(main):211:0>
|
104
135
|
|
data/Rakefile
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rdoc/task'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require "rake/clean"
|
5
|
+
|
6
|
+
task "default" => 'test'
|
7
|
+
|
8
|
+
CLEAN.include ["*.gem", "pkg", "rdoc"]
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'jeweler'
|
12
|
+
Jeweler::Tasks.new do |s|
|
13
|
+
s.name = 'expect4r'
|
14
|
+
s.authors = ['Jean-Michel Esnault']
|
15
|
+
s.email = "jesnault@gmail.com"
|
16
|
+
s.summary = "Expect4r"
|
17
|
+
s.description = "A Ruby Library for interacting with IOS, IOS-XR, and JUNOS CLI."
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.executables = []
|
20
|
+
s.files = %w( LICENSE COPYING README.rdoc ) + Dir["lib/**/*"] + ["examples/**/*"]
|
21
|
+
s.test_files = Dir["test/**/*"]
|
22
|
+
s.has_rdoc = false
|
23
|
+
s.rdoc_options = ["--quiet", "--title", "Expect4r", "--line-numbers"]
|
24
|
+
s.require_path = 'lib'
|
25
|
+
s.required_ruby_version = ">= 1.8.6"
|
26
|
+
s.add_dependency('highline', '>= 1.5.0')
|
27
|
+
s.homepage = "http://github.com/jesnault/expect4r"
|
28
|
+
# s.rubyforge_project = 'expect4r'
|
29
|
+
end
|
30
|
+
rescue LoadError
|
31
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
32
|
+
end
|
33
|
+
|
34
|
+
# These are new tasks
|
35
|
+
begin
|
36
|
+
require 'rake/contrib/sshpublisher'
|
37
|
+
namespace :rubyforge do
|
38
|
+
|
39
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
40
|
+
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
41
|
+
|
42
|
+
namespace :release do
|
43
|
+
desc "Publish RDoc to RubyForge."
|
44
|
+
task :docs => [:rdoc] do
|
45
|
+
config = YAML.load(
|
46
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
47
|
+
)
|
48
|
+
host = "#{config['username']}@rubyforge.org"
|
49
|
+
remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
|
50
|
+
local_dir = 'rdoc'
|
51
|
+
|
52
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
rescue LoadError
|
57
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
Rake::TestTask.new do |t|
|
62
|
+
t.libs = ['.']
|
63
|
+
t.pattern = "test/**/*test.rb"
|
64
|
+
t.warning = true
|
65
|
+
end
|
66
|
+
|
67
|
+
Rake::RDocTask.new do |t|
|
68
|
+
t.rdoc_dir = 'rdoc'
|
69
|
+
t.rdoc_files.include("lib/**/*.rb")
|
70
|
+
t.options = ["--quiet", "--title", "Expect4r", "--line-numbers"]
|
71
|
+
t.options << '--fileboxes'
|
72
|
+
end
|
73
|
+
|
74
|
+
require 'rubygems/package_task'
|
75
|
+
|
76
|
+
namespace :gem do
|
77
|
+
|
78
|
+
desc "Run :package and install the .gem locally"
|
79
|
+
task :install => [:gem, :package] do
|
80
|
+
sh %{sudo gem install --local pkg/interact-#{PKG_VERSION}.gem}
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "Like gem:install but without ri or rdocs"
|
84
|
+
task :install_fast => [:gem, :package] do
|
85
|
+
sh %{sudo gem install --local pkg/interact-#{PKG_VERSION}.gem --no-rdoc --no-ri}
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Run :clean and uninstall the .gem"
|
89
|
+
task :uninstall => :clean do
|
90
|
+
sh %{sudo gem uninstall interact}
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/VERSION.yml
ADDED
data/lib/expect/io.rb
CHANGED
@@ -137,18 +137,35 @@ module Expect4r
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def exp_print(s)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
140
|
+
_retry=self.connect_retry
|
141
|
+
begin
|
142
|
+
exp_internal "print: #{s.inspect}, io_writer: #{@w}"
|
143
|
+
return unless @w
|
144
|
+
@w.print(s) and flush
|
145
|
+
rescue Errno::EIO, Errno::ECHILD
|
146
|
+
child_exit
|
147
|
+
exp_internal "session disconnected: retrying..."
|
148
|
+
raise unless _retry>0
|
149
|
+
_retry -=1
|
150
|
+
sleep(1)
|
151
|
+
self.login
|
152
|
+
retry
|
153
|
+
end
|
146
154
|
end
|
155
|
+
|
147
156
|
def getc
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
157
|
+
_retry=self.connect_retry
|
158
|
+
begin
|
159
|
+
@r.getc if @r
|
160
|
+
rescue Errno::EIO, Errno::ECHILD
|
161
|
+
child_exit
|
162
|
+
exp_internal "session disconnected: retrying..."
|
163
|
+
raise unless _retry>0
|
164
|
+
_retry -=1
|
165
|
+
sleep(1)
|
166
|
+
self.login
|
167
|
+
retry
|
168
|
+
end
|
152
169
|
end
|
153
170
|
|
154
171
|
def interact(k="C-t")
|
@@ -264,7 +281,7 @@ module Expect4r
|
|
264
281
|
end
|
265
282
|
alias :login_via :login_by_proxy
|
266
283
|
|
267
|
-
def _login(cmd, arg={})
|
284
|
+
def _login(cmd=self.spawnee, arg={})
|
268
285
|
|
269
286
|
return if connected?
|
270
287
|
|
@@ -351,7 +368,7 @@ module Expect4r
|
|
351
368
|
end
|
352
369
|
[buf, ev]
|
353
370
|
end
|
354
|
-
|
371
|
+
|
355
372
|
alias :login :_login
|
356
373
|
|
357
374
|
|
@@ -366,7 +383,7 @@ module Expect4r
|
|
366
383
|
|
367
384
|
#FIXME ? putline to send_cmd ?
|
368
385
|
# hide putline and expose cmd
|
369
|
-
def
|
386
|
+
def _putline_(line, arg={})
|
370
387
|
raise ConnectionError.new(line) if child_exited?
|
371
388
|
|
372
389
|
arg = {:ti=>13, :no_echo=>false, :debug=>0, :sync=> false, :no_trim=>false}.merge(arg)
|
@@ -429,6 +446,21 @@ module Expect4r
|
|
429
446
|
end
|
430
447
|
[buf, rc]
|
431
448
|
end
|
449
|
+
|
450
|
+
def putline(*args)
|
451
|
+
_retry=self.connect_retry
|
452
|
+
begin
|
453
|
+
_putline_(*args)
|
454
|
+
rescue Errno::EIO, Errno::ECHILD
|
455
|
+
child_exit
|
456
|
+
exp_internal "session disconnected: retrying..."
|
457
|
+
raise unless _retry>0
|
458
|
+
_retry -=1
|
459
|
+
sleep(1)
|
460
|
+
self.login
|
461
|
+
retry
|
462
|
+
end
|
463
|
+
end
|
432
464
|
|
433
465
|
def writer(k)
|
434
466
|
stty_raw
|
@@ -458,7 +490,6 @@ module Expect4r
|
|
458
490
|
rescue Errno::EIO
|
459
491
|
rescue => e
|
460
492
|
p e
|
461
|
-
p '7777777'
|
462
493
|
ensure
|
463
494
|
stty_cooked
|
464
495
|
end
|
data/lib/misc/base.rb
CHANGED
@@ -145,8 +145,11 @@ module Expect4r
|
|
145
145
|
self
|
146
146
|
end
|
147
147
|
|
148
|
-
attr_writer :host, :
|
148
|
+
attr_writer :host, :user, :port
|
149
149
|
alias :hostname= :host=
|
150
|
+
alias :username= :user=
|
151
|
+
|
152
|
+
attr_accessor :ssh_options
|
150
153
|
|
151
154
|
def method=(arg)
|
152
155
|
case arg
|
@@ -160,7 +163,12 @@ module Expect4r
|
|
160
163
|
def spawnee
|
161
164
|
case method
|
162
165
|
when :telnet ; "telnet #{host} #{port if port>0}"
|
163
|
-
when :ssh
|
166
|
+
when :ssh
|
167
|
+
cmd ="ssh #{host}"
|
168
|
+
cmd +=" -oPort=#{port}" if port>0
|
169
|
+
cmd +=" -oUser=#{spawnee_username}" if spawnee_username
|
170
|
+
cmd += [" ", [ssh_options]].flatten.join(" ") if ssh_options
|
171
|
+
cmd
|
164
172
|
else
|
165
173
|
raise RuntimeError
|
166
174
|
end
|
@@ -173,6 +181,15 @@ module Expect4r
|
|
173
181
|
def spawnee_prompt
|
174
182
|
@ps1
|
175
183
|
end
|
184
|
+
|
185
|
+
def connect_retry
|
186
|
+
@connect_retry ||= 0
|
187
|
+
end
|
188
|
+
|
189
|
+
def connect_retry=(arg)
|
190
|
+
raise ArgumentError unless (0 .. 100_000) === arg
|
191
|
+
@connect_retry = arg
|
192
|
+
end
|
176
193
|
|
177
194
|
def dup
|
178
195
|
if @pwd
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expect4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Michel Esnault
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.5
|
19
|
+
version: '1.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.5
|
26
|
+
version: '1.5'
|
27
27
|
description: A Ruby Library for interacting with IOS, IOS-XR, and JUNOS CLI.
|
28
28
|
email: jesnault@gmail.com
|
29
29
|
executables: []
|
@@ -32,11 +32,12 @@ extra_rdoc_files:
|
|
32
32
|
- LICENSE
|
33
33
|
- README.rdoc
|
34
34
|
files:
|
35
|
+
- CHANGELOG
|
35
36
|
- COPYING
|
36
37
|
- LICENSE
|
37
38
|
- README.rdoc
|
38
|
-
-
|
39
|
-
-
|
39
|
+
- Rakefile
|
40
|
+
- VERSION.yml
|
40
41
|
- lib/expect/io.rb
|
41
42
|
- lib/expect4r.rb
|
42
43
|
- lib/misc/base.rb
|
@@ -50,7 +51,6 @@ files:
|
|
50
51
|
- lib/router/cisco/ios/termserver.rb
|
51
52
|
- lib/router/cisco/iox/iox.rb
|
52
53
|
- lib/router/cisco/iox/modes.rb
|
53
|
-
- lib/router/cisco/iox/ping.rb
|
54
54
|
- lib/router/common.rb
|
55
55
|
- lib/router/error.rb
|
56
56
|
- lib/router/juniper/junos/junos.rb
|
@@ -65,38 +65,32 @@ files:
|
|
65
65
|
- test/expect4r_test.rb
|
66
66
|
- test/misc/base_test.rb
|
67
67
|
- test/misc/passwd_test.rb
|
68
|
-
- test/misc/rspec.rb
|
69
68
|
- test/router/cisco/iox/iox_test.rb
|
70
69
|
homepage: http://github.com/jesnault/expect4r
|
71
70
|
licenses: []
|
72
71
|
metadata: {}
|
73
72
|
post_install_message:
|
74
73
|
rdoc_options:
|
75
|
-
- --quiet
|
76
|
-
- --title
|
74
|
+
- "--quiet"
|
75
|
+
- "--title"
|
77
76
|
- Expect4r
|
78
|
-
- --line-numbers
|
77
|
+
- "--line-numbers"
|
79
78
|
require_paths:
|
80
79
|
- lib
|
81
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
81
|
requirements:
|
83
|
-
- -
|
82
|
+
- - ">="
|
84
83
|
- !ruby/object:Gem::Version
|
85
84
|
version: 1.8.6
|
86
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
86
|
requirements:
|
88
|
-
- -
|
87
|
+
- - ">="
|
89
88
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
89
|
+
version: 1.3.6
|
91
90
|
requirements: []
|
92
91
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.2.2
|
94
93
|
signing_key:
|
95
94
|
specification_version: 4
|
96
|
-
summary:
|
97
|
-
test_files:
|
98
|
-
- test/expect4r_test.rb
|
99
|
-
- test/misc/base_test.rb
|
100
|
-
- test/misc/passwd_test.rb
|
101
|
-
- test/misc/rspec.rb
|
102
|
-
- test/router/cisco/iox/iox_test.rb
|
95
|
+
summary: Best way to connect to your routers and other devices using ruby
|
96
|
+
test_files: []
|
data/examples/jex1.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'expect4r'
|
2
|
-
require "enumerator"
|
3
|
-
include Expect4r
|
4
|
-
include Expect4r::Router::Error
|
5
|
-
|
6
|
-
paris_config = %|
|
7
|
-
top
|
8
|
-
edit logical-router Paris interface fxp0 unit 25
|
9
|
-
set vlan-id 25
|
10
|
-
set family inet address 40.0.1.1/24
|
11
|
-
top
|
12
|
-
edit logical-router Paris interface fxp1 unit 22
|
13
|
-
set vlan-id 22
|
14
|
-
set family inet address 40.0.2.1/24
|
15
|
-
top
|
16
|
-
edit logical-router Paris interface lo0 unit 1
|
17
|
-
set family inet address 192.168.127.1/32
|
18
|
-
top
|
19
|
-
edit logical-router Paris interface fxp0 unit 24
|
20
|
-
set vlan-id 24
|
21
|
-
set family inet address 40.0.0.2/24
|
22
|
-
top
|
23
|
-
edit logical-router Paris
|
24
|
-
set routing-options autonomous-system 200
|
25
|
-
top
|
26
|
-
edit logical-router Paris protocols bgp
|
27
|
-
edit group session-to-300
|
28
|
-
set type external
|
29
|
-
set peer-as 300
|
30
|
-
set neighbor 40.0.1.2 peer-as 300
|
31
|
-
exit
|
32
|
-
edit group session-to-210
|
33
|
-
set type external
|
34
|
-
set peer-as 210
|
35
|
-
set neighbor 40.0.2.2 peer-as 210
|
36
|
-
exit
|
37
|
-
edit group session-to-100
|
38
|
-
set type external
|
39
|
-
set peer-as 100
|
40
|
-
set neighbor 40.0.0.1 peer-as 100
|
41
|
-
|
|
42
|
-
|
43
|
-
orleans_config = %|
|
44
|
-
top
|
45
|
-
edit logical-router Orleans interface fxp2 unit 22
|
46
|
-
set vlan-id 22
|
47
|
-
set family inet address 40.0.2.2/24
|
48
|
-
top
|
49
|
-
edit logical-router Orleans
|
50
|
-
set routing-options autonomous-system 100
|
51
|
-
top
|
52
|
-
edit logical-router Orleans protocols bgp
|
53
|
-
edit group session-to-200
|
54
|
-
set type external
|
55
|
-
set peer-as 200
|
56
|
-
set neighbor 40.0.2.1 peer-as 200
|
57
|
-
|
|
58
|
-
|
59
|
-
begin
|
60
|
-
|
61
|
-
paris = J.new_telnet('olive', 'jme').login
|
62
|
-
orleans = J.new_telnet('olive', 'jme').login
|
63
|
-
|
64
|
-
threads =[]
|
65
|
-
threads << Thread.new { paris.config paris_config }
|
66
|
-
threads << Thread.new { p orleans.config orleans_config }
|
67
|
-
threads.each { |th| th.join }
|
68
|
-
|
69
|
-
rescue ConnectionError => e
|
70
|
-
|
71
|
-
p 'CONNECTION ERROR'
|
72
|
-
|
73
|
-
puts e.err_msg
|
74
|
-
|
75
|
-
rescue SyntaxError, SemanticError => e
|
76
|
-
|
77
|
-
p 'CONFIG ERROR'
|
78
|
-
puts e.err_msg
|
79
|
-
|
80
|
-
else
|
81
|
-
|
82
|
-
begin
|
83
|
-
|
84
|
-
paris.ping '40.0.2.1', :logical_router=>'Paris', :count=>100
|
85
|
-
orleans.ping '40.0.2.2', :logical_router=>'Orleans', :count=>100
|
86
|
-
|
87
|
-
rescue PingError => e
|
88
|
-
|
89
|
-
p 'PING ERROR'
|
90
|
-
puts e.err_msg
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
ensure
|
95
|
-
|
96
|
-
[paris, orleans].each { |r| r.logout }
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
data/examples/jex2.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require 'expect4r'
|
3
|
-
|
4
|
-
class TestPingTest < Test::Unit::TestCase
|
5
|
-
include Expect4r
|
6
|
-
include Expect4r::Router::Error
|
7
|
-
|
8
|
-
def setup
|
9
|
-
|
10
|
-
paris_config = %|
|
11
|
-
top
|
12
|
-
edit logical-router Paris interface fxp0 unit 25
|
13
|
-
set vlan-id 25
|
14
|
-
set family inet address 40.0.1.1/24
|
15
|
-
top
|
16
|
-
edit logical-router Paris interface fxp1 unit 22
|
17
|
-
set vlan-id 22
|
18
|
-
set family inet address 40.0.2.1/24
|
19
|
-
top
|
20
|
-
edit logical-router Paris interface lo0 unit 1
|
21
|
-
set family inet address 192.168.127.1/32
|
22
|
-
top
|
23
|
-
edit logical-router Paris interface fxp0 unit 24
|
24
|
-
set vlan-id 24
|
25
|
-
set family inet address 40.0.0.2/24
|
26
|
-
top
|
27
|
-
edit logical-router Paris
|
28
|
-
set routing-options autonomous-system 200
|
29
|
-
top
|
30
|
-
edit logical-router Paris protocols bgp
|
31
|
-
edit group session-to-300
|
32
|
-
set type external
|
33
|
-
set peer-as 300
|
34
|
-
set neighbor 40.0.1.2 peer-as 300
|
35
|
-
exit
|
36
|
-
edit group session-to-210
|
37
|
-
set type external
|
38
|
-
set peer-as 210
|
39
|
-
set neighbor 40.0.2.2 peer-as 210
|
40
|
-
exit
|
41
|
-
edit group session-to-100
|
42
|
-
set type external
|
43
|
-
set peer-as 100
|
44
|
-
set neighbor 40.0.0.1 peer-as 100
|
45
|
-
|
|
46
|
-
|
47
|
-
orleans_config = %|
|
48
|
-
top
|
49
|
-
edit logical-router Orleans interface fxp2 unit 22
|
50
|
-
set vlan-id 22
|
51
|
-
set family inet address 40.0.2.2/24
|
52
|
-
top
|
53
|
-
edit logical-router Orleans
|
54
|
-
set routing-options autonomous-system 100
|
55
|
-
top
|
56
|
-
edit logical-router Orleans protocols bgp
|
57
|
-
edit group session-to-200
|
58
|
-
set type external
|
59
|
-
set peer-as 200
|
60
|
-
set neighbor 40.0.2.1 peer-as 200
|
61
|
-
|
|
62
|
-
|
63
|
-
@paris = J.new_ssh('olive', 'jesnault', 'HomeLab').login
|
64
|
-
@orleans = J.new_ssh('olive', 'jesnault', 'HomeLab').login
|
65
|
-
threads =[]
|
66
|
-
threads << Thread.new { @paris.config paris_config }
|
67
|
-
threads << Thread.new { @orleans.config orleans_config }
|
68
|
-
threads.each { |th| th.join }
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
def teardown
|
73
|
-
@paris.config "delete logical-routers"
|
74
|
-
[@paris, @orleans].each { |r| r.logout }
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_ping_test
|
78
|
-
assert_nothing_raised(Exception) {
|
79
|
-
threads =[]
|
80
|
-
threads << Thread.new { @paris.ping '40.0.2.1', :logical_router=>'Paris', :count=>100 }
|
81
|
-
threads << Thread.new { @orleans.ping '40.0.2.2', :logical_router=>'Orleans', :count=>100 }
|
82
|
-
threads.each { |th| th.join }
|
83
|
-
}
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
@@ -1,55 +0,0 @@
|
|
1
|
-
|
2
|
-
__END__
|
3
|
-
|
4
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 ?
|
5
|
-
donotfrag set DF bit in IP header
|
6
|
-
pattern data pattern
|
7
|
-
size datagram size
|
8
|
-
source source address or source interface
|
9
|
-
sweep sweep ping
|
10
|
-
timeout timeout in seconds
|
11
|
-
type type of service
|
12
|
-
validate validate return packet
|
13
|
-
verbose verbose output
|
14
|
-
<cr>
|
15
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 size ?
|
16
|
-
<36-18024> datagram size
|
17
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 size 100 ?
|
18
|
-
donotfrag set DF bit in IP header
|
19
|
-
pattern data pattern
|
20
|
-
source source address or source interface
|
21
|
-
sweep sweep ping
|
22
|
-
timeout timeout in seconds
|
23
|
-
type type of service
|
24
|
-
validate validate return packet
|
25
|
-
verbose verbose output
|
26
|
-
<cr>
|
27
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 size 100 donotfrag ?
|
28
|
-
pattern data pattern
|
29
|
-
source source address or source interface
|
30
|
-
sweep sweep ping
|
31
|
-
timeout timeout in seconds
|
32
|
-
type type of service
|
33
|
-
validate validate return packet
|
34
|
-
verbose verbose output
|
35
|
-
<cr>
|
36
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 size 100 donotfrag pattern ?
|
37
|
-
<0-65535> data pattern
|
38
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 size 100 donotfrag pattern 0xdead type 2 ?
|
39
|
-
source source address or source interface
|
40
|
-
sweep sweep ping
|
41
|
-
timeout timeout in seconds
|
42
|
-
validate validate return packet
|
43
|
-
verbose verbose output
|
44
|
-
<cr>
|
45
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 size 100 donotfrag pattern 0xdead type 2 timeout 10 sweep ?
|
46
|
-
source source address or source interface
|
47
|
-
validate validate return packet
|
48
|
-
verbose verbose output
|
49
|
-
<cr>
|
50
|
-
RP/0/0/CPU0:Paris-rp0#ping ipv4 1.1.1.1 count 5 size 100 donotfrag pattern 0xdead type 2 timeout 10 sweep ?
|
51
|
-
source source address or source interface
|
52
|
-
validate validate return packet
|
53
|
-
verbose verbose output
|
54
|
-
<cr>
|
55
|
-
RP/0/0/CPU0:Paris-rp0#
|