X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/1b506c7210655ca2f4ea844cd076e44869d6e6a2..e92ed5e09215d67f2bd7dc21a32425d7ec5aa26f:/cookbooks/networking/libraries/interfaces.rb diff --git a/cookbooks/networking/libraries/interfaces.rb b/cookbooks/networking/libraries/interfaces.rb index 029cb4f32..64aecdeca 100644 --- a/cookbooks/networking/libraries/interfaces.rb +++ b/cookbooks/networking/libraries/interfaces.rb @@ -1,23 +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| - next unless options[:role].nil? || interface[:role].to_s == options[:role].to_s - next unless options[:family].nil? || interface[:family].to_s == options[:family].to_s - - if block.nil? - interfaces << interface - else - block.call(interface) + 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)