]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
join arrays and use insert order to determine replacement position
authorJonathan Boyett <jonathan@failingservers.com>
Thu, 12 May 2011 02:07:27 +0000 (19:07 -0700)
committerJonathan Boyett <jonathan@failingservers.com>
Thu, 12 May 2011 02:07:27 +0000 (19:07 -0700)
lib/puppet/provider/firewall/iptables.rb
lib/puppet/type/firewall.rb

index 427eb0f0a183ee6e227c4b969e78337eb26e4383..b8dd479ffcbba437656c4139b2873d01041b0971 100644 (file)
@@ -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
index 693df71a92f59e00a554c645fd099db5be666cf0..f1316375d067e94dd0f1b5d1db7b316dadd2b774 100644 (file)
@@ -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