Class: PuppetX::SIMP::IPTables::Rule
- Inherits:
-
Object
- Object
- PuppetX::SIMP::IPTables::Rule
- Defined in:
- lib/puppetx/simp/iptables/rule.rb
Instance Attribute Summary collapse
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#complex ⇒ Object
readonly
This is true if the rule has more than just a jump in it.
-
#jump ⇒ Object
readonly
Returns the value of attribute jump.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#rule_type ⇒ Object
readonly
Returns the value of attribute rule_type.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rule, table) ⇒ Rule
constructor
Create the particular rule.
- #to_s ⇒ Object
Constructor Details
#initialize(rule, table) ⇒ Rule
Create the particular rule. The containing table should be passed in for future reference.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 29 def initialize(rule,table) @rule = rule.strip @rule_type = :rule if table.nil? or table.empty? then raise(Puppet::Error,"All rules must have an associated table: '#{rule}'") end @table = table.strip parsed_rule = PuppetX::SIMP::IPTables::Rule.parse(rule) @chain = parsed_rule[:chain] @jump = parsed_rule[:jump] @complex = true if @rule == 'COMMIT' then @rule_type = :commit elsif @rule =~ /^\s*(:.*)\s+(.*)\s/ then @rule = "#{$1} #{$2} [0:0]" @rule_type = :chain end if @rule =~ /^\s*-(A|D|I|R|N|P)\s+\S+\s+-j\s+\S+\s*$/ then @complex = false end end |
Instance Attribute Details
#chain ⇒ Object (readonly)
Returns the value of attribute chain
8 9 10 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 8 def chain @chain end |
#complex ⇒ Object (readonly)
This is true if the rule has more than just a jump in it.
11 12 13 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 11 def complex @complex end |
#jump ⇒ Object (readonly)
Returns the value of attribute jump
9 10 11 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 9 def jump @jump end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule
5 6 7 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 5 def rule @rule end |
#rule_type ⇒ Object (readonly)
Returns the value of attribute rule_type
6 7 8 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 6 def rule_type @rule_type end |
#table ⇒ Object (readonly)
Returns the value of attribute table
7 8 9 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 7 def table @table end |
Class Method Details
.parse(rule) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 13 def self.parse(rule) output = { :chain => nil, :jump => nil } if rule =~ /^\s*-(?:A|D|I|R|N|P)\s+(\S+)(?:.*-j\s+(.+)\s*)*/ then output[:chain] = $1 output[:jump] = $2.to_s.split(/\s+/).first end return output end |
Instance Method Details
#to_s ⇒ Object
57 58 59 |
# File 'lib/puppetx/simp/iptables/rule.rb', line 57 def to_s return @rule end |