class OnetableTerminator::Iptables::RulesHandler

Public Instance Methods

find_redundant_rules(nics) click to toggle source
# File lib/onetable_terminator/iptables/rules_handler.rb, line 4
def find_redundant_rules(nics)
  rules = []

  nics.each do |nic|
    logger.debug "Validating rules for NIC #{nic.name.inspect}"
    sorted_rules = nic.rules.sort { |left, right| right.vm_id <=> left.vm_id }
    correct_vm_id = sorted_rules.first.vm_id
    logger.debug "Correct VM ID is #{correct_vm_id.inspect}"
    redundant_rules = sorted_rules.reject { |rule| rule.vm_id == correct_vm_id }

    log_redundant redundant_rules

    rules.concat redundant_rules
  end

  rules
end

Private Instance Methods

log_redundant(redundant_rules) click to toggle source
# File lib/onetable_terminator/iptables/rules_handler.rb, line 24
def log_redundant(redundant_rules)
  if redundant_rules.empty?
    logger.debug 'Found no redundant rules'
  else
    logger.debug "Found #{redundant_rules.size} redundant rules:"
    redundant_rules.each { |redundant_rule| logger.debug redundant_rule.raw_line.to_s }
  end
end