Skip to content

Commit

Permalink
Fix cloud provision quota memory and cpu counting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jaywcarman committed May 19, 2023
1 parent bd95166 commit ac87c1f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/models/mixins/miq_provision_quota_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ def flavor(request)
end

def number_of_cpus(prov, cloud, flavor_obj)
return flavor_obj.try(:cpus) if cloud
if cloud
num_cpus = flavor_obj.try(:cpus)
return num_cpus unless num_cpus.nil?
end

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
Expand All @@ -384,7 +388,11 @@ def storage(prov, cloud, vendor, flavor_obj = nil)
end

def memory(prov, cloud, vendor, flavor_obj = nil)
return flavor_obj.try(:memory) if cloud
if cloud
memory = flavor_obj.try(:memory)
return memory unless memory.nil?
end

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
Expand Down

0 comments on commit ac87c1f

Please sign in to comment.