Skip to content

Commit

Permalink
Gather AWS labels and create CustomAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronagh Sorota committed Mar 6, 2017
1 parent a3d0495 commit c4606c8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def parse_image(image, is_public)
name ||= $1 if location =~ /^(.+?)(\.(image|img))?\.manifest\.xml$/
name ||= uid

labels = parse_labels(image)

new_result = {
:type => ManageIQ::Providers::Amazon::CloudManager::Template.name,
:uid_ems => uid,
Expand All @@ -185,6 +187,7 @@ def parse_image(image, is_public)
:vendor => "amazon",
:raw_power_state => "never",
:template => true,
:labels => labels,
# the is_public flag here avoids having to make an additional API call
# per image, since we already know whether it's a public image
:publicly_available => is_public,
Expand Down Expand Up @@ -223,6 +226,8 @@ def parse_instance(instance)
:hostname => instance.public_dns_name.presence
}.delete_nils

labels = parse_labels(instance)

new_result = {
:type => ManageIQ::Providers::Amazon::CloudManager::Vm.name,
:uid_ems => uid,
Expand All @@ -231,7 +236,7 @@ def parse_instance(instance)
:vendor => "amazon",
:raw_power_state => status,
:boot_time => instance.launch_time,

:labels => labels,
:hardware => {
:bitness => architecture_to_bitness(instance.architecture),
:virtualization_type => instance.virtualization_type,
Expand Down Expand Up @@ -387,4 +392,24 @@ def parse_stack_resource(resource)
}
return uid, new_result
end

def parse_labels(entity)
parse_identifying_attributes(entity.tags)
end

def parse_identifying_attributes(attributes)
result = []
return result if attributes.blank?
attributes.each do |struct|
custom_attr = {
:section => 'labels',
:name => struct[:key].to_s,
:value => struct[:value],
:source => 'amazon'
}
result << custom_attr
end

result
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def assert_specific_vm_powered_on
:cpu_reserve_expand => nil,
:cpu_limit => nil,
:cpu_shares => nil,
:cpu_shares_level => nil
:cpu_shares_level => nil,
)

expect(v.ext_management_system).to eq(@ems)
Expand Down Expand Up @@ -403,6 +403,7 @@ def assert_specific_vm_powered_on
v.with_relationship_type("genealogy") do
expect(v.parent).to eq(@template)
end
expect(v.custom_attributes.find_by(:name => "Name")).to eq("EmsRefreshSpec-PoweredOn-Basic3")
end

def assert_specific_vm_powered_off
Expand Down

0 comments on commit c4606c8

Please sign in to comment.