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 9, 2017
1 parent 4eceeed commit 7a8bed4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def parse_image(image, is_public)
:vendor => "amazon",
:raw_power_state => "never",
:template => true,
:labels => parse_labels(image.tags),
# 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 @@ -231,7 +232,7 @@ def parse_instance(instance)
:vendor => "amazon",
:raw_power_state => status,
:boot_time => instance.launch_time,

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

def parse_labels(tags)
result = []
return result if tags.empty?
tags.each do |tag|
custom_attr = {
:section => 'labels',
:name => tag[:key],
:value => tag[:value],
:source => 'amazon'
}
result << custom_attr
end

result
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def expected_table_counts
:availability_zone => 5,
:cloud_network => 5,
:cloud_subnet => 10,
:custom_attribute => 0,
:custom_attribute => 43,
:disk => 44,
:ext_management_system => 4,
:firewall_rule => 119,
Expand Down 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 All @@ -358,7 +358,7 @@ def assert_specific_vm_powered_on
.to match_array [sg_2, @sg]

expect(v.operating_system).to be_nil # TODO: This should probably not be nil
expect(v.custom_attributes.size).to eq(0)
expect(v.custom_attributes.size).to eq(1)
expect(v.snapshots.size).to eq(0)

expect(v.hardware).to have_attributes(
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").value).to eq("EmsRefreshSpec-PoweredOn-Basic3")
end

def assert_specific_vm_powered_off
Expand Down Expand Up @@ -443,7 +444,7 @@ def assert_specific_vm_powered_off
expect(v.cloud_subnet).to be_nil
expect(v.security_groups).to match_array([@sg])
expect(v.operating_system).to be_nil # TODO: This should probably not be nil
expect(v.custom_attributes.size).to eq(0)
expect(v.custom_attributes.size).to eq(1)
expect(v.snapshots.size).to eq(0)

expect(v.hardware).to have_attributes(
Expand Down

0 comments on commit 7a8bed4

Please sign in to comment.