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.
- 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,233 +1,235 @@
|
|
1
|
+
require 'byebug'
|
1
2
|
#
|
2
3
|
# 这个模块用于统一命令方法,方便一起管理
|
3
4
|
#
|
4
5
|
module Aio::Device
|
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
|
-
|
122
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
6
|
+
module Methods
|
7
|
+
|
8
|
+
class << self
|
9
|
+
include Aio::Ui::Verbose
|
10
|
+
|
11
|
+
def klass=(klass)
|
12
|
+
@@klass = klass
|
13
|
+
end
|
14
|
+
|
15
|
+
def klass
|
16
|
+
@@klass
|
17
|
+
end
|
18
|
+
|
19
|
+
# CPU 利用率百分比
|
20
|
+
def cpu_percent
|
21
|
+
begin
|
22
|
+
cmd = CmdSwitch.cpu(klass)
|
23
|
+
return klass.cmds_useful[cmd][:cpu][:minutes_5] if kind_of?(Cisco, H3C)
|
24
|
+
return klass.cmds_useful[cmd][:cpu][:used_percent] if klass.kind_of? Maipu
|
25
|
+
rescue Exception
|
26
|
+
puts_error
|
27
|
+
return ""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Memory 利用率百分比
|
32
|
+
def memory_percent
|
33
|
+
begin
|
34
|
+
cmd = CmdSwitch.memory(klass)
|
35
|
+
return klass.cmds_useful[cmd][:memory][:used_rate] if klass.kind_of? H3C
|
36
|
+
return klass.cmds_useful[cmd][:memory][:proc_ratio] if klass.kind_of? Cisco
|
37
|
+
return klass.cmds_useful[cmd][:memory][:used_percent] if klass.kind_of? Maipu
|
38
|
+
rescue Exception
|
39
|
+
puts_error
|
40
|
+
return ""
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# IOS 版本
|
45
|
+
def ios_version
|
46
|
+
begin
|
47
|
+
cmd = CmdSwitch.version(klass)
|
48
|
+
return klass.cmds_useful[cmd][:software][:version] if kind_of?(Cisco, H3C, Maipu)
|
49
|
+
rescue Exception
|
50
|
+
puts_error
|
51
|
+
return ""
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# IOS 特性集
|
56
|
+
def soft_image
|
57
|
+
begin
|
58
|
+
cmd = CmdSwitch.version(klass)
|
59
|
+
return klass.cmds_useful[cmd][:software][:soft_image] if kind_of?(Cisco, Maipu)
|
60
|
+
|
61
|
+
# H3C 不是在version中查看
|
62
|
+
rescue Exception
|
63
|
+
puts_error
|
64
|
+
return ""
|
65
|
+
ensure
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# 运行时间
|
70
|
+
def uptime
|
71
|
+
begin
|
72
|
+
cmd = CmdSwitch.version(klass)
|
73
|
+
return klass.cmds_useful[cmd][:software][:uptime] if kind_of?(Cisco, H3C, Maipu)
|
74
|
+
rescue Exception
|
75
|
+
puts_error
|
76
|
+
return ""
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# 判断温度是否有警告
|
81
|
+
def warning_env?
|
82
|
+
begin
|
83
|
+
if klass.kind_of? Maipu
|
84
|
+
return (klass.include_warning?(:mainboard_temperature) and klass.include_warning?(:cpu_temperature))
|
85
|
+
end
|
86
|
+
return klass.include_warning?(:cpu_status) if klass.kind_of? Cisco
|
87
|
+
rescue Exception
|
88
|
+
puts_error
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# 判断电源是否有警告
|
94
|
+
def warning_power?
|
95
|
+
begin
|
96
|
+
return klass.include_warning?(:power_status) if kind_of?(Cisco, H3C, Maipu)
|
97
|
+
rescue Exception
|
98
|
+
puts_error
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# 判断风扇是否有警告
|
103
|
+
def warning_fan?
|
104
|
+
begin
|
105
|
+
return klass.include_warning?(:fan_status) if kind_of?(Cisco, H3C, Maipu)
|
106
|
+
rescue Exception
|
107
|
+
puts_error
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# 只判断最关键的三个信息
|
112
|
+
def warning_interface?
|
113
|
+
begin
|
114
|
+
if kind_of?(Cisco, Maipu, H3C)
|
115
|
+
tmp = klass.include_warning?(:input_errors)
|
116
|
+
tmp = tmp or klass.include_warning(:crc)
|
117
|
+
tmp = tmp or klass.include_warning(:output_errors)
|
118
|
+
return tmp
|
119
|
+
end
|
120
|
+
rescue Exception
|
121
|
+
puts_error
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# 板卡序列号信息
|
126
|
+
# 返回数组: [{:name, :pid, :sn, :description}]
|
127
|
+
def inventory
|
128
|
+
cmd = CmdSwitch.inventory(klass)
|
129
|
+
begin
|
130
|
+
if kind_of?(Cisco, H3C)
|
131
|
+
keys = klass.cmds_useful[cmd][:inventory].keys
|
132
|
+
res = []
|
133
|
+
keys.each do |sn|
|
134
|
+
res << klass.cmds_useful[cmd][:inventory][sn.to_sym]
|
135
|
+
end
|
136
|
+
return res
|
137
|
+
else
|
138
|
+
return [{:name => "", :pid => "", :sn => "", :description => ""}]
|
139
|
+
end
|
140
|
+
|
141
|
+
rescue Exception
|
142
|
+
puts_error
|
143
|
+
return [{:name => "", :pid => "", :sn => "", :description => ""}]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def clock
|
148
|
+
begin
|
149
|
+
cmd = CmdSwitch.clock(klass)
|
150
|
+
pool = ["time", "zone", "week", "year", "month", "day"]
|
151
|
+
res = []
|
152
|
+
pool.each do |key|
|
153
|
+
res << klass.cmds_useful[cmd][:clock][key.to_sym]
|
154
|
+
end
|
155
|
+
return res
|
156
|
+
rescue Exception
|
157
|
+
puts_error
|
158
|
+
return ["", "", "", "", "", ""]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def get_manager_ip
|
163
|
+
return klass.manager_ip unless klass.manager_ip.nil?
|
164
|
+
|
165
|
+
begin
|
166
|
+
cmd = []
|
167
|
+
cmd[0] = CmdSwitch.interface(klass)
|
168
|
+
cmd[1] = CmdSwitch.interface_brief(klass)
|
169
|
+
|
170
|
+
total = []
|
171
|
+
manager = ""
|
172
|
+
|
173
|
+
return unless kind_of?(Cisco, H3C, Maipu)
|
174
|
+
|
175
|
+
# 如果是 show interfaces
|
176
|
+
if klass.has_cmd?(cmd[0])
|
177
|
+
total = klass.cmds_useful[cmd[0]][:interface]
|
178
|
+
|
179
|
+
total.each_value do |info|
|
180
|
+
if (info[:iface_id] == (klass.interface[:loopback] + "0")) and info[:state] =~ /(?i)up/
|
181
|
+
manager = info[:addr]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# 如果是 show ip interface brief
|
186
|
+
elsif klass.has_cmd?(cmd[1])
|
187
|
+
total = klass.cmds_useful[cmd[1]][:interface_brief]
|
188
|
+
|
189
|
+
total.each_value do |info|
|
190
|
+
# 如果有环回口,那么就直接输出
|
191
|
+
if (info[:interface_id].downcase == klass.interface[:loopback].downcase + "0") and (info[:status] =~ /(?i)up/)
|
192
|
+
manager = info[:ip]
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
return manager
|
197
|
+
|
198
|
+
rescue Exception
|
199
|
+
puts_error
|
200
|
+
return ""
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
private
|
205
|
+
|
206
|
+
# 判断klass是否是指定的Device类型
|
207
|
+
def kind_of?(*type)
|
208
|
+
type.each do |t|
|
209
|
+
return true if klass.kind_of?(t)
|
210
|
+
end
|
211
|
+
return false
|
212
|
+
end
|
213
|
+
|
214
|
+
# 统一的错误回显
|
215
|
+
def puts_error
|
216
|
+
res = /`(?<method>.*)'/.match(caller[1])
|
217
|
+
print_error "<#{res[:method]}>方法未执行成功 #{klass.class} : #{klass.device_name}"
|
218
|
+
end
|
219
|
+
|
220
|
+
# 对于有相同路径的cmds_useful,可以使用此方法
|
221
|
+
# 将按照给出的设备类型返回cmds_useful
|
222
|
+
# 方便命令的统一管理
|
223
|
+
def type_send(*types)
|
224
|
+
types.each do |type|
|
225
|
+
if klass.kind_of?(type)
|
226
|
+
yield klass.cmds_useful
|
227
|
+
else
|
228
|
+
next
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
end
|
233
235
|
end
|