Class: OnetableTerminator::Iptables::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/onetable_terminator/iptables/parser.rb

Constant Summary collapse

COLUMN_COUNT =
11
TARGET_COLUMN_COUNT =
4
TARGET_VM_ID_COLUMN =
1
TARGET_IO_COLUMN =
3
NUMBER_COLUMN =
0
TARGET_COLUMN =
1
NIC_COLUMN =
9

Instance Method Summary collapse

Instance Method Details

#parse_rules(output) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/onetable_terminator/iptables/parser.rb', line 12

def parse_rules(output)
  nics = {}
  lines = output.lines.to_a
  normalize_output!(lines)

  lines.each do |line|
    parsed_line = parse_line line
    nic_name = parsed_line[:nic]

    nic = nics[nic_name]
    unless nic
      nic = OnetableTerminator::Structures::Nic.new nic_name
      nics[nic_name] = nic
    end
    nic.add_rule OnetableTerminator::Structures::Rule.new parsed_line
  end

  nics.values
end