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 d90855d59..e8fa70d63 100644 --- a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb @@ -211,6 +211,7 @@ def instances labels = parse_labels(instance["tags"]) tags = map_labels_to_tags("Vm", labels) + vm_and_template_taggings(persister_instance, tags) vm_and_template_labels(persister_instance, instance["tags"] || []) end end @@ -237,6 +238,14 @@ def parse_identifying_attributes(attributes, section, source = "amazon") 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 vm_and_template_taggings(parent, tags_inventory_objects) + tags_inventory_objects.each do |tag| + persister.vm_and_template_taggings.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']), diff --git a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb index fbff77988..2ba877242 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb @@ -2,7 +2,8 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::CloudManager < ManageIQ def initialize_inventory_collections add_inventory_collections( cloud, - %i(vms miq_templates hardwares operating_systems networks disks availability_zones vm_and_template_labels + %i(vms miq_templates hardwares operating_systems networks disks availability_zones + vm_and_template_labels vm_and_template_taggings flavors key_pairs orchestration_stacks orchestration_stacks_resources orchestration_stacks_outputs orchestration_stacks_parameters orchestration_templates) ) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb index 8ebfdfcd6..b55a8f37e 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb @@ -16,8 +16,8 @@ def initialize_inventory_collections # Child models with references in the Parent InventoryCollections for Cloud add_inventory_collections( cloud, - %i(hardwares operating_systems networks disks vm_and_template_labels orchestration_stacks_resources - orchestration_stacks_outputs orchestration_stacks_parameters) + %i(hardwares operating_systems networks disks vm_and_template_labels vm_and_template_taggings + orchestration_stacks_resources orchestration_stacks_outputs orchestration_stacks_parameters) ) add_inventory_collection(cloud.orchestration_templates) diff --git a/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb index 73c268ca9..18be7237d 100644 --- a/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb @@ -176,6 +176,31 @@ def vm_and_template_labels(extra_attributes = {}) attributes.merge!(extra_attributes) end + def vm_and_template_taggings(extra_attributes = {}) + # TODO: make a generic Taggings IC and move it to base class? + attributes = { + :model_class => Tagging, + :association => :vm_and_template_taggings, + :manager_ref => [:taggable, :tag], + :parent_inventory_collections => [:vms, :miq_templates], + :inventory_object_attributes => [ + :taggable, + :tag, + ] + } + + attributes[:targeted_arel] = lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.collect(&:manager_uuids).map(&:to_a).flatten + ems = inventory_collection.parent + ems.vm_and_template_taggings.where( + 'taggable_type' => 'VmOrTemplate', + 'taggable_id' => ems.vms_and_templates(:ems_ref => manager_uuids) + ) + end + + attributes.merge!(extra_attributes) + end + def orchestration_stacks(extra_attributes = {}) attributes = { :model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack,