forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_inventory_object_storage.rb
83 lines (66 loc) · 2.57 KB
/
save_inventory_object_storage.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
#
# Calling order for EmsCloud
# - ems
# - cloud_object_store_containers
# - cloud_object_store_objects
#
module EmsRefresh::SaveInventoryObjectStorage
def save_ems_object_storage_inventory(ems, hashes, target = nil)
target = ems if target.nil?
log_header = "EMS: [#{ems.name}], id: [#{ems.id}]"
# Check if the data coming in reflects a complete removal from the ems
if hashes.blank?
target.disconnect_inv
return
end
_log.info("#{log_header} Saving EMS Object Storage Inventory...")
if debug_trace
require 'yaml'
_log.debug "#{log_header} hashes:\n#{YAML.dump(hashes)}"
end
child_keys = [
:cloud_object_store_containers,
:cloud_object_store_objects,
]
# Save and link other subsections
save_object_storage_child_inventory(ems, hashes, child_keys, target)
ems.save!
hashes[:id] = ems.id
_log.info("#{log_header} Saving EMS Object Storage Inventory...Complete")
ems
end
def save_object_storage_child_inventory(obj, hashes, child_keys, *args)
child_keys.each { |k| send("save_object_storage_#{k}_inventory", obj, hashes[k], *args) if hashes.key?(k) }
end
def save_object_storage_cloud_object_store_containers_inventory(ems, hashes, target = nil)
target = ems if target.nil?
ems.cloud_object_store_containers.reset
deletes = if target == ems
:use_association
else
[]
end
hashes.each do |h|
h[:ems_id] = ems.id
# h[:cloud_tenant_id] = h.fetch_path(:tenant, :id) # TODO: add "unless h[:cloud_tenant_id]" so can be common?
end
save_inventory_multi(ems.cloud_object_store_containers, hashes, deletes, [:ems_ref], nil, :tenant)
store_ids_for_new_records(ems.cloud_object_store_containers, hashes, :ems_ref)
end
def save_object_storage_cloud_object_store_objects_inventory(ems, hashes, target = nil)
target = ems if target.nil?
ems.cloud_object_store_objects.reset
deletes = if target == ems
:use_association
else
[]
end
hashes.each do |h|
h[:ems_id] = ems.id
# h[:cloud_tenant_id] = h.fetch_path(:tenant, :id) # TODO: add "unless h[:cloud_tenant_id]" so can be common?
h[:cloud_object_store_container_id] = h.fetch_path(:container, :id)
end
save_inventory_multi(ems.cloud_object_store_objects, hashes, deletes, [:ems_ref], nil, [:tenant, :container], true)
store_ids_for_new_records(ems.cloud_object_store_objects, hashes, :ems_ref)
end
end