From 8c04616b77bc05139642ed24baf11ab80f6b4df0 Mon Sep 17 00:00:00 2001 From: Jay Carman Date: Fri, 19 May 2023 08:01:01 -0500 Subject: [PATCH] Fix cloud provision quota memory and cpu counting Cloud providers are not required to use flavors to set VM memory and cpu allocation during provisioning (for example IbmCloud::PowerVirtualServers::CloudManager). These 'number_of_cpus' and 'memory' methods are expected to return int values. In the case where a 'cloud' type provision is associated with a flavor without 'memory' or 'cpus' values the non-cloud logic is better than returning nil. Depending on how the provider implements the provision request, the return value will be something useful or just 0, avoiding raising an exception. --- app/models/mixins/miq_provision_quota_mixin.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/mixins/miq_provision_quota_mixin.rb b/app/models/mixins/miq_provision_quota_mixin.rb index e0de52edd6d..5f3edda1df4 100644 --- a/app/models/mixins/miq_provision_quota_mixin.rb +++ b/app/models/mixins/miq_provision_quota_mixin.rb @@ -365,7 +365,9 @@ def flavor(request) end def number_of_cpus(prov, cloud, flavor_obj) - return flavor_obj.try(:cpus) if cloud + num_cpus = flavor_obj.try(:cpus) if cloud + return num_cpus if num_cpus.present? + request = prov.kind_of?(MiqRequest) ? prov : prov.miq_request num_cpus = request.get_option(:number_of_sockets).to_i * request.get_option(:cores_per_socket).to_i num_cpus.zero? ? request.get_option(:number_of_cpus).to_i : num_cpus @@ -384,7 +386,9 @@ def storage(prov, cloud, vendor, flavor_obj = nil) end def memory(prov, cloud, vendor, flavor_obj = nil) - return flavor_obj.try(:memory) if cloud + memory = flavor_obj.try(:memory) if cloud + return memory if memory.present? + request = prov.kind_of?(MiqRequest) ? prov : prov.miq_request memory = request.get_option(:vm_memory).to_i %w(amazon openstack google).include?(vendor) ? memory : memory.megabytes