Skip to content

Commit

Permalink
Move *_for_request methods into Cloud/Infra classes
Browse files Browse the repository at this point in the history
Cloud and Infra requests use different default quota calculation logic.
  • Loading branch information
jaywcarman committed Oct 27, 2023
1 parent ceea06a commit b458eaa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
12 changes: 12 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,18 @@ def self.display_name(number = 1)
n_('Image', 'Images', number)
end

def memory_for_request(request, flavor_id = nil)
flavor_id ||= request.get_option(:instance_type)
flavor_obj = Flavor.find(flavor_id)
flavor_obj.try(:memory)
end

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

private

def raise_created_event
Expand Down
10 changes: 10 additions & 0 deletions app/models/manageiq/providers/infra_manager/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ def self.display_name(number = 1)
n_('Template', 'Templates', number)
end

def memory_for_request(request, _flavor_id = nil)
memory = request.get_option(:vm_memory).to_i
%w[amazon openstack google].include?(vendor) ? memory : memory.megabytes
end

def number_of_cpus_for_request(request, _flavor_id = nil)
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

def raise_created_event
Expand Down
20 changes: 2 additions & 18 deletions app/models/miq_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,11 @@ def display_deprecated
end

def memory_for_request(request, flavor_id = nil)
flavor_id ||= request.get_option(:instance_type)
flavor_obj = Flavor.find(flavor_id)

memory = flavor_obj.try(:memory) if request.source.try(: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
raise NotImplementedError, _("must be implemented in a subclass")
end

def number_of_cpus_for_request(request, flavor_id = nil)
flavor_id ||= request.get_option(:instance_type)
flavor_obj = Flavor.find(flavor_id)

num_cpus = flavor_obj.try(:cpus) if request.source.try(: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
raise NotImplementedError, _("must be implemented in a subclass")
end

private_class_method def self.refresh_association
Expand Down

0 comments on commit b458eaa

Please sign in to comment.