diff --git a/.rubocop.yml b/.rubocop.yml index 4eba943..51223d8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,12 +3,11 @@ AllCops: - metadata.rb - Gemfile - attributes/** + - libraries/** - providers/** - recipes/** - resources/** - spec/** - Excludes: - - libraries/** Encoding: Exclude: diff --git a/libraries/drive_utils.rb b/libraries/drive_utils.rb index 85fff65..d48d380 100644 --- a/libraries/drive_utils.rb +++ b/libraries/drive_utils.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 # # Cookbook Name:: openstack-object-storage # Library:: drive_utils @@ -19,11 +20,14 @@ # Author: Ron Pedde # +# Drive Inspection Related Utilities +# rubocop:disable Eval, UselessAssignment +# TODO(chrislaco) This is a tragedy, and needs refactored module DriveUtils def locate_disks(enum_expression, filter_expressions) candidate_disks = eval(enum_expression) - candidate_expression = "candidate_disks.select{|candidate,info| (" + - filter_expressions.map{|x| "(#{x})"}.join(" and ") + ")}" + candidate_expression = 'candidate_disks.select{|candidate,info| (' + + filter_expressions.map { |x| "(#{x})" }.join(' and ') + ')}' # TODO(mancdaz): fix this properly so the above works in the first place candidate_expression.gsub!(/\[\'removable\'\] = 0/, "['removable'].to_i == 0") drives = Hash[eval(candidate_expression)] @@ -31,4 +35,3 @@ module DriveUtils drives.keys end end - diff --git a/libraries/ip_utils.rb b/libraries/ip_utils.rb index 4b1ed42..5ef7e4f 100644 --- a/libraries/ip_utils.rb +++ b/libraries/ip_utils.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 # # Cookbook Name:: openstack-object-storage # Library:: ip_utils @@ -19,20 +20,20 @@ # Author: Alan Meadows # -require "ipaddr" +require 'ipaddr' +# IPAddress Related Utilities module IPUtils - def locate_ip_in_cidr(network, node) + # TODO(chrislaco) This needs yanked/refactored into common/libraries/network + def locate_ip_in_cidr(network, node) # rubocop:disable MethodLength Chef::Log.debug("Searching for ip within #{network} on node #{node.name}") net = IPAddr.new(network) - node["network"]["interfaces"].each do |interface| - if interface[1].has_key?("addresses") then - interface[1]["addresses"].each do |k,v| - if v["family"] == "inet6" or (v["family"] == "inet" and v["prefixlen"] != "32") then - addr=IPAddr.new(k) - if net.include?(addr) then - return k - end + node['network']['interfaces'].each do |interface| + if interface[1].key?('addresses') + interface[1]['addresses'].each do |k, v| + if v['family'] == 'inet6' || (v['family'] == 'inet' && v['prefixlen'] != '32') + addr = IPAddr.new(k) + return k if net.include?(addr) end end end @@ -40,6 +41,6 @@ module IPUtils error = "Can't find address within network #{network} for node #{node.name}" Chef::Log.error(error) - raise error + fail error end end