aio_elin 0.0.1 → 1.0.0

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/config.rb +32 -32
  3. data/lib/aio/base/toolkit/excel_wps.rb +1 -0
  4. data/lib/aio/base/toolkit/hash.rb +95 -0
  5. data/lib/aio/base/toolkit/myers.rb +161 -0
  6. data/lib/aio/base/toolkit.rb +2 -0
  7. data/lib/aio/core/device/cmd_switch.rb +1 -1
  8. data/lib/aio/core/device/h3c.rb +2 -0
  9. data/lib/aio/core/device/maipu.rb +8 -0
  10. data/lib/aio/core/device/methods.rb +230 -228
  11. data/lib/aio/core/device/parent_device.rb +270 -267
  12. data/lib/aio/core/device_manager.rb +255 -202
  13. data/lib/aio/core/module/cmd.rb +155 -150
  14. data/lib/aio/core/module/compare.rb +39 -0
  15. data/lib/aio/core/module/output_style.rb +2 -0
  16. data/lib/aio/core/module.rb +1 -0
  17. data/lib/aio/core/module_loader.rb +11 -0
  18. data/lib/aio/core/parse/file.rb +12 -14
  19. data/lib/aio/core/parse/parser.rb +99 -87
  20. data/lib/aio/core/parse/parser_machine/has_device_state.rb +42 -42
  21. data/lib/aio/core/parse/parser_machine.rb +44 -44
  22. data/lib/aio/core/text/block.rb +88 -0
  23. data/lib/aio/core/text/compare.rb +109 -0
  24. data/lib/aio/core/text/context.rb +206 -206
  25. data/lib/aio/core/text/line_string.rb +17 -62
  26. data/lib/aio/core/text/match_string_info.rb +73 -0
  27. data/lib/aio/core/text/warning.rb +175 -175
  28. data/lib/aio/core/text.rb +3 -0
  29. data/lib/aio/core/warning/warning_summarize.rb +246 -229
  30. data/lib/aio/core.rb +3 -0
  31. data/lib/aio/ui/logger.rb +38 -0
  32. data/lib/aio/ui/verbose.rb +6 -2
  33. data/lib/aio/ui.rb +135 -134
  34. data/lib/modules/cmd/cisco/show_version.rb +84 -84
  35. data/lib/modules/cmd/h3c/display_cpu.rb +41 -41
  36. data/lib/modules/cmd/h3c/display_version.rb +43 -43
  37. data/lib/modules/cmd/maipu/show_clock.rb +32 -0
  38. data/lib/modules/cmd/maipu/show_cpu.rb +36 -0
  39. data/lib/modules/cmd/maipu/show_ip_interface_brief.rb +44 -0
  40. data/lib/modules/cmd/maipu/show_memory.rb +22 -22
  41. data/lib/modules/cmd/maipu/show_version.rb +40 -40
  42. data/lib/modules/input/style/compare_xml.rb +73 -73
  43. data/lib/modules/output/style/cmds.rb +3 -3
  44. data/lib/modules/output/style/compare_diff.rb +23 -0
  45. data/lib/modules/output/style/excel_table_office.rb +1 -0
  46. data/lib/modules/output/style/excel_table_wps.rb +1 -0
  47. data/lib/modules/output/style/summary_report.rb +2 -1
  48. data/lib/modules/special/style/compare.rb +153 -103
  49. data/lib/modules/special/style/compare_old.rb +121 -0
  50. data/lib/modules/special/style/compare_with_device_manager.rb +227 -0
  51. metadata +16 -3
@@ -1,207 +1,260 @@
1
1
  class Aio::DeviceManager
2
2
 
3
- # 保存所有设备类
4
- # devices = {"device_name" => device_klass}
5
- attr_accessor :devices
6
-
7
- # 按设备型号保存cmd
8
- # cmds = {"device_type" => [module_klass1, module_klass2]}
9
- attr_accessor :cmds
10
-
11
- # 命令的正则表达式匹配
12
- # cmds_reg = {module_klass => ["device_type", "cmd_reg"]}
13
- attr_accessor :cmds_reg
14
-
15
- # 警告信息汇总类
16
- attr_reader :warning_summarize
17
-
18
- # 模块管理信息,只读
19
- attr_accessor :module_manager
20
-
21
- # 当初始化完成,所有cmd模块已经整理完毕
22
- def initialize(module_manager)
23
- self.cmds = {}
24
- self.cmds_reg = {}
25
- self.devices = {}
26
- @module_manager = module_manager
27
- @warning_summarize = Aio::Warning::WarningSummarize.new(self)
28
- tidy_cmds
29
- end
30
-
31
- def []=(key, val)
32
- @devices[key] = val
33
- end
34
-
35
- def [](key)
36
- @devices[key]
37
- end
38
-
39
- # 设备台数
40
- def devices_number
41
- self.devices.keys.size
42
- end
43
-
44
- # 整理cmds 和 cmds_reg
45
- # 返回为Hash = {"cisco" => [klass, klass]}
46
- def tidy_cmds
47
- device_type = @module_manager.get_modules_device_type_to_s
48
-
49
- device_type.each do |type|
50
- # 整理cmds
51
- type_modules = @module_manager.get_modules_by_device_type(type)
52
- self.cmds[type] = type_modules
53
-
54
- # 整理cmds_reg
55
- type_modules.each do |cmd_klass|
56
-
57
- # 将cmd_short转变为正则表达式
58
- # 相同的cmd_short会导致重复
59
- cmd_short_reg = Aio::Base::Toolkit::Regexp.to_reg(cmd_klass.cmd_short)
60
- cmds_reg[cmd_klass] = [type, cmd_short_reg]
61
- end
62
- end
63
- return cmds
64
- end
65
-
66
- # 仅仅返回各个命令的正则表达式的数组,在input/console中使用
67
- def just_cmds_reg
68
- res = []
69
- cmds_reg.each_pair do |klass, info|
70
- res << info[1]
71
- end
72
- return res
73
- end
74
-
75
- def each_devices
76
- devices.each_pair do |device_name, device_klass|
77
- yield device_name, device_klass
78
- end
79
- end
80
-
81
- def each_devices_with_index
82
- i = 0
83
- devices.each_pair do |device_name, device_klass|
84
- yield device_name, device_klass, i
85
- i += 1
86
- end
87
- end
88
-
89
- # 轮询设备名以及有用信息
90
- def each_devices_with_useful
91
- each_devices do |device_name, device_klass|
92
- useful = device_klass.cmds_useful
93
- yield device_name, useful
94
- end
95
- end
96
-
97
- # 判断设备名是否存在
98
- def device_exist?(opts={})
99
- each_devices do |devices, _|
100
- if devices == opts[:device_name]
101
- return true
102
- end
103
- end
104
- return false
105
- end
106
-
107
- # 设备类型分类
108
- # 返回 { "cisco" => [device_name1, ...] }
109
- def device_type_classify
110
- res = {}
111
- each_devices do |device_name, device_klass|
112
- type = device_klass.device_type
113
- unless res.has_key?(type)
114
- res[type] = []
115
- end
116
- res[type] << device_name
117
- end
118
-
119
- return res
120
- end
121
- # 查找是否有符合指定的cmd模块
3
+ # 保存所有设备类
4
+ # devices = {"device_name" => device_klass}
5
+ attr_accessor :devices
6
+
7
+ # 按设备型号保存cmd
8
+ # cmds = {"device_type" => [module_klass1, module_klass2]}
9
+ attr_accessor :cmds
10
+
11
+ # 命令的正则表达式匹配
12
+ # cmds_reg = {module_klass => ["device_type", "cmd_reg"]}
13
+ attr_accessor :cmds_reg
14
+
15
+ # 警告信息汇总类
16
+ attr_reader :warning_summarize
17
+
18
+ # 模块管理信息,只读
19
+ attr_accessor :module_manager
20
+
21
+ # 当初始化完成,所有cmd模块已经整理完毕
22
+ def initialize(module_manager)
23
+ self.cmds = {}
24
+ self.cmds_reg = {}
25
+ self.devices = {}
26
+ @module_manager = module_manager
27
+ @warning_summarize = Aio::Warning::WarningSummarize.new(self)
28
+ tidy_cmds
29
+ end
30
+
31
+ def []=(key, val)
32
+ @devices[key] = val
33
+ end
34
+
35
+ def [](key)
36
+ @devices[key]
37
+ end
38
+
39
+ # 设备台数
40
+ def devices_number
41
+ self.devices.keys.size
42
+ end
43
+
44
+ def inspect
45
+ total = devices_number
46
+ names = []
47
+ each_devices do |name, klass|
48
+ names << name
49
+ end
50
+
51
+ "#<Aio::DeviceManager @device_number: #{total}, @devices_name=#{names.to_s} >"
52
+ end
53
+
54
+ # 整理cmds 和 cmds_reg
55
+ # 返回为Hash = {"cisco" => [klass, klass]}
56
+ def tidy_cmds
57
+ device_type = @module_manager.get_modules_device_type_to_s
58
+
59
+ device_type.each do |type|
60
+ # 整理cmds
61
+ type_modules = @module_manager.get_modules_by_device_type(type)
62
+ self.cmds[type] = type_modules
63
+
64
+ # 整理cmds_reg
65
+ type_modules.each do |cmd_klass|
66
+
67
+ # 将cmd_short转变为正则表达式
68
+ # 相同的cmd_short会导致重复
69
+ cmd_short_reg = Aio::Base::Toolkit::Regexp.to_reg(cmd_klass.cmd_short)
70
+ cmds_reg[cmd_klass] = [type, cmd_short_reg]
71
+ end
72
+ end
73
+ return cmds
74
+ end
75
+
76
+ # 仅仅返回各个命令的正则表达式的数组,在input/console中使用
77
+ def just_cmds_reg
78
+ res = []
79
+ cmds_reg.each_pair do |klass, info|
80
+ res << info[1]
81
+ end
82
+ return res
83
+ end
84
+
85
+ def each_devices
86
+ devices.each_pair do |device_name, device_klass|
87
+ yield device_name, device_klass
88
+ end
89
+ end
90
+
91
+ def each_devices_with_index
92
+ i = 0
93
+ devices.each_pair do |device_name, device_klass|
94
+ yield device_name, device_klass, i
95
+ i += 1
96
+ end
97
+ end
98
+
99
+ # 轮询设备名以及有用信息
100
+ def each_devices_with_useful
101
+ each_devices do |device_name, device_klass|
102
+ useful = device_klass.cmds_useful
103
+ yield device_name, useful
104
+ end
105
+ end
106
+
107
+ # 只返回按照特定的设备,types 为数组
108
+ def each_devices_of(*types)
109
+ each_devices do |name, klass|
110
+ next unless types.include? klass.device_type
111
+ yield klass
112
+ end
113
+ end
114
+
115
+ # 返回只是cisco的设备
116
+ def each_devices_of_cisco
117
+ each_devices do |name, klass|
118
+ next unless klass.device_type == 'cisco'
119
+ yield klass
120
+ end
121
+ end
122
+
123
+ # 返回只是h3c的设备
124
+ def each_devices_of_h3c
125
+ each_devices do |name, klass|
126
+ next unless klass.device_type == 'h3c'
127
+ yield klass
128
+ end
129
+ end
130
+
131
+ # 返回只是maipu的设备
132
+ def each_devices_of_maipu
133
+ each_devices do |name, klass|
134
+ next unless klass.device_type == 'maipu'
135
+ yield klass
136
+ end
137
+ end
138
+
139
+ # 判断设备名是否存在
140
+ def device_exist?(opts={})
141
+ each_devices do |devices, _|
142
+ if devices == opts[:device_name]
143
+ return true
144
+ end
145
+ end
146
+ return false
147
+ end
148
+
149
+ # 设备类型分类
150
+ # 返回 { "cisco" => [device_name1, ...] }
151
+ def device_type_classify
152
+ res = {}
153
+ each_devices do |device_name, device_klass|
154
+ type = device_klass.device_type
155
+ unless res.has_key?(type)
156
+ res[type] = []
157
+ end
158
+ res[type] << device_name
159
+ end
160
+
161
+ return res
162
+ end
163
+ # 查找是否有符合指定的cmd模块
122
164
  # 有可能两种设备类型同时存在同样的命令,在不确定设备类型的情况下,全部输出
123
- # 注意此处输出的样式为 res = [ [device_type, cmd_klass], ... ]
124
- # info = { cmd_klass => [type, cmd_reg] }
125
- def cmd_module_assign(opts)
126
- cmd = opts[:cmd]
127
- res = []
128
-
129
- device_type = opts[:device_type]
130
- cmds_reg.each do |cmd_klass, info|
131
- reg = info[1]
132
- type = info[0]
133
- if reg.match(cmd)
134
-
135
- # 判断如果没有指定device_type,那么全部输出
136
- # 如果指定,则只输出指定类型
137
- if device_type == type
138
- res << [type, cmd_klass]
139
- elsif device_type.nil?
140
- res << [type, cmd_klass]
141
- end
142
-
143
- end
144
- end
145
-
146
- return res.empty? ? nil : res
147
- end
148
-
149
-
150
- # 在状态机中使用了,添加设备,并添加cmd-context
151
- def add_device(opts)
152
-
153
- # 判断是否已经有了device,如果有,则沿用,如果没有则新建
154
- if has_device?(opts)
155
- device_klass = self.devices[opts[:device_name]]
156
- else
157
- device_klass = Aio::Device::ParentDevice.new
158
- device_klass.device_name = opts[:device_name]
159
- end
160
-
161
- # cmd 和 context 必须同时存在的情况下才能加载的
162
- if opts[:cmd] and opts[:context]
163
-
164
- cmd_arr = cmd_module_assign(opts)
165
- if cmd_arr.nil?
166
- device_klass.add_cmd_context_by_cmd_name(
167
- opts[:cmd],
168
- opts[:context]
169
- )
170
- elsif cmd_arr.size == 1
171
- device_klass.add_cmd_context_by_klass(
172
- cmd_arr[0],
173
- opts[:context]
174
- )
175
- else
176
- # 有多个cmd模块的情况,全部依次加进去,但是最后分析的时候,出现明显问题的将被删除
177
- cmd_arr.each do |cmd_klass|
178
- device_klass.add_cmd_context_by_klass(
179
- cmd_klass,
180
- opts[:context]
181
- )
182
- end
183
- end
184
-
185
- end
186
-
187
- self.devices[opts[:device_name]] = device_klass
188
- end
189
-
190
- # 将compare中得到的warning信息合并到各个设备的warning_klass中
191
- def merge_warning(info)
192
- info.each do |name, warn|
193
- self[name].warning_klass.warning_compare(warn)
194
- end
195
- end
196
-
197
- # 整理汇总警告信息
198
- def warning_summarize_tidy
199
- @warning_summarize.tidy_warning
200
- end
201
-
202
- # 是否已经有device_name
203
- def has_device?(opts)
204
- self.devices.has_key?(opts[:device_name])
205
- end
165
+ # 注意此处输出的样式为 res = [ [device_type, cmd_klass], ... ]
166
+ # info = { cmd_klass => [type, cmd_reg] }
167
+ def cmd_module_assign(opts)
168
+ cmd = opts[:cmd]
169
+ res = []
170
+
171
+ device_type = opts[:device_type]
172
+ cmds_reg.each do |cmd_klass, info|
173
+ reg = info[1]
174
+ type = info[0]
175
+ if reg.match(cmd)
176
+
177
+ # 判断如果没有指定device_type,那么全部输出
178
+ # 如果指定,则只输出指定类型
179
+ # cmd_klass 会被覆盖, 已经修复
180
+ if device_type == type
181
+ res << [type, cmd_klass.division]
182
+ elsif device_type.nil?
183
+ res << [type, cmd_klass.division]
184
+ end
185
+
186
+ end
187
+ end
188
+
189
+ return res.empty? ? nil : res
190
+ end
191
+
192
+
193
+ # 在状态机中使用了,添加设备,并添加cmd-context
194
+ def add_device(opts)
195
+
196
+ # 判断是否已经有了device,如果有,则沿用,如果没有则新建
197
+ if has_device?(opts)
198
+ device_klass = self.devices[opts[:device_name]]
199
+ else
200
+ device_klass = Aio::Device::ParentDevice.new
201
+ device_klass.device_name = opts[:device_name]
202
+ end
203
+
204
+ # cmd context 必须同时存在的情况下才能加载的
205
+ if opts[:cmd] and opts[:context]
206
+
207
+ cmd_arr = cmd_module_assign(opts)
208
+ if cmd_arr.nil?
209
+ device_klass.add_cmd_context_by_cmd_name(
210
+ opts[:cmd],
211
+ opts[:context]
212
+ )
213
+ elsif cmd_arr.size == 1
214
+ device_klass.add_cmd_context_by_klass(
215
+ cmd_arr[0],
216
+ opts[:context]
217
+ )
218
+ else
219
+ # 有多个cmd模块的情况,全部依次加进去,但是最后分析的时候,出现明显问题的将被删除
220
+ cmd_arr.each do |cmd_klass|
221
+ device_klass.add_cmd_context_by_klass(
222
+ cmd_klass,
223
+ opts[:context]
224
+ )
225
+ end
226
+ end
227
+
228
+ end
229
+
230
+ self.devices[opts[:device_name]] = device_klass
231
+ end
232
+
233
+ # 将compare中得到的warning信息合并到各个设备的warning_klass中
234
+ def merge_warning(info)
235
+
236
+ # info = {
237
+ # cm1: [ [device_name, cmd, str], .. ],
238
+ # cm2: [ [device_name, cmd, str], .. ]
239
+ # }
240
+ info.each_pair do |key, element|
241
+
242
+ element.each do |e|
243
+ name = e.shift
244
+ # e = [cmd, match_str_info]
245
+ self[name].warning_klass.warning_compare({cm: key, e: e})
246
+ end
247
+ end
248
+ end
249
+
250
+ # 整理汇总警告信息
251
+ def warning_summarize_tidy
252
+ @warning_summarize.tidy_warning
253
+ end
254
+
255
+ # 是否已经有device_name
256
+ def has_device?(opts)
257
+ self.devices.has_key?(opts[:device_name])
258
+ end
206
259
 
207
260
  end