Class: Aio::Module::Cmd::Maipu::ShowIpInterfaceBrief

Inherits:
Aio::Module::Cmd::Maipu show all
Includes:
Aio::Module
Defined in:
lib/modules/cmd/maipu/show_ip_interface_brief.rb

Instance Attribute Summary

Attributes inherited from Aio::Module::Cmd

#cmd_info, #context, #device_info, #ext_info, #useful, #warning_klass

Instance Method Summary collapse

Methods inherited from Aio::Module::Cmd

#author, #benchmark, #clear_useful, #cmd_full, #cmd_short, #description, #division, #key_stand, #license, #platform, #ranking, #set_defaults, #type

Methods included from Ui::Verbose

#clear_line, #print_error, #print_good, #progress_bar

Constructor Details

#initializeShowIpInterfaceBrief

Returns a new instance of ShowIpInterfaceBrief.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/modules/cmd/maipu/show_ip_interface_brief.rb', line 8

def initialize
  super({
    :cmd_full			=> "show ip interface brief",
    :cmd_short		=> "sh ip int b",
    :author				=> "Elin",
    :description	=> "This is Maipu Command# show ip interface brief",
    :ranking			=> Ranking_1,
    :platform			=> RS,
    :benchmark	=> { }
  })
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/modules/cmd/maipu/show_ip_interface_brief.rb', line 20

def parse
  context = self.context.dup
  useful[:interface_brief] = {}
  context.readline_match_block(/Interface IP-Address Status Protocol Description/) {|b|b}
  context.readline_match_block_loop(/(?<interface_id>[^\s]+) (?<ip>[^\s]+) (?<status>[^\s]+) (?<protocol_description>[^\s].*)/, reg_blank) do |block|
    iface = {}
    iface_id = block[:interface_id]
    useful[:interface_brief][iface_id.to_sym] = iface
    
    protocol, description = block[:protocol_description].split(' ', 2)
    block.update(iface, :interface_id)
    block.update(iface, :ip)
    block.update(iface, :status)
    block.update(iface, :protocol, protocol)
    block.update(iface, :description, description.to_s)
    # 当状态是起来的,但是协议为Down,则纳入警告
    if (block[:status] =~ /up/) and !(protocol =~ /up/)
      block.warning_serious(iface, :protocol, self, {string: protocol, force: true})
    else
      block.warning_serious(iface, :protocol, self, {string: protocol, force: false})
    end
  end
end