]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
allow arrays in dport, sport, destination, source, and state
authorJonathan Boyett <jonathan@failingservers.com>
Fri, 13 May 2011 20:37:30 +0000 (13:37 -0700)
committerJonathan Boyett <jonathan@failingservers.com>
Fri, 13 May 2011 20:37:30 +0000 (13:37 -0700)
lib/puppet/type/firewall.rb

index f1316375d067e94dd0f1b5d1db7b316dadd2b774..1a74280df6e81a2fcc99fb47621bae2db88b452d 100644 (file)
@@ -96,14 +96,24 @@ Puppet::Type.newtype(:firewall) do
     defaultto "ACCEPT"
   end
 
-  newproperty(:source) do
+  newproperty(:source, :array_matching => :all) do
     desc "The value for the iptables --source parameter.
       Accepts a single string or array."
+
+    def should_to_s(value)
+      value = [value] unless value.is_a?(Array)
+      value.join(',')
+    end
   end
 
-  newproperty(:destination) do
+  newproperty(:destination, :array_matching => :all) do
     desc "The value for the iptables --destination parameter.
       Accepts a single string or array."
+
+    def should_to_s(value)
+      value = [value] unless value.is_a?(Array)
+      value.join(',')
+    end
   end
 
   newproperty(:sport, :array_matching => :all) do
@@ -120,16 +130,10 @@ Puppet::Type.newtype(:firewall) do
       @resource.string_to_port(value)
     end
 
-    def value_to_s(value)
+    def should_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
@@ -146,16 +150,10 @@ Puppet::Type.newtype(:firewall) do
       @resource.string_to_port(value)
     end
 
-    def value_to_s(value)
+    def should_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(:iniface) do
@@ -202,10 +200,15 @@ Puppet::Type.newtype(:firewall) do
     end
   end
 
-  newproperty(:state) do
+  newproperty(:state, :array_matching => :all) do
     desc "The value for the iptables -m state --state parameter.
       Possible values are: 'INVALID', 'ESTABLISHED', 'NEW', 'RELATED'.
       Accepts a single string or array."
+
+    def should_to_s(value)
+      value = [value] unless value.is_a?(Array)
+      value.join(',')
+    end
   end
 
   newproperty(:limit) do