Skip to content

Commit

Permalink
Merge pull request #17884 from PanSpagetka/add-template-provision-rep…
Browse files Browse the repository at this point in the history
…ort-methods

Add template methods needed for provision report

(cherry picked from commit 67fd66a)

https://bugzilla.redhat.com/show_bug.cgi?id=1610927
  • Loading branch information
martinpovolny authored and simaishi committed Oct 31, 2018
1 parent 26956a0 commit 2b4a340
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions app/models/miq_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ class MiqTemplate < VmOrTemplate

default_scope { where(:template => true) }

virtual_column :display_type, :type => :string
virtual_column :display_operating_system, :type => :string
virtual_column :display_platform, :type => :string
virtual_column :display_cpu_cores, :type => :string
virtual_column :display_memory, :type => :string
virtual_column :display_snapshots, :type => :string
virtual_column :display_tenant, :type => :string
virtual_column :display_deprecated, :type => :string

include_concern 'Operations'

def self.base_model
Expand Down Expand Up @@ -41,4 +50,74 @@ def active?; false; end
def self.display_name(number = 1)
n_('Template and Image', 'Templates and Images', number)
end

def self.non_deprecated
where(:deprecated => false).or(where(:deprecated => nil))
end

def display_type
if respond_to?(:volume_template?)
_("Volume")
elsif respond_to?(:volume_snapshot_template?)
_("Volume Snapshot")
elsif respond_to?(:image?)
image? ? _("Image") : _("Snapshot")
else
_("N/A")
end
end

def display_operating_system
if respond_to?(:volume_template?) || respond_to?(:volume_snapshot_template?)
_("N/A")
else
operating_system.try(:product_name)
end
end

def display_platform
if respond_to?(:volume_template?) || respond_to?(:volume_snapshot_template?)
_("N/A")
else
platform
end
end

def display_cpu_cores
if respond_to?(:volume_template?) || respond_to?(:volume_snapshot_template?)
_("N/A")
else
cpu_total_cores
end
end

def display_memory
if respond_to?(:volume_template?) || respond_to?(:volume_snapshot_template?)
_("N/A")
else
mem_cpu.to_i * 1024 * 1024
end
end

def display_snapshots
if respond_to?(:volume_template?) || respond_to?(:volume_snapshot_template?)
_("N/A")
else
v_total_snapshots
end
end

def display_tenant
respond_to?(:cloud_tenant) ? cloud_tenant.try(:name) : _("N/A")
end

def display_deprecated
if respond_to?(:volume_template?) || respond_to?(:volume_snapshot_template?)
_("N/A")
elsif respond_to?(:deprecated)
_(deprecated.to_s)
else
_("N/A")
end
end
end

0 comments on commit 2b4a340

Please sign in to comment.