]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/libraries/interfaces.rb
Add a load more cookbooks
[chef.git] / cookbooks / networking / libraries / interfaces.rb
diff --git a/cookbooks/networking/libraries/interfaces.rb b/cookbooks/networking/libraries/interfaces.rb
new file mode 100644 (file)
index 0000000..cc9c11a
--- /dev/null
@@ -0,0 +1,24 @@
+class Chef
+  class Node
+    def interfaces(options = {}, &block)
+      interfaces = []
+
+      networking = construct_attributes[:networking] || {}
+      networking_interfaces = networking[:interfaces] || []
+
+      networking_interfaces.each do |name,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
+        end
+      end
+
+      interfaces
+    end
+  end
+end