From b8268d37da3759108e6317a764bdf16d42f3b4bd Mon Sep 17 00:00:00 2001 From: Oleg Barenboim Date: Thu, 23 Feb 2017 17:19:17 -0500 Subject: [PATCH] Replace sort_by.last with max_by and sort_by.first with min_by (transferred from ManageIQ/manageiq@4435c061637c81ec9eee541c9463497d0817b2e2) --- .../engine/miq_ae_engine/miq_ae_builtin_method.rb | 2 +- .../Provisioning/WHERE.class/__methods__/least_utilized.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb index b258fb033..67595143a 100644 --- a/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb +++ b/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_builtin_method.rb @@ -93,7 +93,7 @@ def self.miq_host_and_storage_least_utilized(obj, _inputs) nvms = h.vms.collect { |v| v if v.power_state == "on" }.compact.length if min_running_vms.nil? || nvms < min_running_vms storages = h.writable_storages.find_all { |s| s.free_space > vm.provisioned_storage } # Filter out storages that do not have enough free space for the Vm - s = storages.sort_by(&:free_space).last + s = storages.max_by(&:free_space) unless s.nil? result["host"] = h result["storage"] = s diff --git a/spec/data/provision/SPEC_DOMAIN/EVMApplications/Provisioning/WHERE.class/__methods__/least_utilized.rb b/spec/data/provision/SPEC_DOMAIN/EVMApplications/Provisioning/WHERE.class/__methods__/least_utilized.rb index 61e9219e3..4662ade8d 100644 --- a/spec/data/provision/SPEC_DOMAIN/EVMApplications/Provisioning/WHERE.class/__methods__/least_utilized.rb +++ b/spec/data/provision/SPEC_DOMAIN/EVMApplications/Provisioning/WHERE.class/__methods__/least_utilized.rb @@ -13,7 +13,7 @@ next unless h.power_state == "on" nvms = h.vms.length if min_registered_vms.nil? || nvms < min_registered_vms - s = h.storages.sort_by(&:free_space).last + s = h.storages.max_by(&:free_space) unless s.nil? host = h storage = s