From: Jonathan Boyett Date: Thu, 12 May 2011 02:07:27 +0000 (-0700) Subject: join arrays and use insert order to determine replacement position X-Git-Tag: v0.0.1~59 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=06eb1443a0141f5913a358044fe561b03ec99f15;p=puppet-modules%2Fpuppetlabs-firewall.git join arrays and use insert order to determine replacement position --- diff --git a/lib/puppet/provider/firewall/iptables.rb b/lib/puppet/provider/firewall/iptables.rb index 427eb0f..b8dd479 100644 --- a/lib/puppet/provider/firewall/iptables.rb +++ b/lib/puppet/provider/firewall/iptables.rb @@ -50,7 +50,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir def delete debug 'Deleting rule %s' % resource[:name] - iptables "-D", properties[:chain], properties[:rulenum] + iptables "-D", properties[:chain], insert_order end def exists? @@ -119,7 +119,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir def update_args args = [] - args << ["-R", resource[:chain], properties[:rulenum]] + args << ["-R", resource[:chain], insert_order] args << general_args args end @@ -130,7 +130,11 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir @@resource_list.each do |res| if(resource.value(res)) args << @@resource_map[res].split(' ') - args << resource[res] + if resource[res].is_a?(Array) + args << resource[res].join(',') + else + args << resource[res] + end end end args diff --git a/lib/puppet/type/firewall.rb b/lib/puppet/type/firewall.rb index 693df71..f131637 100644 --- a/lib/puppet/type/firewall.rb +++ b/lib/puppet/type/firewall.rb @@ -106,7 +106,7 @@ Puppet::Type.newtype(:firewall) do Accepts a single string or array." end - newproperty(:sport) do + newproperty(:sport, :array_matching => :all) do desc "The value for the iptables --source-port parameter. If an array is specified, values will be passed to multiport module." @@ -119,6 +119,17 @@ Puppet::Type.newtype(:firewall) do munge do |value| @resource.string_to_port(value) end + + def value_to_s(value) + value = [value] unless value.is_a?(Array) + value.join(',') + end + + def change_to_s(currentvalue, newvalue) + currentvalue = value_to_s(currentvalue) if currentvalue != :absent + newvalue = value_to_s(newvalue) + super(currentvalue, newvalue) + end end newproperty(:dport, :array_matching => :all) do