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 b45068656..1f628293f 100644 --- a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb @@ -52,6 +52,7 @@ def get_public_images def get_images(images, is_public = false) process_inventory_collection(images, :miq_templates) do |image| get_image_hardware(image) + get_image_labels(image, image["tags"]) parse_image(image, is_public) end @@ -61,6 +62,13 @@ def get_image_hardware(image) process_inventory_collection([image], :hardwares) { |img| parse_image_hardware(img) } end + def get_image_labels(image, tags) + process_inventory_collection(tags, :vm_or_template_labels) do |tag| + resource = persister.miq_templates.lazy_find(image['image_id']) + parse_label(resource, tag) + end + end + def get_stacks process_inventory_collection(collector.stacks, :orchestration_stacks) do |stack| get_stack_resources(stack) @@ -102,6 +110,7 @@ def get_instances flavor = persister.flavors.find(instance['instance_type']) || persister.flavors.find("unknown") get_instance_hardware(instance, flavor) + get_instance_labels(instance, instance["tags"]) parse_instance(instance, flavor) end @@ -116,6 +125,13 @@ def get_instance_hardware(instance, flavor) end end + def get_instance_labels(instance, tags) + process_inventory_collection(tags, :vm_or_template_labels) do |tag| + resource = persister.vms.lazy_find(instance['instance_id']) + parse_label(resource, tag) + end + end + def get_hardware_networks(instance) process_inventory_collection([instance], :networks) { |i| parse_hardware_private_network(i) } process_inventory_collection([instance], :networks) { |i| parse_hardware_public_network(i) } @@ -368,6 +384,16 @@ def parse_stack_resource(resource, stack) } end + def parse_label(resource, tag) + { + :resource => resource, + :section => 'labels', + :name => tag["key"], + :value => tag["value"], + :source => 'amazon' + } + end + # Overridden helper methods, we should put them in helper once we get rid of old refresh def get_from_tags(resource, item) (resource['tags'] || []).detect { |tag, _| tag['key'].downcase == item.to_s.downcase }.try(:[], 'value') 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 263f8a44d..5a3fbf8c8 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,7 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::CloudManager < ManageIQ def initialize_inventory_collections add_inventory_collections( cloud, - %i(vms miq_templates hardwares networks disks availability_zones + %i(vms miq_templates hardwares networks disks availability_zones vm_or_template_labels 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_collection_default/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb index 63ee3db4a..3c25d9528 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 @@ -39,6 +39,16 @@ def key_pairs(extra_attributes = {}) super(attributes.merge!(extra_attributes)) end + def vm_or_template_labels(extra_attributes = {}) + attributes = { + :model_class => CustomAttribute, + :association => :vm_or_template_labels, + :manager_ref => [:resource, :name] + } + + attributes.merge!(extra_attributes) + end + def orchestration_stacks(extra_attributes = {}) attributes = { :model_class => ::ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack,