Class: Specinfra::Ec2Metadata::Tags

Inherits:
Object
  • Object
show all
Defined in:
lib/specinfra/ec2_metadata/tags.rb,
lib/specinfra/ec2_metadata/tags/version.rb

Constant Summary collapse

VERSION =
"0.0.5"

Instance Method Summary collapse

Constructor Details

#initialize(host_inventory) ⇒ Tags

Returns a new instance of Tags.



7
8
9
# File 'lib/specinfra/ec2_metadata/tags.rb', line 7

def initialize(host_inventory)
  @host_inventory = host_inventory
end

Instance Method Details

#getObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/specinfra/ec2_metadata/tags.rb', line 11

def get
  region = @host_inventory['ec2']['placement']['availability-zone'].gsub(/[a-z]$/, '')
  ec2 = Aws::EC2::Client.new(:region => region)
  page = ec2.describe_tags(
    :filters => [{
      :name   => 'resource-id',
      :values => [ @host_inventory['ec2']['instance-id'] ],
    }]
  )
  tags = {}
  page.each do |p|
    page.tags.each do |t|
      tags[t['key']] = t['value']
    end
  end
  tags
end