aio_elin 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config.rb +32 -32
- data/lib/aio/base/toolkit/excel_wps.rb +1 -0
- data/lib/aio/base/toolkit/hash.rb +95 -0
- data/lib/aio/base/toolkit/myers.rb +161 -0
- data/lib/aio/base/toolkit.rb +2 -0
- data/lib/aio/core/device/cmd_switch.rb +1 -1
- data/lib/aio/core/device/h3c.rb +2 -0
- data/lib/aio/core/device/maipu.rb +8 -0
- data/lib/aio/core/device/methods.rb +230 -228
- data/lib/aio/core/device/parent_device.rb +270 -267
- data/lib/aio/core/device_manager.rb +255 -202
- data/lib/aio/core/module/cmd.rb +155 -150
- data/lib/aio/core/module/compare.rb +39 -0
- data/lib/aio/core/module/output_style.rb +2 -0
- data/lib/aio/core/module.rb +1 -0
- data/lib/aio/core/module_loader.rb +11 -0
- data/lib/aio/core/parse/file.rb +12 -14
- data/lib/aio/core/parse/parser.rb +99 -87
- data/lib/aio/core/parse/parser_machine/has_device_state.rb +42 -42
- data/lib/aio/core/parse/parser_machine.rb +44 -44
- data/lib/aio/core/text/block.rb +88 -0
- data/lib/aio/core/text/compare.rb +109 -0
- data/lib/aio/core/text/context.rb +206 -206
- data/lib/aio/core/text/line_string.rb +17 -62
- data/lib/aio/core/text/match_string_info.rb +73 -0
- data/lib/aio/core/text/warning.rb +175 -175
- data/lib/aio/core/text.rb +3 -0
- data/lib/aio/core/warning/warning_summarize.rb +246 -229
- data/lib/aio/core.rb +3 -0
- data/lib/aio/ui/logger.rb +38 -0
- data/lib/aio/ui/verbose.rb +6 -2
- data/lib/aio/ui.rb +135 -134
- data/lib/modules/cmd/cisco/show_version.rb +84 -84
- data/lib/modules/cmd/h3c/display_cpu.rb +41 -41
- data/lib/modules/cmd/h3c/display_version.rb +43 -43
- data/lib/modules/cmd/maipu/show_clock.rb +32 -0
- data/lib/modules/cmd/maipu/show_cpu.rb +36 -0
- data/lib/modules/cmd/maipu/show_ip_interface_brief.rb +44 -0
- data/lib/modules/cmd/maipu/show_memory.rb +22 -22
- data/lib/modules/cmd/maipu/show_version.rb +40 -40
- data/lib/modules/input/style/compare_xml.rb +73 -73
- data/lib/modules/output/style/cmds.rb +3 -3
- data/lib/modules/output/style/compare_diff.rb +23 -0
- data/lib/modules/output/style/excel_table_office.rb +1 -0
- data/lib/modules/output/style/excel_table_wps.rb +1 -0
- data/lib/modules/output/style/summary_report.rb +2 -1
- data/lib/modules/special/style/compare.rb +153 -103
- data/lib/modules/special/style/compare_old.rb +121 -0
- data/lib/modules/special/style/compare_with_device_manager.rb +227 -0
- metadata +16 -3
@@ -1,207 +1,260 @@
|
|
1
1
|
class Aio::DeviceManager
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|