Class: Aio::Parse::Parser
- Inherits:
-
Object
- Object
- Aio::Parse::Parser
- Includes:
- Ui::Verbose
- Defined in:
- lib/aio/core/parse/parser.rb
Instance Attribute Summary collapse
-
#device_manager ⇒ Object
Returns the value of attribute device_manager.
-
#input_klass ⇒ Object
重要!在分析前需要确定input_klass input_klass 的类为input模块的类 Aio::Module::InputStyle.
-
#parser_machine ⇒ Object
Returns the value of attribute parser_machine.
Instance Method Summary collapse
-
#initialize(device_manager, parser_machine) ⇒ Parser
constructor
A new instance of Parser.
-
#invalid?(context) ⇒ Boolean
判断 context 是否有效.
-
#parse_by_compare(compare_klass) ⇒ Object
通过output/compare_xml生成的XML文件解析,直接将结果保存 compare_klass 为比较模块 其中只比较useful的值,并不会去比较warning warning 有原本device中以及比较中共同得出.
-
#parse_by_compare_with_device_manager(compare_klass, other_device_manager) ⇒ Object
按照两个 device_manager 来进行比较.
-
#parse_by_module ⇒ Object
通过巡检文件的方式获得关键信息,并按cmd模块逐个解析.
Methods included from Ui::Verbose
#clear_line, #print_error, #print_good, #progress_bar
Constructor Details
#initialize(device_manager, parser_machine) ⇒ Parser
Returns a new instance of Parser.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/aio/core/parse/parser.rb', line 15 def initialize(device_manager, parser_machine) self.device_manager = device_manager self.parser_machine = parser_machine @invalid_input = Aio::Base::Toolkit::Regexp.merge([ Aio::Device::Cisco::InvalidInput, Aio::Device::H3C::InvalidInput, Aio::Device::Huawei::InvalidInput, Aio::Device::Maipu::InvalidInput, Aio::Device::Juniper::InvalidInput, ]) end |
Instance Attribute Details
#device_manager ⇒ Object
Returns the value of attribute device_manager.
5 6 7 |
# File 'lib/aio/core/parse/parser.rb', line 5 def device_manager @device_manager end |
#input_klass ⇒ Object
重要!在分析前需要确定input_klass input_klass 的类为input模块的类Aio::Module::InputStyle
11 12 13 |
# File 'lib/aio/core/parse/parser.rb', line 11 def input_klass @input_klass end |
#parser_machine ⇒ Object
Returns the value of attribute parser_machine.
6 7 8 |
# File 'lib/aio/core/parse/parser.rb', line 6 def parser_machine @parser_machine end |
Instance Method Details
#invalid?(context) ⇒ Boolean
判断 context 是否有效
72 73 74 75 76 |
# File 'lib/aio/core/parse/parser.rb', line 72 def invalid?(context) return true if context.empty? return true if @invalid_input.match(context[1]) return false end |
#parse_by_compare(compare_klass) ⇒ Object
通过output/compare_xml生成的XML文件解析,直接将结果保存compare_klass 为比较模块其中只比较useful的值,并不会去比较warning warning 有原本device中以及比较中共同得出
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aio/core/parse/parser.rb', line 82 def parse_by_compare(compare_klass) # device_hash 为提供比较文件的hash print_good "正在将比较文件转换为内部Hash表" device_hash = @input_klass.parse compare_klass.device_manager = device_manager compare_klass.input_benchmark = device_hash compare_hash = compare_klass.parse device_manager.merge_warning(compare_hash) end |
#parse_by_compare_with_device_manager(compare_klass, other_device_manager) ⇒ Object
按照两个 device_manager 来进行比较
94 95 96 97 98 99 100 |
# File 'lib/aio/core/parse/parser.rb', line 94 def parse_by_compare_with_device_manager(compare_klass, other_device_manager) print_good '正在导入device_manager信息' compare_klass.device_manager = device_manager compare_klass.input_benchmark = other_device_manager compare_hash = compare_klass.parse device_manager.merge_warning(compare_hash) end |
#parse_by_module ⇒ Object
通过巡检文件的方式获得关键信息,并按cmd模块逐个解析
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 |
# File 'lib/aio/core/parse/parser.rb', line 29 def parse_by_module # 注意这里manager_ip可有可无, 没有的话默认为nil print_good "正在加载信息..." @input_klass.parse do |device_name, cmd, context, manager_ip| device_info = { :device_name => device_name, :cmd => cmd.strip, :context => Aio::Text::Context.new(context), :manager_ip => manager_ip } # 判断 context 是否有效 next if invalid?(context) # 所有判断交到状态机处理 self.parser_machine.get_device(device_info) self.parser_machine.get_full(device_info) end print_good "信息加载完成" # 获取所有设备数量 total = device_manager.devices_number #Aio::Ui::Logger.instance.info = {devices_number: total} print_good "总共 #{total} 台设备" print_good "正在对各个设备进行分析..." device_manager.each_devices_with_index do |name, klass, i| # 将解析命令后,并修改了自身类的实例覆盖掉原来父类 (total, i+1, name) # Debug处 if name == "CIB41_CS_H5500SW01" #debugger end new_klass = klass.parse device_manager[name] = new_klass.instance end clear_line print_good "设备信息分析完成" end |