class OnetableTerminator::Iptables::Exec
Constants
- COMMAND_DELETE_OPENNEBULA_CHAIN
- COMMAND_DELETE_OPENNEBULA_RULE
- COMMAND_FLUSH_OPENNEBULA_CHAIN
- COMMAND_LIST_OPENNEBULA_CHAIN
- IPTABLES_BINARY
- OPENNEBULA_CHAIN
Attributes
dry_run[R]
parser[R]
Public Class Methods
new(dry_run = false)
click to toggle source
# File lib/onetable_terminator/iptables/exec.rb, line 15 def initialize(dry_run = false) @parser = OnetableTerminator::Iptables::Parser.new @dry_run = dry_run end
Public Instance Methods
delete_opennebula_chain(chain)
click to toggle source
# File lib/onetable_terminator/iptables/exec.rb, line 43 def delete_opennebula_chain(chain) command = COMMAND_DELETE_OPENNEBULA_CHAIN.dup command << chain run_command command, 'Cannot delete opennebula chain' end
delete_opennebula_rule(rule_number)
click to toggle source
# File lib/onetable_terminator/iptables/exec.rb, line 29 def delete_opennebula_rule(rule_number) command = COMMAND_DELETE_OPENNEBULA_RULE.dup command << rule_number.to_s run_command command, 'Cannot delete opennebula chain rule' end
flush_opennebula_chain(chain)
click to toggle source
# File lib/onetable_terminator/iptables/exec.rb, line 36 def flush_opennebula_chain(chain) command = COMMAND_FLUSH_OPENNEBULA_CHAIN.dup command << chain run_command command, 'Cannot flush opennebula chain' end
load_opennebula_chain()
click to toggle source
# File lib/onetable_terminator/iptables/exec.rb, line 20 def load_opennebula_chain output = run_command COMMAND_LIST_OPENNEBULA_CHAIN, 'Cannot retrieve rules for opennebula iptables chain', safe: true, log_only: true logger.debug('Output:') logger.debug(output) parser.parse_rules output end
Private Instance Methods
run_command(command, error_msg, options = {})
click to toggle source
# File lib/onetable_terminator/iptables/exec.rb, line 52 def run_command(command, error_msg, options = {}) logger.debug("Running command: #{command.inspect}") output = '' if !dry_run || options[:safe] iptables = Mixlib::ShellOut.new(command) iptables.run_command output = iptables.stdout if iptables.error? if options[:log_only] logger.warn "Command execution error: #{error_msg}: #{iptables.stderr}" return '' end raise OnetableTerminator::Errors::CommandExecutionError, "#{error_msg}: #{iptables.stderr}" if iptables.error? end end output end