X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/faf8ae12e85eabb050b0f5eceb2cb67ad1de5261..4b03c18aff06d5f34a587fd90af9af0f528e4c61:/cookbooks/networking/libraries/interfaces.rb diff --git a/cookbooks/networking/libraries/interfaces.rb b/cookbooks/networking/libraries/interfaces.rb index cc9c11a23..64aecdeca 100644 --- a/cookbooks/networking/libraries/interfaces.rb +++ b/cookbooks/networking/libraries/interfaces.rb @@ -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 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 + 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)