Skip to content

Commit

Permalink
Ported saving AWS labels to the custom attributes table
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronagh Sorota committed Mar 10, 2017
1 parent 2c950a7 commit 52b0f27
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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) }
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 52b0f27

Please sign in to comment.