Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Using the new tag mapping for graph refresh #384

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,51 @@ 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 = {
:name => tag["key"],
:value => tag["value"],
}
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<Tag> 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]
Copy link
Contributor

@Ladas Ladas Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are no @inv_collections[key]

first, you need to add the inv collection as @cben is doing it https://github.com/ManageIQ/manageiq-providers-kubernetes/pull/162/files#diff-26f0b75803f05ef203ec5099294834dfR380
then the collection will be here as in @collections

then call it e.g. as persister.taggings_for_vm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw. NoMethodError: undefined method `[]' for nil:NilClass is because @inv_collections are nil

We have @collections here, but we should not access it directly, that is why we call it as persister.collection_name

But unless you place it on @collections[collection.name] = InventoryCollection.new..., it will not be there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the taggings collections can be added in app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb similar to vm_and_template_labels (and called from https://github.com/Ladas/manageiq-providers-amazon/blob/f9123d84236a66348c4bd05d499c74f94f6d7594/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb#L5)
playing with that now...

Also need to add persistor.add_inventory_collection(@tag_mapper.tags_to_resolve_collection) somewhere.

Copy link
Contributor

@Ladas Ladas Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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']),
Expand Down