Skip to content

Commit

Permalink
Move 'number_of_cpus' into MiqTemplate classes
Browse files Browse the repository at this point in the history
Move method calculating the number of cpus for a given request into
MiqTemplate base class, and then override it in the
ManageIQ::Providers::CloudManager::Template subclass.
  • Loading branch information
jaywcarman committed Aug 22, 2023
1 parent 41533f9 commit 07ad68d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions app/models/manageiq/providers/cloud_manager/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def self.display_name(number = 1)
n_('Image', 'Images', number)
end

def number_of_cpus_for_request(request)
flavor_obj = Flavor.find(request.get_option(:instance_type))
flavor_obj.try(:cpus)
end

private

def raise_created_event
Expand Down
6 changes: 6 additions & 0 deletions app/models/miq_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def display_deprecated
end
end

def number_of_cpus_for_request(request)
request = request.source.kind_of?(MiqRequest) ? request.source : request.source.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
end

private_class_method def self.refresh_association
:miq_templates
end
Expand Down
13 changes: 2 additions & 11 deletions app/models/mixins/miq_provision_quota_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def vm_quota_values(pr, result)
flavor_obj = flavor(pr)
result[:count] += num_vms_for_request
result[:memory] += memory(pr, cloud?(pr), vendor(pr), flavor_obj) * num_vms_for_request
result[:cpu] += number_of_cpus(pr, cloud?(pr), flavor_obj) * num_vms_for_request
result[:cpu] += pr.source.number_of_cpus_for_request(pr) * num_vms_for_request
result[:storage] += storage(pr, cloud?(pr), vendor(pr), flavor_obj) * num_vms_for_request
result[:ids] << pr.id

Expand All @@ -303,7 +303,7 @@ def vm_quota_values(pr, result)
host_id, storage_id = p.get_option(:dest_host).to_i, p.get_option(:dest_storage).to_i
active = result[:active]
active[:memory_by_host_id][host_id] += memory(p, cloud?(pr), vendor(pr), flavor_obj)
active[:cpu_by_host_id][host_id] += number_of_cpus(p, cloud?(pr), flavor_obj)
active[:cpu_by_host_id][host_id] += pr.source.number_of_cpus_for_request(pr)
active[:storage_by_id][storage_id] += storage(p, cloud?(pr), vendor(pr), flavor_obj)
active[:vms_by_storage_id][storage_id] << p.id
active[:ids] << p.id
Expand Down Expand Up @@ -364,15 +364,6 @@ def flavor(request)
Flavor.find(request.get_option(:instance_type)) if cloud?(request)
end

def number_of_cpus(prov, cloud, flavor_obj)
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
end

def storage(prov, cloud, vendor, flavor_obj = nil)
if cloud
if vendor == 'google'
Expand Down

0 comments on commit 07ad68d

Please sign in to comment.