Skip to content

Commit

Permalink
Tag mapping in graph refresh: assign Taggings
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Cheal authored and cben committed Jan 3, 2018
1 parent 8468ba4 commit bfb0cdf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Tag> 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']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bfb0cdf

Please sign in to comment.