-
Notifications
You must be signed in to change notification settings - Fork 927
Expand file tree
/
Copy pathmiq_template.rb
More file actions
108 lines (87 loc) · 2.76 KB
/
miq_template.rb
File metadata and controls
108 lines (87 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
class MiqTemplate < VmOrTemplate
include CustomActionsMixin
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_tenant, :type => :string
virtual_column :display_deprecated, :type => :string
virtual_column :display_memory, :type => :integer
include Operations
def self.base_model
MiqTemplate
end
# Don't tack on `type IN []` query for the top level classes (default scope already filters out the vms)
def self.finder_needs_type_condition?
self < base_model
end
def self.corresponding_model
module_parent::Vm
end
class << self; alias_method :corresponding_vm_model, :corresponding_model; end
delegate :corresponding_model, :to => :class
alias_method :corresponding_vm_model, :corresponding_model
def scan_via_ems?
true
end
def self.eligible_for_provisioning
where(:type => subclasses_supporting(:provisioning).map(&:name)).active
end
def self.filter_with_name(name)
where(arel_table[:name].matches("%#{name}%"))
end
def self.without_volume_templates
where.not(:type => ["ManageIQ::Providers::Openstack::CloudManager::VolumeTemplate",
"ManageIQ::Providers::Openstack::CloudManager::VolumeSnapshotTemplate"])
end
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_memory
mem_cpu.to_i * 1024 * 1024
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 ? _("true") : _("false")
else
_("N/A")
end
end
private_class_method def self.refresh_association
:miq_templates
end
end