From 6a212ee93fa1f48b9b62fb043b27c094c5dbfb4f Mon Sep 17 00:00:00 2001 From: Julian Cheal Date: Tue, 2 Jan 2018 16:21:14 +0000 Subject: [PATCH 1/2] Using the new tag mapping for graph refresh --- .../amazon/inventory/parser/cloud_manager.rb | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb index f81f9848c..41584d2e4 100644 --- a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb @@ -199,12 +199,53 @@ def instances ), ) + @tag_mapper = ContainerLabelTagMapping.mapper + + labels = parse_labels(instance["tags"]) + taggings = map_labels_to_tags("Vm", labels) + map_taggings(persister_instance, taggings) + instance_hardware(persister_instance, instance, flavor) instance_operating_system(persister_instance, instance) + vm_and_template_labels(persister_instance, instance["tags"] || []) end end + def parse_labels(entity) + parse_identifying_attributes(entity, 'labels') + end + + def parse_identifying_attributes(attributes, section, source = "amazon") + result = [] + return result if attributes.nil? + attributes.each do |tag| + custom_attr = { + :section => section, + :name => tag["key"], + :value => tag["value"], + :source => source + } + result << custom_attr + end + result + end + + def map_labels_to_tags(model_name, labels) + @tag_mapper.map_labels(model_name, labels) + end + + # Conveniently, the tags map_labels emits are already in InventoryObject form + def map_taggings(parent, tags_inventory_objects) + model_name = parent.inventory_collection.model_class.base_class.name + key = [:taggings_for, model_name] + collection = @inv_collections[key] + raise("can't save: missing @inv_collections[#{key}]") if collection.nil? + tags_inventory_objects.each do |tag| + collection.build(:taggable => parent, :tag => tag) + end + end + def instance_hardware(persister_instance, instance, flavor) persister_hardware = persister.hardwares.find_or_build(persister_instance).assign_attributes( :bitness => architecture_to_bitness(instance['architecture']), From 58c2ab1f4db689fb066c1b3a817d8389239ef2cb Mon Sep 17 00:00:00 2001 From: Julian Cheal Date: Tue, 2 Jan 2018 19:25:54 +0000 Subject: [PATCH 2/2] Removed non-used fields from custom_attrs. --- .../manageiq/providers/amazon/inventory/parser/cloud_manager.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb index 41584d2e4..dc9b9c13b 100644 --- a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb @@ -221,10 +221,8 @@ def parse_identifying_attributes(attributes, section, source = "amazon") return result if attributes.nil? attributes.each do |tag| custom_attr = { - :section => section, :name => tag["key"], :value => tag["value"], - :source => source } result << custom_attr end