network-utility 1.1.30 → 1.1.31

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/network.rb +1 -1
  3. metadata +1 -2
  4. data/document/config.md +0 -1374
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76df9b9cedac6e23575d726c35bd8b4af04a259e4a3b9ddf8350d95755bb8241
4
- data.tar.gz: 15dab7c453a86eacce87a525383f53f8a0fc0ab49b1d8309742fd3d57f3432c9
3
+ metadata.gz: d67830b489eab09e942e1a5a397070883ca32dfa28645c9d6e68a54a1d25744d
4
+ data.tar.gz: e5d6c8aeba4b0d8ecd59cab95618c656539fb2345c15226a8d211044162bb370
5
5
  SHA512:
6
- metadata.gz: 7c275d86741c490a05fd7f14e4692bc9eb6f64fa40c69bfcf688c611d848c93236e8c5fbdcd99325ecd3e758e18ffee2d41931760635ce03658876292467df2e
7
- data.tar.gz: fd78a82529aa6e046e6fa610e664db2981a9d96752c5785d8bf0e6d1ac97ecb8a7a6fc99b3bbea1e21323bbc09f98544b65b70e8d345672f1e52756c77a5be24
6
+ metadata.gz: e1f8a7f4f04140f05a124266b8608c7b882185ab0a5844eb2bff3d4f8f65a308717b704fcdb69acfa73a302cedacad5c1b6db2855d3459cb778898879885c636
7
+ data.tar.gz: e766755b97078351dd5bb4f31ea778fe4d9142cb898f1dcd414f79e14535cc46075f03a44be5836687e22d6dd91f2ed4c6591ee9a6e5b8da3891ba1d20829e18
data/network.rb CHANGED
@@ -22,5 +22,5 @@
22
22
  ].each{|mod|require mod}
23
23
 
24
24
  module Network
25
- VERSION = '1.1.30'
25
+ VERSION = '1.1.31'
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network-utility
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.30
4
+ version: 1.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt
@@ -81,7 +81,6 @@ files:
81
81
  - document/bgp-NE5000E-X16.md
82
82
  - document/bgp-NE5000E-X16A.md
83
83
  - document/bgp-NE80E.md
84
- - document/config.md
85
84
  - document/document.rb
86
85
  - document/if-ALCATEL7750.md
87
86
  - document/if-C7609.md
data/document/config.md DELETED
@@ -1,1374 +0,0 @@
1
-
2
- # 配置文档解析
3
-
4
- ## Alcatel
5
-
6
- ```ruby
7
- @sign << ['ALCATEL7750', '配置解析']
8
-
9
- module ALCATEL7750
10
- module_function
11
-
12
- def 配置解析 raw
13
- conf = {}; name = nil; temp = []
14
- raw.split("\n").each do|line|
15
- if line[0..4]=='echo '
16
- conf[name] = temp
17
- temp = []
18
- name = line.split('"')[1]
19
- conf[name] = ''
20
- elsif line.include?('#--------------------------------------------------')
21
- next
22
- else
23
- temp << line
24
- end
25
- end
26
- conf[name] = temp
27
- conf.delete(nil)
28
- return conf
29
- end
30
- end
31
- ```
32
-
33
- ```ruby
34
- @sign << ['Nokia7750', '配置解析']
35
-
36
- module Nokia7750
37
- module_function
38
-
39
- def 配置解析 raw
40
- conf = {}; name = nil; temp = []
41
- raw.split("\n").each do|line|
42
- if line[0..4]=='echo '
43
- conf[name] = temp
44
- temp = []
45
- name = line.split('"')[1]
46
- conf[name] = ''
47
- elsif line.include?('#--------------------------------------------------')
48
- next
49
- else
50
- temp << line
51
- end
52
- end
53
- conf[name] = temp
54
- conf.delete(nil)
55
- return conf
56
- end
57
- end
58
- ```
59
-
60
- ## 思科
61
-
62
- ```ruby
63
- @sign << ['C7609', '配置解析']
64
-
65
- module C7609
66
- module_function
67
-
68
- def 配置解析 raw
69
- conf = {}; name = nil; temp = []
70
- return conf
71
- end
72
- end
73
- ```
74
-
75
- ```ruby
76
- @sign << ['CRS-16', '配置解析']
77
-
78
- module CRS_16
79
- module_function
80
-
81
- def 配置解析 raw, *guards
82
- config = {}
83
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
84
- prepart = raw.split("show running-config")[1]
85
- return {} unless prepart
86
- content = prepart.split("\nend\n")[0]
87
- config, pretent = {}, content
88
- while pretent.include?("!\n!"); pretent = pretent.gsub("!\n!","!") end
89
- pieces = pretent.split("\n!\n").select{|pc|pc.strip != ''}
90
- pieces.each do|piece|
91
- tag = piece.split("\n")[0].split(" ")[0]
92
- (config[tag] ||= []) << piece
93
- end
94
- return config
95
- end
96
- end
97
- ```
98
-
99
- ## 华为
100
-
101
- ```ruby
102
- @sign << ['CX600-X8A', '配置解析']
103
- @sign << ['CX600-X8A', '主机名']
104
-
105
- module CX600_X8A
106
- module_function
107
-
108
- def 配置解析 braw,*guards
109
- raw = braw
110
- begin
111
- raw.split("\n")
112
- rescue
113
- begin
114
- raw = braw.force_encoding('GBK').encode('UTF-8')
115
- rescue
116
- raw = braw.force_encoding('ASCII-8BIT')
117
- end
118
- end
119
- cfg = {}
120
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
121
- # prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
122
- # return cfg unless prepart
123
- content = raw#prepart.split(/<#{hostname}>( )*\n/)[0]
124
- pretent = "\n"+content
125
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
126
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
127
- pieces.each do|piece|
128
- tag = piece.split("\n")[0].split(" ")[0]
129
- (cfg[tag] ||= []) << piece
130
- end
131
- return cfg
132
- end
133
-
134
- def 主机名 config
135
- config['sysname'].first.to_s.split(' ')[1]
136
- end
137
- end
138
- ```
139
-
140
- ```ruby
141
- @sign << ['CX600-X16A', '配置解析']
142
- @sign << ['CX600-X16A', '主机名']
143
-
144
- module CX600_X16A
145
- module_function
146
-
147
- def 配置解析 braw,*guards
148
- raw = braw
149
- begin
150
- raw.split("\n")
151
- rescue
152
- begin
153
- raw = braw.force_encoding('GBK').encode('UTF-8')
154
- rescue
155
- raw = braw.force_encoding('ASCII-8BIT')
156
- end
157
- end
158
- cfg = {}
159
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
160
- # prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
161
- # return cfg unless prepart
162
- content = raw#prepart.split(/<#{hostname}>( )*\n/)[0]
163
- pretent = "\n"+content
164
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
165
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
166
- pieces.each do|piece|
167
- tag = piece.split("\n")[0].split(" ")[0]
168
- (cfg[tag] ||= []) << piece
169
- end
170
- return cfg
171
- end
172
-
173
- def 主机名 config
174
- config['sysname'].first.to_s.split(' ')[1]
175
- end
176
- end
177
- ```
178
-
179
- ```ruby
180
- @sign << ['MA5200G-8', '配置解析']
181
- @sign << ['MA5200G-8', '主机名 ']
182
-
183
- module MA5200G_8
184
- module_function
185
-
186
- def 配置解析 braw,*guards
187
- raw = braw
188
- begin
189
- raw.split("\n")
190
- rescue
191
- begin
192
- raw = braw.force_encoding('GBK').encode('UTF-8')
193
- rescue
194
- raw = braw.force_encoding('ASCII-8BIT')
195
- end
196
- end
197
- cfg = {}
198
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
199
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
200
- return cfg unless prepart
201
- content = prepart.split(/<#{hostname}>( )*\n/)[0]
202
- pretent = "\n"+content
203
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
204
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
205
- pieces.each do|piece|
206
- tag = piece.split("\n")[0].split(" ")[0]
207
- (cfg[tag] ||= []) << piece
208
- end
209
- return cfg
210
- end
211
-
212
- def 主机名 config
213
- config['sysname'].first.to_s.split(' ')[1]
214
- end
215
- end
216
- ```
217
-
218
- ```ruby
219
- @sign << ['NE40E', '配置解析']
220
- @sign << ['NE40E', '主机名 ']
221
-
222
- module NE40E
223
- module_function
224
-
225
- def 配置解析 raw,*guards
226
- cfg = {}
227
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
228
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
229
- return cfg unless prepart
230
- content = prepart.split(/<#{hostname}>( )*\n/)[0]
231
- pretent = "\n"+content
232
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
233
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
234
- pieces.each do|piece|
235
- tag = piece.split("\n")[0].split(" ")[0]
236
- (cfg[tag] ||= []) << piece
237
- end
238
- return cfg
239
- end
240
-
241
- def 主机名 config
242
- config['sysname'].first.to_s.split(' ')[1]
243
- end
244
- end
245
- ```
246
-
247
- ```ruby
248
- @sign << ['NE80E', '配置解析']
249
- @sign << ['NE80E', '主机名 ']
250
-
251
- module NE80E
252
- module_function
253
-
254
- def 配置解析 raw,*guards
255
- cfg = {}
256
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
257
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
258
- return cfg unless prepart
259
- content = prepart.split(/<#{hostname}>( )*\n/)[0]
260
- pretent = "\n"+content
261
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
262
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
263
- pieces.each do|piece|
264
- tag = piece.split("\n")[0].split(" ")[0]
265
- (cfg[tag] ||= []) << piece
266
- end
267
- return cfg
268
- end
269
-
270
- def 主机名 config
271
- config['sysname'].first.to_s.split(' ')[1]
272
- end
273
-
274
- end
275
- ```
276
-
277
- ```ruby
278
- @sign << ['ME60-16', '配置解析']
279
- @sign << ['ME60-16', '主机名 ']
280
-
281
- module ME60_16
282
- module_function
283
-
284
- def 配置解析 braw,*guards
285
- raw = braw
286
- begin
287
- raw.split("\n")
288
- rescue
289
- begin
290
- raw = braw.force_encoding('GBK').encode('UTF-8')
291
- rescue
292
- raw = braw.force_encoding('ASCII-8BIT')
293
- end
294
- end
295
- cfg = {}
296
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
297
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
298
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
299
- return cfg unless prepart
300
- content = prepart.split(/<#{hostname}>( )*/)[0]
301
- content = prepart.split("\nreturn")[0] unless content
302
- pretent = "\n"+content
303
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
304
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
305
- pieces.each do|piece|
306
- tag = piece.split("\n")[0].split(" ")[0]
307
- (cfg[tag] ||= []) << piece
308
- end
309
- return cfg
310
- end
311
-
312
- def 主机名 config
313
- config['sysname'].first.to_s.split(' ')[1]
314
- end
315
- end
316
- ```
317
-
318
- ```ruby
319
- @sign << ['ME60-X16', '配置解析']
320
- @sign << ['ME60-X16', '主机名 ']
321
-
322
- module ME60_X16
323
- module_function
324
-
325
- def 配置解析 braw,*guards
326
- raw = braw
327
- begin
328
- raw.split("\n")
329
- rescue
330
- begin
331
- raw = braw.force_encoding('GBK').encode('UTF-8')
332
- rescue
333
- raw = braw.force_encoding('ASCII-8BIT')
334
- end
335
- end
336
- cfg = {}
337
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
338
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
339
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
340
- return cfg unless prepart
341
- content = prepart.split(/<#{hostname}>( )*/)[0]
342
- content = prepart.split("\nreturn")[0] unless content
343
- pretent = "\n"+content
344
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
345
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
346
- pieces.each do|piece|
347
- tag = piece.split("\n")[0].split(" ")[0]
348
- (cfg[tag] ||= []) << piece
349
- end
350
- return cfg
351
- end
352
-
353
- def 主机名 config
354
- config['sysname'].first.to_s.split(' ')[1]
355
- end
356
- end
357
- ```
358
-
359
- ```ruby
360
- @sign << ['NE40E-X8', '配置解析']
361
- @sign << ['NE40E-X8', '主机名 ']
362
-
363
- module NE40E_X8
364
- module_function
365
-
366
- def 配置解析 braw,*guards
367
- raw = braw
368
- begin
369
- raw.split("\n")
370
- rescue
371
- begin
372
- raw = braw.force_encoding('GBK').encode('UTF-8')
373
- rescue
374
- raw = braw.force_encoding('ASCII-8BIT')
375
- end
376
- end
377
- cfg = {}
378
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
379
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
380
- return cfg unless prepart
381
- content = prepart.split(/<#{hostname}>( )*\n/)[0]
382
- pretent = "\n"+content
383
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
384
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
385
- pieces.each do|piece|
386
- tag = piece.split("\n")[0].split(" ")[0]
387
- (cfg[tag] ||= []) << piece
388
- end
389
- return cfg
390
- end
391
-
392
- def 主机名 config
393
- config['sysname'].first.to_s.split(' ')[1]
394
- end
395
- end
396
- ```
397
-
398
- ```ruby
399
- @sign << ['NE40E-X16', '配置解析']
400
- @sign << ['NE40E-X16', '主机名 ']
401
-
402
- module NE40E_X16
403
- module_function
404
-
405
- def 配置解析 braw,*guards
406
- raw = braw
407
- begin
408
- raw.split("\n")
409
- rescue
410
- begin
411
- raw = braw.force_encoding('GBK').encode('UTF-8')
412
- rescue
413
- raw = braw.force_encoding('ASCII-8BIT')
414
- end
415
- end
416
- cfg = {}
417
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
418
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
419
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
420
- return cfg unless prepart
421
- content = prepart.split(/<#{hostname}>( )*/)[0]
422
- content = prepart.split("\nreturn")[0] unless content
423
- pretent = "\n"+content
424
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
425
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
426
- pieces.each do|piece|
427
- tag = piece.split("\n")[0].split(" ")[0]
428
- (cfg[tag] ||= []) << piece
429
- end
430
- return cfg
431
- end
432
-
433
- def 主机名 config
434
- config['sysname'].first.to_s.split(' ')[1]
435
- end
436
- end
437
- ```
438
-
439
- ```ruby
440
- @sign << ['NE40E-X16A', '配置解析']
441
- @sign << ['NE40E-X16A', '主机名 ']
442
-
443
- module NE40E_X16A
444
- module_function
445
-
446
- def 配置解析 braw,*guards
447
- raw = braw
448
- begin
449
- raw.split("\n")
450
- rescue
451
- begin
452
- raw = braw.force_encoding('GBK').encode('UTF-8')
453
- rescue
454
- raw = braw.force_encoding('ASCII-8BIT')
455
- end
456
- end
457
- cfg = {}
458
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
459
- prepart = raw.split("display current-configuration\n").select{|part|!part.include?('>>>>')}
460
- return cfg if prepart.empty?
461
- content = prepart.join.split("\nreturn\n").first
462
- pretent = "\n"+content
463
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
464
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
465
- pieces.each do|piece|
466
- tag = piece.split("\n")[0].split(" ")[0]
467
- (cfg[tag] ||= []) << piece
468
- end
469
- return cfg
470
- end
471
-
472
- def 主机名 config
473
- config['sysname'].first.to_s.split(' ')[1]
474
- end
475
-
476
- end
477
- ```
478
-
479
- ```ruby
480
- @sign << ['NE5000E-X16', '配置解析']
481
- @sign << ['NE5000E-X16', '主机名 ']
482
-
483
- module NE5000E_X16
484
- module_function
485
-
486
- def 配置解析 braw,*guards
487
- raw = braw
488
- begin
489
- raw.split("\n")
490
- rescue
491
- begin
492
- raw = braw.force_encoding('GBK').encode('UTF-8')
493
- rescue
494
- raw = braw.force_encoding('ASCII-8BIT')
495
- end
496
- end
497
- cfg = {}
498
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
499
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
500
- return cfg unless prepart
501
- content = prepart.split(/<#{hostname}>( )*\n/)[0]
502
- pretent = "\n"+content
503
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
504
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
505
- pieces.each do|piece|
506
- tag = piece.split("\n")[0].split(" ")[0]
507
- (cfg[tag] ||= []) << piece
508
- end
509
- return cfg
510
- end
511
-
512
- def 主机名 config
513
- config['sysname'].first.to_s.split(' ')[1]
514
- end
515
-
516
- end
517
- ```
518
-
519
- ```ruby
520
- @sign << ['NE5000E-X16A', '配置解析']
521
- @sign << ['NE5000E-X16A', '主机名 ']
522
-
523
- module NE5000E_X16A
524
- module_function
525
-
526
- def 配置解析 braw,*guards
527
- raw = braw
528
- begin
529
- raw.split("\n")
530
- rescue
531
- begin
532
- raw = braw.force_encoding('GBK').encode('UTF-8')
533
- rescue
534
- raw = braw.force_encoding('ASCII-8BIT')
535
- end
536
- end
537
- cfg = {}
538
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
539
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
540
- return cfg unless prepart
541
- content = prepart.split(/<#{hostname}>( )*\n/)[0]
542
- pretent = "\n"+content
543
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
544
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
545
- pieces.each do|piece|
546
- tag = piece.split("\n")[0].split(" ")[0]
547
- (cfg[tag] ||= []) << piece
548
- end
549
- return cfg
550
- end
551
-
552
- def 主机名 config
553
- config['sysname'].first.to_s.split(' ')[1]
554
- end
555
- end
556
- ```
557
-
558
- ```ruby
559
- @sign << ['NE5000E-20', '配置解析']
560
- @sign << ['NE5000E-20', '主机名 ']
561
-
562
- module NE5000E_20
563
- module_function
564
-
565
- def 配置解析 braw,*guards
566
- raw = braw
567
- begin
568
- raw.split("\n")
569
- rescue
570
- begin
571
- raw = braw.force_encoding('GBK').encode('UTF-8')
572
- rescue
573
- raw = braw.force_encoding('ASCII-8BIT')
574
- end
575
- end
576
- cfg = {}
577
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
578
- if raw.include?("<#{hostname}>\ndisplay current-configuration\n")
579
- pretent = raw.split("display current-configuration")[1].split("\nreturn")[0]
580
- else
581
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
582
- return cfg unless prepart
583
- content = prepart.split(/<#{hostname}>( )*\n/)[0]
584
- pretent = "\n"+content
585
- end
586
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
587
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
588
- pieces.each do|piece|
589
- tag = piece.split("\n")[0].split(" ")[0]
590
- (cfg[tag] ||= []) << piece
591
- end
592
- return cfg
593
- end
594
-
595
- def 主机名 config
596
- config['sysname'].first.to_s.split(' ')[1]
597
- end
598
-
599
- end
600
- ```
601
-
602
- ```ruby
603
- @sign << ['NE8000E-X8', '配置解析']
604
- @sign << ['NE8000E-X8', '主机名 ']
605
-
606
- module NE8000E_X8
607
- module_function
608
-
609
- def 配置解析 braw,*guards
610
- raw = braw
611
- begin
612
- raw.split("\n")
613
- rescue
614
- begin
615
- raw = braw.force_encoding('GBK').encode('UTF-8')
616
- rescue
617
- raw = braw.force_encoding('ASCII-8BIT')
618
- end
619
- end
620
- cfg = {}
621
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
622
- # prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
623
- # return cfg unless prepart
624
- content = raw#prepart.split(/<#{hostname}>( )*\n/)[0]
625
- pretent = "\n"+content
626
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
627
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
628
- pieces.each do|piece|
629
- tag = piece.split("\n")[0].split(" ")[0]
630
- (cfg[tag] ||= []) << piece
631
- end
632
- return cfg
633
- end
634
-
635
- def 主机名 config
636
- config['sysname'].first.to_s.split(' ')[1]
637
- end
638
- end
639
- ```
640
-
641
- ```ruby
642
- @sign << ['NE8100-X8', '配置解析']
643
- @sign << ['NE8100-X8', '主机名 ']
644
-
645
- module NE8100_X8
646
- module_function
647
-
648
- def 配置解析 braw,*guards
649
- raw = braw
650
- begin
651
- raw.split("\n")
652
- rescue
653
- begin
654
- raw = braw.force_encoding('GBK').encode('UTF-8')
655
- rescue
656
- raw = braw.force_encoding('ASCII-8BIT')
657
- end
658
- end
659
- cfg = {}
660
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
661
- # prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
662
- # return cfg unless prepart
663
- content = raw#prepart.split(/<#{hostname}>( )*\n/)[0]
664
- pretent = "\n"+content
665
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
666
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
667
- pieces.each do|piece|
668
- tag = piece.split("\n")[0].split(" ")[0]
669
- (cfg[tag] ||= []) << piece
670
- end
671
- return cfg
672
- end
673
-
674
- def 主机名 config
675
- config['sysname'].first.to_s.split(' ')[1]
676
- end
677
-
678
- end
679
- ```
680
-
681
- ```ruby
682
- @sign << ['VNE9000', '配置解析']
683
- @sign << ['VNE9000', '主机名 ']
684
-
685
- module VNE9000
686
- module_function
687
-
688
- def 配置解析 braw,*guards
689
- raw = braw
690
- begin
691
- raw.split("\n")
692
- rescue
693
- begin
694
- raw = braw.force_encoding('GBK').encode('UTF-8')
695
- rescue
696
- raw = braw.force_encoding('ASCII-8BIT')
697
- end
698
- end
699
- cfg = {}
700
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
701
- # prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
702
- # return cfg unless prepart
703
- content = raw#prepart.split(/<#{hostname}>( )*\n/)[0]
704
- pretent = "\n"+content
705
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
706
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
707
- pieces.each do|piece|
708
- tag = piece.split("\n")[0].split(" ")[0]
709
- (cfg[tag] ||= []) << piece
710
- end
711
- return cfg
712
- end
713
-
714
- def 主机名 config
715
- config['sysname'].first.to_s.split(' ')[1]
716
- end
717
- end
718
- ```
719
-
720
- ## 中兴
721
-
722
- ```ruby
723
- @sign << ['M6000', '配置解析']
724
- @sign << ['M6000', '主机名']
725
-
726
- module M6000
727
- module_function
728
-
729
- # Fix a special bug when naming as a tag
730
- def preprocess raw
731
- new_raw = []
732
- raw.split("\n").each do|line|
733
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
734
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
735
- else
736
- new_raw << line
737
- end
738
- end
739
- return new_raw.join("\n")
740
- end
741
-
742
- def connect preline, postline
743
- connect = ' '
744
- connect = '' if preline.include?('ip-host')
745
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
746
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
747
- return connect
748
- end
749
-
750
- def 配置解析 raw,*guards
751
- cfg = {}
752
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
753
- # prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
754
- # return cfg unless prepart
755
- newraw = [""]; flag = false
756
- raw.split("\n").each_with_index do|line,index|
757
- if flag && line[0..1]!='!<'
758
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) +line
759
- else
760
- newraw << line
761
- end
762
- flag = line.size==80
763
- end
764
- raw = newraw.join("\n")
765
- content = self.preprocess(raw)#prepart.split(/#{hostname}#( )*\n/)[0]
766
-
767
- begin
768
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
769
- cfg[element.name] = element.attributes[:text]
770
- end
771
- #rescue
772
- end
773
- cfg
774
- end
775
-
776
- def 主机名 config
777
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
778
- end
779
- end
780
- ```
781
-
782
- ```ruby
783
- @sign << ['M6000-8', '配置解析']
784
- @sign << ['M6000-8', '主机名']
785
-
786
- module M6000_8
787
- module_function
788
-
789
- # Fix a special bug when naming as a tag
790
- def preprocess raw
791
- new_raw = []
792
- raw.split("\n").each do|line|
793
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
794
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
795
- else
796
- new_raw << line
797
- end
798
- end
799
- return new_raw.join("\n")
800
- end
801
-
802
- def connect preline, postline
803
- connect = ' '
804
- connect = '' if preline.include?('ip-host')
805
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
806
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
807
- return connect
808
- end
809
-
810
- def 配置解析 raw,*guards
811
- cfg = {}
812
- newraw = [""]; flag = false
813
- raw.split("\n").each_with_index do|line,index|
814
- if flag && line[0..1]!='!<'
815
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) +line
816
- else
817
- newraw << line
818
- end
819
- flag = line.size==80
820
- end
821
- raw = newraw.join("\n")
822
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
823
- prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
824
- return cfg unless prepart
825
- content = prepart.split(/#{hostname}#( )*\n/)[0]
826
- begin
827
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
828
- cfg[element.name] = element.attributes[:text]
829
- end
830
- #rescue
831
- end
832
- cfg
833
- end
834
-
835
- def 主机名 config
836
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
837
- end
838
- end
839
- ```
840
-
841
- ```ruby
842
- @sign << ['M6000-8E', '配置解析']
843
- @sign << ['M6000-8E', '主机名']
844
-
845
- module M6000_8E
846
- module_function
847
-
848
- # Fix a special bug when naming as a tag
849
- def preprocess raw
850
- new_raw = []
851
- raw.split("\n").each do|line|
852
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
853
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
854
- else
855
- new_raw << line
856
- end
857
- end
858
- return new_raw.join("\n")
859
- end
860
-
861
- def connect preline, postline
862
- connect = ' '
863
- connect = '' if preline.include?('ip-host')
864
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
865
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
866
- return connect
867
- end
868
-
869
- def 配置解析 raw,*guards
870
- cfg = {}
871
- newraw = [""]; flag = false
872
- raw.split("\n").each_with_index do|line,index|
873
- if flag && line[0..1]!='!<'
874
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) +line
875
- else
876
- newraw << line
877
- end
878
- flag = line.size==80
879
- end
880
- raw = newraw.join("\n")
881
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
882
- prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
883
- return cfg unless prepart
884
- content = prepart.split(/#{hostname}#( )*\n/)[0]
885
-
886
- begin
887
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
888
- cfg[element.name] = element.attributes[:text]
889
- end
890
- #rescue
891
- end
892
- cfg
893
- end
894
-
895
- def 主机名 config
896
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
897
- end
898
- end
899
- ```
900
-
901
- ```ruby
902
- @sign << ['M6000-16E', '配置解析']
903
- @sign << ['M6000-16E', '主机名']
904
-
905
- module M6000_16E
906
- module_function
907
-
908
- # Fix a special bug when naming as a tag
909
- def preprocess raw
910
- new_raw = []
911
- raw.split("\n").each do|line|
912
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
913
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
914
- else
915
- new_raw << line
916
- end
917
- end
918
- return new_raw.join("\n")
919
- end
920
-
921
- def connect preline, postline
922
- connect = ' '
923
- connect = '' if preline.include?('ip-host')
924
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
925
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
926
- return connect
927
- end
928
-
929
- def 配置解析 raw,*guards
930
- cfg = {}
931
- newraw = [""]; flag = false
932
- raw.split("\n").each_with_index do|line,index|
933
- if flag && line[0..1]!='!<'
934
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) +line
935
- else
936
- newraw << line
937
- end
938
- flag = line.size==80
939
- end
940
- raw = newraw.join("\n")
941
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
942
- prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
943
- prepart = self.preprocess(raw).split("show running-config\n")[1].split("<<<<")[0] unless prepart # ssh >>>>
944
- return cfg unless prepart
945
- content = prepart.split(/#{hostname}#( )*\n/)[0]
946
- begin
947
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
948
- cfg[element.name] = element.attributes[:text]
949
- end
950
- #rescue
951
- end
952
- cfg
953
- end
954
-
955
- def 主机名 config
956
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
957
- end
958
- end
959
- ```
960
-
961
- ```ruby
962
- @sign << ['M6000-18S', '配置解析']
963
- @sign << ['M6000-18S', '主机名']
964
-
965
- module M6000_18S
966
- module_function
967
-
968
- # Fix a special bug when naming as a tag
969
- def preprocess raw
970
- new_raw = []
971
- raw.split("\n").each do|line|
972
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
973
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
974
- else
975
- new_raw << line
976
- end
977
- end
978
- return new_raw.join("\n")
979
- end
980
-
981
- def connect preline, postline
982
- connect = ' '
983
- connect = '' if preline.include?('ip-host')
984
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
985
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
986
- return connect
987
- end
988
-
989
- def 配置解析 raw,*guards
990
- cfg = {}
991
- newraw = [""]; flag = false
992
- raw.split("\n").each_with_index do|line,index|
993
- if flag && line[0..1]!='!<'
994
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
995
- else
996
- newraw << line
997
- end
998
- flag = line.size==80
999
- end
1000
- raw = newraw.join("\n")
1001
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1002
- prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1003
- prepart = self.preprocess(raw).split("show running-config\n")[1].split("<<<<")[0] unless prepart # ssh >>>>
1004
- return cfg unless prepart
1005
- content = prepart.split(/#{hostname}#( )*\n/)[0]
1006
-
1007
- begin
1008
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1009
- cfg[element.name] = element.attributes[:text]
1010
- end
1011
- #rescue
1012
- end
1013
- cfg
1014
- end
1015
-
1016
- def 主机名 config
1017
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1018
- end
1019
- end
1020
- ```
1021
-
1022
- ```ruby
1023
- @sign << ['T8000-18', '配置解析']
1024
- @sign << ['T8000-18', '主机名 ']
1025
-
1026
- module T8000_18
1027
- module_function
1028
-
1029
- # Fix a special bug when naming as a tag
1030
- def preprocess raw
1031
- new_raw = []
1032
- raw.split("\n").each do|line|
1033
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1034
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1035
- else
1036
- new_raw << line
1037
- end
1038
- end
1039
- return new_raw.join("\n")
1040
- end
1041
-
1042
- def connect preline, postline
1043
- connect = ' '
1044
- connect = '' if preline.include?('ip-host')
1045
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1046
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1047
- return connect
1048
- end
1049
-
1050
- def 配置解析 raw,*guards
1051
- cfg = {}
1052
- newraw = []; flag = false
1053
- raw.split("\n").each_with_index do|line,index|
1054
- if flag && line[0..1]!='!<'
1055
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1056
- else
1057
- newraw << line
1058
- end
1059
- flag = line.size==80
1060
- end
1061
- raw = newraw.join("\n")
1062
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1063
- prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1064
- prepart = self.preprocess(raw).split("show running-config\n")[1].split("<<<<")[0] unless prepart # ssh >>>>
1065
- return cfg unless prepart
1066
- content = prepart.split(/#{hostname}#( )*\n/)[0]
1067
-
1068
- begin
1069
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1070
- cfg[element.name] = element.attributes[:text]
1071
- end
1072
- #rescue
1073
- end
1074
- cfg
1075
- end
1076
-
1077
- def 主机名 config
1078
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1079
- end
1080
- end
1081
- ```
1082
-
1083
- ```ruby
1084
- @sign << ['ZXCTN9000-8EA', '配置解析']
1085
- @sign << ['ZXCTN9000-8EA', '主机名 ']
1086
-
1087
- module ZXCTN9000_8EA
1088
- module_function
1089
-
1090
- # Fix a special bug when naming as a tag
1091
- def preprocess raw
1092
- new_raw = []
1093
- raw.split("\n").each do|line|
1094
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1095
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1096
- else
1097
- new_raw << line
1098
- end
1099
- end
1100
- return new_raw.join("\n")
1101
- end
1102
-
1103
- def connect preline, postline
1104
- connect = ' '
1105
- connect = '' if preline.include?('ip-host')
1106
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1107
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1108
- return connect
1109
- end
1110
-
1111
- def 配置解析 raw,*guards
1112
- cfg = {}
1113
- newraw = []; flag = false
1114
- raw.split("\n").each_with_index do|line,index|
1115
- if flag && line[0..1]!='!<'
1116
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1117
- else
1118
- newraw << line
1119
- end
1120
- flag = line.size==80
1121
- end
1122
- raw = newraw.join("\n")
1123
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1124
- # prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1125
- # return cfg unless prepart
1126
- content = self.preprocess(raw)#prepart.split(/#{hostname}#( )*\n/)[0]
1127
-
1128
- begin
1129
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1130
- cfg[element.name] = element.attributes[:text]
1131
- end
1132
- #rescue
1133
- end
1134
- cfg
1135
- end
1136
-
1137
- def 主机名 config
1138
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1139
- end
1140
- end
1141
- ```
1142
-
1143
- ```ruby
1144
- @sign << ['ZXCTN9000-18EA', '配置解析']
1145
- @sign << ['ZXCTN9000-18EA', '主机名 ']
1146
-
1147
- module ZXCTN9000_18EA
1148
- module_function
1149
-
1150
- # Fix a special bug when naming as a tag
1151
- def preprocess raw
1152
- new_raw = []
1153
- raw.split("\n").each do|line|
1154
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1155
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1156
- else
1157
- new_raw << line
1158
- end
1159
- end
1160
- return new_raw.join("\n")
1161
- end
1162
-
1163
- def connect preline, postline
1164
- connect = ' '
1165
- connect = '' if preline.include?('ip-host')
1166
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1167
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1168
- return connect
1169
- end
1170
-
1171
- def 配置解析 raw,*guards
1172
- cfg = {}
1173
- newraw = []; flag = false
1174
- raw.split("\n").each_with_index do|line,index|
1175
- if flag && line[0..1]!='!<'
1176
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1177
- else
1178
- newraw << line
1179
- end
1180
- flag = line.size==80
1181
- end
1182
- raw = newraw.join("\n")
1183
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1184
- # prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1185
- # return cfg unless prepart
1186
- content = self.preprocess(raw)#prepart.split(/#{hostname}#( )*\n/)[0]
1187
-
1188
- begin
1189
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1190
- cfg[element.name] = element.attributes[:text]
1191
- end
1192
- #rescue
1193
- end
1194
- cfg
1195
- end
1196
-
1197
- def 主机名 config
1198
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1199
- end
1200
- end
1201
- ```
1202
-
1203
- ```ruby
1204
- @sign << ['V6000', '配置解析']
1205
- @sign << ['V6000', '主机名 ']
1206
-
1207
- module V6000
1208
- module_function
1209
-
1210
- # Fix a special bug when naming as a tag
1211
- def preprocess raw
1212
- new_raw = []
1213
- raw.split("\n").each do|line|
1214
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1215
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1216
- else
1217
- new_raw << line
1218
- end
1219
- end
1220
- return new_raw.join("\n")
1221
- end
1222
-
1223
- def connect preline, postline
1224
- connect = ' '
1225
- connect = '' if preline.include?('ip-host')
1226
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1227
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1228
- return connect
1229
- end
1230
-
1231
- def 配置解析 raw,*guards
1232
- cfg = {}
1233
- newraw = []; flag = false
1234
- raw.split("\n").each_with_index do|line,index|
1235
- if flag && line[0..1]!='!<'
1236
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1237
- else
1238
- newraw << line
1239
- end
1240
- flag = line.size==80
1241
- end
1242
- raw = newraw.join("\n")
1243
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1244
- # prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1245
- # return cfg unless prepart
1246
- content = self.preprocess(raw)#prepart.split(/#{hostname}#( )*\n/)[0]
1247
-
1248
- begin
1249
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1250
- cfg[element.name] = element.attributes[:text]
1251
- end
1252
- #rescue
1253
- end
1254
- cfg
1255
- end
1256
-
1257
- def 主机名 config
1258
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1259
- end
1260
- end
1261
- ```
1262
-
1263
- ## 华三
1264
-
1265
- ```ruby
1266
- @sign << ['CR16010H-F', '配置解析']
1267
- @sign << ['CR16010H-F', '主机名']
1268
-
1269
- module CR16010H_F
1270
- module_function
1271
-
1272
- def 配置解析 braw,*guards
1273
- raw = braw.gsub("\r","")
1274
- begin
1275
- raw.split("\n")
1276
- rescue
1277
- raw = braw.force_encoding('GBK').encode('UTF-8').gsub("\r","")
1278
- end
1279
- cfg = {}
1280
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
1281
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
1282
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
1283
- return cfg unless prepart
1284
- content = prepart.split(/<#{hostname}>( )*/)[0]
1285
- content = prepart.split("\nreturn")[0] unless content
1286
- pretent = "\n"+content
1287
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
1288
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
1289
- pieces.each do|piece|
1290
- tag = piece.split("\n")[0].split(" ")[0]
1291
- (cfg[tag] ||= []) << piece
1292
- end
1293
- return cfg
1294
- end
1295
-
1296
- def 主机名 config
1297
- config['sysname'].first.to_s.split(' ')[1]
1298
- end
1299
- end
1300
- ```
1301
-
1302
- ```ruby
1303
- @sign << ['CR16018-F', '配置解析']
1304
- @sign << ['CR16018-F', '主机名']
1305
-
1306
- module CR16018_F
1307
- module_function
1308
-
1309
- def 配置解析 braw,*guards
1310
- raw = braw.gsub("\r","")
1311
- begin
1312
- raw.split("\n")
1313
- rescue
1314
- raw = braw.force_encoding('GBK').encode('UTF-8').gsub("\r","")
1315
- end
1316
- cfg = {}
1317
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
1318
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
1319
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
1320
- return cfg unless prepart
1321
- content = prepart.split(/<#{hostname}>( )*/)[0]
1322
- content = prepart.split("\nreturn")[0] unless content
1323
- pretent = "\n"+content
1324
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
1325
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
1326
- pieces.each do|piece|
1327
- tag = piece.split("\n")[0].split(" ")[0]
1328
- (cfg[tag] ||= []) << piece
1329
- end
1330
- return cfg
1331
- end
1332
-
1333
- def 主机名 config
1334
- config['sysname'].first.to_s.split(' ')[1]
1335
- end
1336
- end
1337
- ```
1338
-
1339
- ```ruby
1340
- @sign << ['CR19000-20', '配置解析']
1341
- @sign << ['CR19000-20', '主机名']
1342
-
1343
- module CR19000_20
1344
- module_function
1345
-
1346
- def 配置解析 braw,*guards
1347
- raw = braw.gsub("\r","")
1348
- begin
1349
- raw.split("\n")
1350
- rescue
1351
- raw = braw.force_encoding('GBK').encode('UTF-8').gsub("\r","")
1352
- end
1353
- cfg = {}
1354
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
1355
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
1356
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
1357
- return cfg unless prepart
1358
- content = prepart.split(/<#{hostname}>( )*/)[0]
1359
- content = prepart.split("\nreturn")[0] unless content
1360
- pretent = "\n"+content
1361
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
1362
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
1363
- pieces.each do|piece|
1364
- tag = piece.split("\n")[0].split(" ")[0]
1365
- (cfg[tag] ||= []) << piece
1366
- end
1367
- return cfg
1368
- end
1369
-
1370
- def 主机名 config
1371
- config['sysname'].first.to_s.split(' ')[1]
1372
- end
1373
- end
1374
- ```