commutateurs 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 004cc139c226d06b9138a383fbbe24785ddedc4d
4
- data.tar.gz: faf1a3664f09d5cc0cc89d11f6088bbb4c914fc9
3
+ metadata.gz: 7169b4ffc6129dc3f778f246922607fe8959c167
4
+ data.tar.gz: f5bf6bb867c867097eb35e5451bdba5fca781e87
5
5
  SHA512:
6
- metadata.gz: e742d374a0af081ad83d47902ba6d79f6e36a04c902c944967801509d181849dd27fccf9542ce932fe5e9007cf1e50b83df75e4b50066a0e05acf0c69e6ff9c1
7
- data.tar.gz: 958be74a8eebb3780a0b03fb789b3ea54775189c564d6843738e230d12430dfb704944c3a71c2aa18938f23a3de54dcefdad94d1ba222a1e95c1f0a4d2d7bd8b
6
+ metadata.gz: dbe1b0df004ee1a170b7f2a5929bc6a9575c0abede2fa512f24ceba706d62aeb64e7a1ed2d61177bfefd2443e8b4146b3f78f5dd8d202d289a73b770f729e6b6
7
+ data.tar.gz: 382a9ac0525b8ac6639e75ab55ebc00c83fb715c5ec73edd15533bc5c6761dca00a778049ae1d501dd0b4bbe8564466f8a5bce69cd6720ef3b53dba4e5b690a3
data/lib/commutateurs.rb CHANGED
@@ -4,6 +4,11 @@ require 'net/ssh'
4
4
  module Commutateurs
5
5
  end
6
6
 
7
- require 'commutateurs/ssh'
8
- require 'commutateurs/device'
9
-
7
+ require_relative './commutateurs/ssh'
8
+ require_relative './commutateurs/base'
9
+ require_relative './commutateurs/cisco'
10
+ require_relative './commutateurs/credentials'
11
+ require_relative './commutateurs/fortigate'
12
+ require_relative './commutateurs/h3c'
13
+ require_relative './commutateurs/hp'
14
+ require_relative './commutateurs/juniper'
@@ -0,0 +1,16 @@
1
+ module Commutateurs
2
+ class Base
3
+ def initialize(host, credentials, verbose = false)
4
+ @enable = credentials.enable
5
+
6
+ @transport = Ssh.new(verbose)
7
+ @transport.host = host
8
+ @transport.user = credentials.user
9
+ @transport.password = credentials.password
10
+ end
11
+
12
+ def execute(line)
13
+ @transport.command line
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ module Commutateurs
2
+ class Cisco < Base
3
+ def initialize(host, credentials, verbose = false)
4
+ super
5
+ @transport.default_prompt = /[#>]\s?\z/n
6
+ end
7
+
8
+ def enable
9
+ @transport.command("enable", :prompt => /^Password:/)
10
+ @transport.command(@enable)
11
+ end
12
+
13
+ def connect
14
+ @transport.connect
15
+ @transport.command('terminal length 0')
16
+ end
17
+
18
+ def configuration
19
+ execute('show run')
20
+ end
21
+
22
+ def save
23
+ execute('wr mem')
24
+ end
25
+
26
+ def disconnect
27
+ @transport.send 'exit'
28
+ @transport.close
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ module Commutateurs
2
+ class Credentials
3
+ attr_reader :user, :password, :enable
4
+ def initialize(user, password, enable)
5
+ @user = user
6
+ @password = password
7
+ @enable = enable
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module Commutateurs
2
+ class Fortigate < Base
3
+ def initialize(host, credentials, verbose = false)
4
+ super
5
+ @transport.default_prompt = / [#\$] $/
6
+ end
7
+
8
+ def enable
9
+ end
10
+
11
+ def connect
12
+ @transport.connect
13
+ end
14
+
15
+ def configuration
16
+ execute('show')
17
+ end
18
+
19
+ def save
20
+ end
21
+
22
+ def disconnect
23
+ @transport.send 'exit'
24
+ @transport.close
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module Commutateurs
2
+ class H3c < Base
3
+ def initialize(host, credentials, verbose = false)
4
+ super
5
+ @transport.default_prompt = /(<.*>|\[.*\])$/
6
+ end
7
+
8
+ def enable
9
+ @transport.command('super', :prompt => /Password:/)
10
+ @transport.command(@enable)
11
+ @transport.command('screen-length disable')
12
+ end
13
+
14
+ def connect
15
+ @transport.connect
16
+ end
17
+
18
+ def configuration
19
+ execute('dis curr')
20
+ end
21
+
22
+ def save
23
+ @transport.command('save safely', :prompt => /Are you sure/)
24
+ @transport.command('Y', :prompt => /enter key/)
25
+ @transport.command('')
26
+ end
27
+
28
+ def disconnect
29
+ @transport.send 'quit'
30
+ @transport.close
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module Commutateurs
2
+ # Work in progress
3
+ class HP < Base
4
+ def initialize(host, credentials, verbose = false)
5
+ super
6
+ @transport.default_prompt = /(Press any key to continue|# )/
7
+
8
+ # hpuifilter.c used by rancid - https://github.com/dotwaffle/rancid-git/blob/master/bin/hpuifilter.c#L534
9
+ @transport.filter = Proc.new do |line|
10
+ line.gsub(/\e\[2K|\e\[2J|\e\[\?7l|\e\[\?6l|\e\[[0-9]+;[0-9]+r|\e\[[0-9]+;[0-9]+H|\e\[\?25l|\e\[\?25h/, "")
11
+ .gsub(/\eE/, "\n")
12
+ end
13
+ end
14
+
15
+ def connect
16
+ @transport.connect
17
+ @transport.command("\n")
18
+ @transport.command("terminal length 1000")
19
+ end
20
+
21
+ def enable
22
+
23
+ end
24
+
25
+ def configuration
26
+ execute('write term')
27
+ end
28
+
29
+ def save
30
+ execute('write memory')
31
+ end
32
+
33
+ def disconnect
34
+ @transport.send 'exit'
35
+ @transport.close
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ module Commutateurs
2
+ class Juniper < Base
3
+ def initialize(host, credentials, verbose = false)
4
+ super
5
+ @transport.default_prompt = /-> $/
6
+ end
7
+
8
+ def enable
9
+ end
10
+
11
+ def connect
12
+ @transport.connect
13
+ end
14
+
15
+ def configuration
16
+ execute('get config')
17
+ end
18
+
19
+ def save
20
+ end
21
+
22
+ def disconnect
23
+ @transport.send 'exit'
24
+ @transport.close
25
+ end
26
+ end
27
+ end
@@ -3,12 +3,12 @@
3
3
  module Commutateurs
4
4
  class Ssh
5
5
  attr_accessor :user, :password, :host, :port
6
- attr_accessor :default_prompt, :timeout, :debug
6
+ attr_accessor :default_prompt, :timeout, :filter
7
7
 
8
8
  def initialize(verbose)
9
9
  @timeout = 10
10
10
  @verbose = verbose
11
- @debug = Proc.new { |line| $stderr.print(line) }
11
+ @filter = Proc.new { |line| line }
12
12
  end
13
13
 
14
14
  def command(cmd, options = {})
@@ -34,11 +34,16 @@ module Commutateurs
34
34
  raise "failed to open ssh shell channel" unless success
35
35
 
36
36
  ch.on_data { |ch,data|
37
- # p data
38
- @debug.call(data) if @verbose
39
- @buf << data
37
+ # p @filter.call(data)
38
+ $stderr.puts(@filter.call(data)) if @verbose
39
+ @buf << @filter.call(data)
40
+ }
41
+ ch.on_extended_data { |ch,type,data|
42
+ if type == 1
43
+ $stderr.puts(@filter.call(data)) if @verbose
44
+ @buf << @filter.call(data)
45
+ end
40
46
  }
41
- ch.on_extended_data { |ch,type,data| @debug.call(data) if type == 1; @buf << data if type == 1 }
42
47
  ch.on_close { @eof = true }
43
48
 
44
49
  @channel = ch
@@ -109,4 +114,4 @@ module Commutateurs
109
114
  end
110
115
  end
111
116
  end
112
- end
117
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commutateurs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Rose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-16 00:00:00.000000000 Z
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -30,7 +30,13 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - lib/commutateurs/device.rb
33
+ - lib/commutateurs/base.rb
34
+ - lib/commutateurs/cisco.rb
35
+ - lib/commutateurs/credentials.rb
36
+ - lib/commutateurs/fortigate.rb
37
+ - lib/commutateurs/h3c.rb
38
+ - lib/commutateurs/hp.rb
39
+ - lib/commutateurs/juniper.rb
34
40
  - lib/commutateurs/ssh.rb
35
41
  - lib/commutateurs.rb
36
42
  homepage: http://www.github.com/guillaumerose/commutateurs
@@ -1,181 +0,0 @@
1
- module Commutateurs
2
- class Credentials
3
- attr_reader :user, :password, :enable
4
- def initialize(user, password, enable)
5
- @user = user
6
- @password = password
7
- @enable = enable
8
- end
9
- end
10
-
11
- class Base
12
- def initialize(host, credentials, verbose = false)
13
- @enable = credentials.enable
14
-
15
- @transport = Ssh.new(verbose)
16
- @transport.host = host
17
- @transport.user = credentials.user
18
- @transport.password = credentials.password
19
- end
20
-
21
- def execute(line)
22
- @transport.command line
23
- end
24
- end
25
-
26
- # Work in progress
27
- class HP < Base
28
- def initialize(host, credentials, verbose = false)
29
- super
30
- @transport.default_prompt = /(Press any key to continue|# )/
31
- @transport.debug = Proc.new { |line| $stderr.print(clean(line)) }
32
- end
33
-
34
- def connect
35
- @transport.connect
36
- @transport.command("\n")
37
- @transport.command("terminal length 1000")
38
- end
39
-
40
- def enable
41
-
42
- end
43
-
44
- def configuration
45
- execute('write term')
46
- end
47
-
48
- def save
49
- raise "Not implemented yet"
50
- end
51
-
52
- def disconnect
53
- @transport.send 'exit'
54
- @transport.close
55
- end
56
-
57
- def execute(arg)
58
- clean(super(arg))
59
- end
60
-
61
- def clean(arg)
62
- cleaned = ""
63
- (arg || "").each_byte { |x| cleaned << x unless x > 127 }
64
- cleaned
65
- end
66
- end
67
-
68
- class Cisco < Base
69
- def initialize(host, credentials, verbose = false)
70
- super
71
- @transport.default_prompt = /[#>]\s?\z/n
72
- end
73
-
74
- def enable
75
- @transport.command("enable", :prompt => /^Password:/)
76
- @transport.command(@enable)
77
- end
78
-
79
- def connect
80
- @transport.connect
81
- @transport.command('terminal length 0')
82
- end
83
-
84
- def configuration
85
- execute('show run')
86
- end
87
-
88
- def save
89
- execute('wr mem')
90
- end
91
-
92
- def disconnect
93
- @transport.send 'exit'
94
- @transport.close
95
- end
96
- end
97
-
98
- class H3c < Base
99
- def initialize(host, credentials, verbose = false)
100
- super
101
- @transport.default_prompt = /(<.*>|\[.*\])$/
102
- end
103
-
104
- def enable
105
- @transport.command('super', :prompt => /Password:/)
106
- @transport.command(@enable)
107
- @transport.command('screen-length disable')
108
- end
109
-
110
- def connect
111
- @transport.connect
112
- end
113
-
114
- def configuration
115
- execute('dis curr')
116
- end
117
-
118
- def save
119
- @transport.command('save safely', :prompt => /Are you sure/)
120
- @transport.command('Y', :prompt => /enter key/)
121
- @transport.command('')
122
- end
123
-
124
- def disconnect
125
- @transport.send 'quit'
126
- @transport.close
127
- end
128
- end
129
-
130
- class Juniper < Base
131
- def initialize(host, credentials, verbose = false)
132
- super
133
- @transport.default_prompt = /-> $/
134
- end
135
-
136
- def enable
137
- end
138
-
139
- def connect
140
- @transport.connect
141
- end
142
-
143
- def configuration
144
- execute('get config')
145
- end
146
-
147
- def save
148
- end
149
-
150
- def disconnect
151
- @transport.send 'exit'
152
- @transport.close
153
- end
154
- end
155
-
156
- class Fortigate < Base
157
- def initialize(host, credentials, verbose = false)
158
- super
159
- @transport.default_prompt = / [#\$] $/
160
- end
161
-
162
- def enable
163
- end
164
-
165
- def connect
166
- @transport.connect
167
- end
168
-
169
- def configuration
170
- execute('show')
171
- end
172
-
173
- def save
174
- end
175
-
176
- def disconnect
177
- @transport.send 'exit'
178
- @transport.close
179
- end
180
- end
181
- end