Class: Kanrisuru::Core::IP::Parser::Link
- Defined in:
- lib/kanrisuru/core/ip/parsers/link.rb
Class Method Summary collapse
- .ip_link_result_json(rows) ⇒ Object
- .ip_link_result_parse(lines) ⇒ Object
- .parse(command, action, version) ⇒ Object
Methods inherited from Base
ip_address_label_result_json, ip_address_label_result_parse, parse_address_info, parse_alias, parse_ip_maddr_name, parse_ip_row, parse_link, parse_rx, parse_tx, parse_valid
Class Method Details
.ip_link_result_json(rows) ⇒ Object
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 |
# File 'lib/kanrisuru/core/ip/parsers/link.rb', line 49 def ip_link_result_json(rows) result = [] rows.each do |row| next if row['ifindex'].instance_of?(NilClass) new_row = Kanrisuru::Core::IP::IPLinkProperty.new( row['ifindex'], row['ifname'], row['flags'], row['mtu'], row['qdisc'], row['operstate'], row['group'], row['txqlen'], row['linkmode'], row['link_type'], row['address'], row['ifalias'], nil ) if row.key?('stats64') rx = row['stats64']['rx'] tx = row['stats64']['tx'] new_row[:stats] = Kanrisuru::Core::IP::IPStats.new( Kanrisuru::Core::IP::IPStatRX.new( rx['bytes'], rx['packets'], rx['errors'], rx['dropped'], rx['over_errors'], rx['multicast'] ), Kanrisuru::Core::IP::IPStatTX.new( tx['bytes'], tx['packets'], tx['errors'], tx['dropped'], tx['carrier_errors'], tx['collisions'] ) ) end result << new_row end result end |
.ip_link_result_parse(lines) ⇒ Object
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 |
# File 'lib/kanrisuru/core/ip/parsers/link.rb', line 23 def ip_link_result_parse(lines) rows = [] current_row = nil lines.each.with_index do |line, index| case line when /^\d+:\s/ rows << current_row unless current_row.nil? current_row = Kanrisuru::Core::IP::IPLinkProperty.new parse_ip_row(current_row, line) when /^link/ parse_link(current_row, line) when /^alias/ parse_alias(current_row, line) when /^RX:/ parse_rx(current_row, lines[index + 1]) when /^TX:/ parse_tx(current_row, lines[index + 1]) end end rows << current_row rows end |
.parse(command, action, version) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kanrisuru/core/ip/parsers/link.rb', line 9 def parse(command, action, version) return unless %w[show list].include?(action) if version >= Kanrisuru::Core::IP::IPROUTE2_JSON_VERSION begin ip_link_result_json(command.to_json) rescue JSON::ParserError ip_link_result_parse(command.to_a) end else ip_link_result_parse(command.to_a) end end |