Class: Aio::Module::Cmd::H3C::DisplayInterface
- Inherits:
-
Aio::Module::Cmd::H3C
- Object
- Aio::Module::Cmd
- Aio::Module::Cmd::H3C
- Aio::Module::Cmd::H3C::DisplayInterface
- Includes:
- Aio::Module
- Defined in:
- lib/modules/cmd/h3c/display_interface.rb
Constant Summary collapse
- Reg_Bridge_Aggregation =
/Bridge-Aggregation/
- Reg_Ethernet =
/Ethernet/
- Reg_Loopback =
/LoopBack/
- Reg_Vlanif =
/Vlan/
Instance Attribute Summary
Attributes inherited from Aio::Module::Cmd
#cmd_info, #context, #device_info, #ext_info, #useful, #warning_klass
Instance Method Summary collapse
-
#initialize ⇒ DisplayInterface
constructor
A new instance of DisplayInterface.
- #parse ⇒ Object
- #parse_bridge(context) ⇒ Object
- #parse_eth(context) ⇒ Object
- #parse_loopback(context) ⇒ Object
- #parse_vlanif(context) ⇒ Object
- #same_line_1(context, iface, iface_id) ⇒ Object
- #same_line_2(context, iface, iface_id) ⇒ Object
- #switch_iface(context) ⇒ Object
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
#initialize ⇒ DisplayInterface
Returns a new instance of DisplayInterface.
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 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 9 def initialize super({ :cmd_full => "display interface", :cmd_short => "dis inter", :author => "Elin", :description => "This is H3C Command# display interface", :ranking => Ranking_1, :platform => "switch", :benchmark => { :duplex => ["=~", /full/], :input_errors => ["<", 10], :output_errors => ["<", 10], :runts => ["<", 10], :giants => ["<", 10], :throttles => ["<", 10], :crc => ["<", 1000], :frame => ["<", 10], :overruns => ["<", 10], :aborts => ["<", 10], :underruns => ["<", 10], :deferred => ["<", 10], :carrier => ["<", 10], :input_drops => ["<", 10], :output_drops => ["<", 10], :collisions => ["<", 10], :last_collisions => ["<", 10], :lost_carrier => ["<", 10], } }) end |
Instance Method Details
#parse ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 45 def parse cont = self.context.dup useful[:interface] = {} loop do cont.readline_range(/.*/, reg_blank) do |cont_layer| switch_iface(cont_layer) end end end |
#parse_bridge(context) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 75 def parse_bridge(context) iface = {} iface_id = nil context.readline_match_block(/(?<iface_id>Bridge-Aggregation\d+) current state\s?:\s?(?<state>.*)/) do |block| iface_id = block[:iface_id] useful[:interface][iface_id] = iface block.update(iface, :iface_id) block.update(iface, :state) end context.readline_match_block(/IP Packet Frame Type: PKTFMT_ETHNT_2, Hardware Address: (?<mac>.*)/) do |block| block.update(iface, :mac) end context.readline_match_block(/Description: (?<description>.*)/) do |block| block.update(iface, :description) end context.readline_match_block(/(?<speed>.*) mode, (?<duplex>.*) mode/) do |block| block.update(iface, :speed) block.warning_serious(iface, :duplex, self) if iface[:state] =~ /UP/ end context.readline_match_block(/Port link-type: (?<link_type>.*)/) do |block| block.update(iface, :link_type) end same_line_1(context, iface, iface_id) if iface[:state] =~ /UP/ end |
#parse_eth(context) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 100 def parse_eth(context) iface = {} iface_id = nil context.readline_match_block(/(?<iface_id>.*) current state\s?:\s?(?<state>.*)/) do |block| iface_id = block[:iface_id].strip useful[:interface][iface_id] = iface block.update(iface, :iface_id) block.update(iface, :state) end return if iface.nil? context.readline_match_block(/Hardware Address: (?<mac>.*)/) do |block| block.update(iface, :mac) end context.readline_match_block(/Description: (?<description>.*)/) do |block| block.update(iface, :description) end context.readline_match_block(/(?<speed>.*) mode, (?<duplex>.*) mode/) do |block| block.update(iface, :speed) block.warning_serious(iface, :duplex, self) if iface[:state] =~ /UP/ end same_line_1(context, iface, iface_id) if iface[:state] =~ /UP/ end |
#parse_loopback(context) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 151 def parse_loopback(context) iface = {} iface_id = nil context.readline_match_block(/(?<iface_id>LoopBack\d+) current state\s?:\s?(?<state>.*)/) do |block| iface_id = block[:iface_id] useful[:interface][iface_id] = iface block.update(iface, :iface_id) block.update(iface, :state) end same_line_2(context, iface, iface_id) end |
#parse_vlanif(context) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 163 def parse_vlanif(context) iface = {} iface_id = nil context.readline_match_block(/(?<iface_id>.*) current state: (?<state>.*)/) do |block| iface_id = block[:iface_id] useful[:interface][iface_id] = iface block.update(iface, :iface_id) block.update(iface, :state) end same_line_2(context, iface, iface_id) end |
#same_line_1(context, iface, iface_id) ⇒ Object
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 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 123 def same_line_1(context, iface, iface_id) context.readline_match_block(/Input: (?<input_errors>\d+) input errors, (?<runts>\d+) runts, (?<giants>\d+) giants, (?<throttles>\d+) throttles/) do |block| ##### block.warning_ordinary(iface, :input_errors, self) block.warning_ordinary(iface, :runts, self) block.warning_ordinary(iface, :giants, self) block.warning_ordinary(iface, :throttles, self) end context.readline_match_block(/(?<crc>\d+) CRC, (?<frame>\d+) frame, - overruns, (?<aborts>\d+) aborts/) do |block| block.warning_serious(iface, :crc, self) block.warning_ordinary(iface, :frame, self) block.warning_ordinary(iface, :aborts, self) end context.readline_match_block(/Output: (?<output_errors>\d+) output errors, - underruns, - buffer failures/) do |block| block.warning_ordinary(iface, :output_errors, self) end context.readline_match_block(/(?<aborts>\d+) aborts, (?<deferred>\d+) deferred, (?<collisions>\d+) collisions, (?<last_collisions>\d+) late collisions/) do |block| block.warning_ordinary(iface, :aborts, self) block.warning_ordinary(iface, :deferred, self) block.warning_ordinary(iface, :collisions, self) block.warning_ordinary(iface, :last_collisions, self) end context.readline_match_block(/(?<lost_carrier>\d+) lost carrier/) do |block| block.warning_ordinary(iface, :lost_carrier, self) end end |
#same_line_2(context, iface, iface_id) ⇒ Object
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 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 175 def same_line_2(context, iface, iface_id) context.readline_match_block(/Line protocol current state: (?<proto_state>.*)/) do |block| block.update(iface, :proto_state) end context.readline_match_block(/Description: (?<description>.*)/) do |block| block.update(iface, :description) end context.readline_match_block(/Internet (?<addr>.*)/) do |block| if block[:addr] =~ /Address (.*) Primary/ block.update(iface, :ip_addr, $1) end end context.readline_match_block(/Hardware Address: (?<mac>.*)/) do |block| block.update(iface, :mac) end if iface[:state] =~ /UP/ context.readline_match_block(/input, \d+ bytes, (?<input_drops>\d+) drops/) do |block| block.warning_ordinary(iface, :input_drops, self) end context.readline_match_block(/output, \d+ bytes, (?<output_drops>\d+) drops/) do |block| block.warning_ordinary(iface, :output_drops, self) end end end |
#switch_iface(context) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/modules/cmd/h3c/display_interface.rb', line 55 def switch_iface(context) i = 0 while(i < 5) if context[i] =~ /current/ break end i += 1 end case context[i] when Reg_Bridge_Aggregation parse_bridge(context) when Reg_Ethernet parse_eth(context) when Reg_Loopback parse_loopback(context) when Reg_Vlanif parse_vlanif(context) end end |