]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/libraries/interfaces.rb
Add a run time limit to the mediawiki-jobs service
[chef.git] / cookbooks / networking / libraries / interfaces.rb
index 67b2bd2373176e2fd69ab93697170d2de6025f77..64aecdeca7fb32b5ea9ebc774f1c3f6ccd46f884 100644 (file)
@@ -1,24 +1,16 @@
-class Chef
-  class Node
-    def interfaces(options = {}, &block)
-      interfaces = []
+module OpenStreetMap
+  module Mixin
+    module Interfaces
+      def interfaces(role: nil)
+        networking = construct_attributes[:networking] || {}
+        networking_interfaces = networking[:interfaces] || {}
 
-      networking = construct_attributes[:networking] || {}
-      networking_interfaces = networking[:interfaces] || []
-
-      networking_interfaces.each_value  do |interface|
-        if options[:role].nil? or interface[:role].to_s == options[:role].to_s
-          if options[:family].nil? or interface[:family].to_s == options[:family].to_s
-            if block.nil?
-              interfaces << interface
-            else
-              block.call(interface)
-            end
-          end
+        networking_interfaces.each_value.select do |interface|
+          role.nil? || interface[:role].to_s == role.to_s
         end
       end
-
-      interfaces
     end
   end
 end
+
+Chef::Node.include(OpenStreetMap::Mixin::Interfaces)