forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory_collection_default.rb
184 lines (172 loc) · 5.86 KB
/
inventory_collection_default.rb
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
class ManagerRefresh::InventoryCollectionDefault
class << self
def vms(extra_attributes = {})
attributes = {
:model_class => ::Vm,
:association => :vms,
:delete_method => :disconnect_inv,
:attributes_blacklist => [:genealogy_parent],
:use_ar_object => true, # Because of raw_power_state setter and hooks are needed for settings user
# TODO(lsmola) can't do batch strategy for vms because of key_pairs relation
:saver_strategy => :default,
:batch_extra_attributes => [:power_state, :state_changed_on, :previous_state],
:inventory_object_attributes => [
:type,
:cpu_limit,
:cpu_reserve,
:cpu_reserve_expand,
:cpu_shares,
:cpu_shares_level,
:ems_ref,
:ems_ref_obj,
:uid_ems,
:connection_state,
:vendor,
:name,
:location,
:template,
:memory_limit,
:memory_reserve,
:memory_reserve_expand,
:memory_shares,
:memory_shares_level,
:raw_power_state,
:boot_time,
:host,
:ems_cluster,
:storages,
:storage,
:snapshots
],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
:name => "unknown",
:location => "unknown",
}
}
attributes.merge!(extra_attributes)
end
def miq_templates(extra_attributes = {})
attributes = {
:model_class => ::MiqTemplate,
:association => :miq_templates,
:delete_method => :disconnect_inv,
:attributes_blacklist => [:genealogy_parent],
:use_ar_object => true, # Because of raw_power_state setter
:saver_strategy => :default, # Hooks are needed for setting user
:batch_extra_attributes => [:power_state, :state_changed_on, :previous_state],
:inventory_object_attributes => [
:type,
:ems_ref,
:ems_ref_obj,
:uid_ems,
:connection_state,
:vendor,
:name,
:location,
:template,
:memory_limit,
:memory_reserve,
:raw_power_state,
:boot_time,
:host,
:ems_cluster,
:storages,
:storage,
:snapshots
],
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
:name => "unknown",
:location => "unknown",
:template => true
}
}
attributes.merge!(extra_attributes)
end
def hardwares(extra_attributes = {})
attributes = {
:model_class => ::Hardware,
:manager_ref => [:vm_or_template],
:association => :hardwares,
:parent_inventory_collections => [:vms, :miq_templates],
:inventory_object_attributes => [
:annotation,
:cpu_cores_per_socket,
:cpu_sockets,
:cpu_speed,
:cpu_total_cores,
:cpu_type,
:guest_os,
:manufacturer,
:memory_mb,
:model,
:networks,
:number_of_nics,
:serial_number,
:virtual_hw_version
],
# TODO(lsmola) just because of default value on cpu_sockets, this can be fixed by separating instances_hardwares and images_hardwares
:use_ar_object => true,
}
attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.hardwares.joins(:vm_or_template).where(
'vms' => {:ems_ref => manager_uuids}
)
end
attributes.merge!(extra_attributes)
end
def operating_systems(extra_attributes = {})
attributes = {
:model_class => ::OperatingSystem,
:manager_ref => [:vm_or_template],
:association => :operating_systems,
:parent_inventory_collections => [:vms, :miq_templates],
:inventory_object_attributes => [
:name,
:product_name,
:product_type,
:system_type,
:version
],
}
attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.operating_systems.joins(:vm_or_template).where(
'vms' => {:ems_ref => manager_uuids}
)
end
attributes.merge!(extra_attributes)
end
def disks(extra_attributes = {})
attributes = {
:model_class => ::Disk,
:manager_ref => [:hardware, :device_name],
:association => :disks,
:parent_inventory_collections => [:vms],
:inventory_object_attributes => [
:device_name,
:device_type,
:controller_type,
:present,
:filename,
:location,
:size,
:size_on_disk,
:disk_type,
:mode,
:bootable,
:storage
],
}
attributes[:targeted_arel] = lambda do |inventory_collection|
manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a }
inventory_collection.parent.disks.joins(:hardware => :vm_or_template).where(
:hardware => {'vms' => {:ems_ref => manager_uuids}}
)
end
attributes.merge!(extra_attributes)
end
end
end