forked from ManageIQ/manageiq-providers-amazon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtargets.rb
51 lines (41 loc) · 1.86 KB
/
targets.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
class ManageIQ::Providers::Amazon::Inventory::Targets < ManageIQ::Providers::Amazon::Inventory
include ManageIQ::Providers::Amazon::Inventory::InventoryCollectionDefaultInitData
protected
def initialize_inventory_collections
raise "initialize_inventory_collections must be defined in a subclass"
end
def add_inventory_collection(inventory_collection_data, key = nil)
model_class, data = inventory_collection_data
data[:parent] ||= ems
key ||= data[:association]
inventory_collections[key] = ::ManagerRefresh::InventoryCollection.new(model_class, data)
end
def add_inventory_collections(inventory_collections, inventory_collections_data = {})
inventory_collections.each do |inventory_collection|
add_inventory_collection(send("#{inventory_collection}_init_data", inventory_collections_data))
end
end
def add_remaining_inventory_collections(inventory_collections_data)
# Get names of all inventory collections defined in InventoryCollectionDefaultInitData
all_inventory_collections = ManageIQ::Providers::Amazon::Inventory::InventoryCollectionDefaultInitData.
public_instance_methods.grep(/.+_init_data/).map { |x| x.to_s.gsub("_init_data", "") }
# Get names of all defined inventory_collections
defined_inventory_collections = inventory_collections.keys.map(&:to_s)
# Add all missing inventory_collections with defined init_data
add_inventory_collections(all_inventory_collections - defined_inventory_collections,
inventory_collections_data)
end
def event_payload(event)
transform_keys(event[:full_data]["configurationItem"]["configuration"])
end
def transform_keys(value)
case value
when Array
value.map { |x| transform_keys(x) }
when Hash
Hash[value.map { |k, v| [k.to_s.underscore, transform_keys(v)] }]
else
value
end
end
end