network-utility 1.1.29 → 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 -1372
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de383d07d38127a54118125a871116fffdde68feff561495af35d621cbd6477c
4
- data.tar.gz: 8d8086c0b54c5c2916cf1656455ec2c8db118da31a573d6c97a293adb2bd20aa
3
+ metadata.gz: d67830b489eab09e942e1a5a397070883ca32dfa28645c9d6e68a54a1d25744d
4
+ data.tar.gz: e5d6c8aeba4b0d8ecd59cab95618c656539fb2345c15226a8d211044162bb370
5
5
  SHA512:
6
- metadata.gz: 965d4d24f3879da46c1e4495ba007977b4a28e32b568d5a012158a876d8ec8d81a705316bd0704313bf5376e19d52ff4a6aa222eb5c8e5fa14d7d9e7044f8506
7
- data.tar.gz: a207162c2cf187f66b795ee4254d5c1df16b974a8cebffee328b49c75e361d5a4d33598a0bf3d37cb79bfb3e7bab563011ccd5fc0bb090d5ac2afc551266bb18
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.29'
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.29
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,1372 +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
- return cfg unless prepart
944
- content = prepart.split(/#{hostname}#( )*\n/)[0]
945
- begin
946
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
947
- cfg[element.name] = element.attributes[:text]
948
- end
949
- #rescue
950
- end
951
- cfg
952
- end
953
-
954
- def 主机名 config
955
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
956
- end
957
- end
958
- ```
959
-
960
- ```ruby
961
- @sign << ['M6000-18S', '配置解析']
962
- @sign << ['M6000-18S', '主机名']
963
-
964
- module M6000_18S
965
- module_function
966
-
967
- # Fix a special bug when naming as a tag
968
- def preprocess raw
969
- new_raw = []
970
- raw.split("\n").each do|line|
971
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
972
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
973
- else
974
- new_raw << line
975
- end
976
- end
977
- return new_raw.join("\n")
978
- end
979
-
980
- def connect preline, postline
981
- connect = ' '
982
- connect = '' if preline.include?('ip-host')
983
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
984
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
985
- return connect
986
- end
987
-
988
- def 配置解析 raw,*guards
989
- cfg = {}
990
- newraw = [""]; flag = false
991
- raw.split("\n").each_with_index do|line,index|
992
- if flag && line[0..1]!='!<'
993
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
994
- else
995
- newraw << line
996
- end
997
- flag = line.size==80
998
- end
999
- raw = newraw.join("\n")
1000
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1001
- prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1002
- prepart = self.preprocess(raw).split("show running-config\n")[1].split("<<<<")[0] unless prepart # ssh >>>>
1003
- return cfg unless prepart
1004
- content = prepart.split(/#{hostname}#( )*\n/)[0]
1005
-
1006
- begin
1007
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1008
- cfg[element.name] = element.attributes[:text]
1009
- end
1010
- #rescue
1011
- end
1012
- cfg
1013
- end
1014
-
1015
- def 主机名 config
1016
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1017
- end
1018
- end
1019
- ```
1020
-
1021
- ```ruby
1022
- @sign << ['T8000-18', '配置解析']
1023
- @sign << ['T8000-18', '主机名 ']
1024
-
1025
- module T8000_18
1026
- module_function
1027
-
1028
- # Fix a special bug when naming as a tag
1029
- def preprocess raw
1030
- new_raw = []
1031
- raw.split("\n").each do|line|
1032
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1033
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1034
- else
1035
- new_raw << line
1036
- end
1037
- end
1038
- return new_raw.join("\n")
1039
- end
1040
-
1041
- def connect preline, postline
1042
- connect = ' '
1043
- connect = '' if preline.include?('ip-host')
1044
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1045
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1046
- return connect
1047
- end
1048
-
1049
- def 配置解析 raw,*guards
1050
- cfg = {}
1051
- newraw = []; flag = false
1052
- raw.split("\n").each_with_index do|line,index|
1053
- if flag && line[0..1]!='!<'
1054
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1055
- else
1056
- newraw << line
1057
- end
1058
- flag = line.size==80
1059
- end
1060
- raw = newraw.join("\n")
1061
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1062
- prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1063
- return cfg unless prepart
1064
- content = prepart.split(/#{hostname}#( )*\n/)[0]
1065
-
1066
- begin
1067
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1068
- cfg[element.name] = element.attributes[:text]
1069
- end
1070
- #rescue
1071
- end
1072
- cfg
1073
- end
1074
-
1075
- def 主机名 config
1076
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1077
- end
1078
- end
1079
- ```
1080
-
1081
- ```ruby
1082
- @sign << ['ZXCTN9000-8EA', '配置解析']
1083
- @sign << ['ZXCTN9000-8EA', '主机名 ']
1084
-
1085
- module ZXCTN9000_8EA
1086
- module_function
1087
-
1088
- # Fix a special bug when naming as a tag
1089
- def preprocess raw
1090
- new_raw = []
1091
- raw.split("\n").each do|line|
1092
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1093
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1094
- else
1095
- new_raw << line
1096
- end
1097
- end
1098
- return new_raw.join("\n")
1099
- end
1100
-
1101
- def connect preline, postline
1102
- connect = ' '
1103
- connect = '' if preline.include?('ip-host')
1104
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1105
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1106
- return connect
1107
- end
1108
-
1109
- def 配置解析 raw,*guards
1110
- cfg = {}
1111
- newraw = []; flag = false
1112
- raw.split("\n").each_with_index do|line,index|
1113
- if flag && line[0..1]!='!<'
1114
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1115
- else
1116
- newraw << line
1117
- end
1118
- flag = line.size==80
1119
- end
1120
- raw = newraw.join("\n")
1121
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1122
- # prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1123
- # return cfg unless prepart
1124
- content = self.preprocess(raw)#prepart.split(/#{hostname}#( )*\n/)[0]
1125
-
1126
- begin
1127
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1128
- cfg[element.name] = element.attributes[:text]
1129
- end
1130
- #rescue
1131
- end
1132
- cfg
1133
- end
1134
-
1135
- def 主机名 config
1136
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1137
- end
1138
- end
1139
- ```
1140
-
1141
- ```ruby
1142
- @sign << ['ZXCTN9000-18EA', '配置解析']
1143
- @sign << ['ZXCTN9000-18EA', '主机名 ']
1144
-
1145
- module ZXCTN9000_18EA
1146
- module_function
1147
-
1148
- # Fix a special bug when naming as a tag
1149
- def preprocess raw
1150
- new_raw = []
1151
- raw.split("\n").each do|line|
1152
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1153
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1154
- else
1155
- new_raw << line
1156
- end
1157
- end
1158
- return new_raw.join("\n")
1159
- end
1160
-
1161
- def connect preline, postline
1162
- connect = ' '
1163
- connect = '' if preline.include?('ip-host')
1164
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1165
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1166
- return connect
1167
- end
1168
-
1169
- def 配置解析 raw,*guards
1170
- cfg = {}
1171
- newraw = []; flag = false
1172
- raw.split("\n").each_with_index do|line,index|
1173
- if flag && line[0..1]!='!<'
1174
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1175
- else
1176
- newraw << line
1177
- end
1178
- flag = line.size==80
1179
- end
1180
- raw = newraw.join("\n")
1181
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1182
- # prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1183
- # return cfg unless prepart
1184
- content = self.preprocess(raw)#prepart.split(/#{hostname}#( )*\n/)[0]
1185
-
1186
- begin
1187
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1188
- cfg[element.name] = element.attributes[:text]
1189
- end
1190
- #rescue
1191
- end
1192
- cfg
1193
- end
1194
-
1195
- def 主机名 config
1196
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1197
- end
1198
- end
1199
- ```
1200
-
1201
- ```ruby
1202
- @sign << ['V6000', '配置解析']
1203
- @sign << ['V6000', '主机名 ']
1204
-
1205
- module V6000
1206
- module_function
1207
-
1208
- # Fix a special bug when naming as a tag
1209
- def preprocess raw
1210
- new_raw = []
1211
- raw.split("\n").each do|line|
1212
- if line.include?('<') && line.include?('>') && line[0..1]!='!<'
1213
- new_raw << line.gsub('<',"\&lt\;").gsub('>',"\&gt\;")
1214
- else
1215
- new_raw << line
1216
- end
1217
- end
1218
- return new_raw.join("\n")
1219
- end
1220
-
1221
- def connect preline, postline
1222
- connect = ' '
1223
- connect = '' if preline.include?('ip-host')
1224
- connect = '' if /[\d+|\.|\-|\_]$/.match(preline)
1225
- connect = '' if /^[\d+|\.|\-|\_]/.match(postline)
1226
- return connect
1227
- end
1228
-
1229
- def 配置解析 raw,*guards
1230
- cfg = {}
1231
- newraw = []; flag = false
1232
- raw.split("\n").each_with_index do|line,index|
1233
- if flag && line[0..1]!='!<'
1234
- newraw[-1] = newraw[-1] + connect(newraw[-1],line) + line
1235
- else
1236
- newraw << line
1237
- end
1238
- flag = line.size==80
1239
- end
1240
- raw = newraw.join("\n")
1241
- hostname = guards[0] || self.preprocess(raw).split("\n").find{|line|line.include?("hostname ")}.to_s.split("hostname ")[1]
1242
- # prepart = self.preprocess(raw).split(/#{hostname}#( )*show running-config( )*\n/)[1]
1243
- # return cfg unless prepart
1244
- content = self.preprocess(raw)#prepart.split(/#{hostname}#( )*\n/)[0]
1245
-
1246
- begin
1247
- XmlParser.parse("<root>#{content}</root>").elements.each do|element|
1248
- cfg[element.name] = element.attributes[:text]
1249
- end
1250
- #rescue
1251
- end
1252
- cfg
1253
- end
1254
-
1255
- def 主机名 config
1256
- config['system-config'].to_s.split("\n")[0].split(' ')[1]
1257
- end
1258
- end
1259
- ```
1260
-
1261
- ## 华三
1262
-
1263
- ```ruby
1264
- @sign << ['CR16010H-F', '配置解析']
1265
- @sign << ['CR16010H-F', '主机名']
1266
-
1267
- module CR16010H_F
1268
- module_function
1269
-
1270
- def 配置解析 braw,*guards
1271
- raw = braw.gsub("\r","")
1272
- begin
1273
- raw.split("\n")
1274
- rescue
1275
- raw = braw.force_encoding('GBK').encode('UTF-8').gsub("\r","")
1276
- end
1277
- cfg = {}
1278
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
1279
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
1280
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
1281
- return cfg unless prepart
1282
- content = prepart.split(/<#{hostname}>( )*/)[0]
1283
- content = prepart.split("\nreturn")[0] unless content
1284
- pretent = "\n"+content
1285
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
1286
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
1287
- pieces.each do|piece|
1288
- tag = piece.split("\n")[0].split(" ")[0]
1289
- (cfg[tag] ||= []) << piece
1290
- end
1291
- return cfg
1292
- end
1293
-
1294
- def 主机名 config
1295
- config['sysname'].first.to_s.split(' ')[1]
1296
- end
1297
- end
1298
- ```
1299
-
1300
- ```ruby
1301
- @sign << ['CR16018-F', '配置解析']
1302
- @sign << ['CR16018-F', '主机名']
1303
-
1304
- module CR16018_F
1305
- module_function
1306
-
1307
- def 配置解析 braw,*guards
1308
- raw = braw.gsub("\r","")
1309
- begin
1310
- raw.split("\n")
1311
- rescue
1312
- raw = braw.force_encoding('GBK').encode('UTF-8').gsub("\r","")
1313
- end
1314
- cfg = {}
1315
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
1316
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
1317
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
1318
- return cfg unless prepart
1319
- content = prepart.split(/<#{hostname}>( )*/)[0]
1320
- content = prepart.split("\nreturn")[0] unless content
1321
- pretent = "\n"+content
1322
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
1323
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
1324
- pieces.each do|piece|
1325
- tag = piece.split("\n")[0].split(" ")[0]
1326
- (cfg[tag] ||= []) << piece
1327
- end
1328
- return cfg
1329
- end
1330
-
1331
- def 主机名 config
1332
- config['sysname'].first.to_s.split(' ')[1]
1333
- end
1334
- end
1335
- ```
1336
-
1337
- ```ruby
1338
- @sign << ['CR19000-20', '配置解析']
1339
- @sign << ['CR19000-20', '主机名']
1340
-
1341
- module CR19000_20
1342
- module_function
1343
-
1344
- def 配置解析 braw,*guards
1345
- raw = braw.gsub("\r","")
1346
- begin
1347
- raw.split("\n")
1348
- rescue
1349
- raw = braw.force_encoding('GBK').encode('UTF-8').gsub("\r","")
1350
- end
1351
- cfg = {}
1352
- hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
1353
- prepart = raw.split(/#{hostname}>( )*display current-configuration( )*\n/)[1]
1354
- prepart = raw.split("#{hostname}>display current-configuration\n")[1] unless prepart
1355
- return cfg unless prepart
1356
- content = prepart.split(/<#{hostname}>( )*/)[0]
1357
- content = prepart.split("\nreturn")[0] unless content
1358
- pretent = "\n"+content
1359
- while pretent.include?("\n#\n#"); pretent = pretent.gsub("\n#\n#","\n#") end
1360
- pieces = pretent.split("\n#\n").select{|pc|pc.strip != ''}
1361
- pieces.each do|piece|
1362
- tag = piece.split("\n")[0].split(" ")[0]
1363
- (cfg[tag] ||= []) << piece
1364
- end
1365
- return cfg
1366
- end
1367
-
1368
- def 主机名 config
1369
- config['sysname'].first.to_s.split(' ')[1]
1370
- end
1371
- end
1372
- ```