class AwsInventory::Ec2

Public Instance Methods

cost(instance) click to toggle source
# File lib/aws_inventory/ec2.rb, line 31
def cost(instance)
  cost_type = COST_MAP[instance.instance_type]
  if cost_type
    cost = cost_type[platform(instance)]
    cost.round(2)
  end
end
data() click to toggle source
# File lib/aws_inventory/ec2.rb, line 6
def data
  instances.map do |i|
    name = name_from_tag(i)
    group_names = security_group_names(i)

    [
      name,
      i.instance_id,
      i.instance_type,
      platform(i), # windows or linux
      group_names,
    ]
  end
end
header() click to toggle source
# File lib/aws_inventory/ec2.rb, line 2
def header
  ["Name", "Instance Id", "Instance Type", "Platform", "Security Groups"]
end
name_from_tag(instance) click to toggle source
# File lib/aws_inventory/ec2.rb, line 21
def name_from_tag(instance)
  tags = instance.tags
  name_tag = tags.find { |t| t.key == "Name" }
  name_tag ? name_tag.value : "(unnamed)"
end
platform(instance) click to toggle source
# File lib/aws_inventory/ec2.rb, line 39
def platform(instance)
  instance.platform || "linux"
end
security_group_names(instance) click to toggle source
# File lib/aws_inventory/ec2.rb, line 27
def security_group_names(instance)
  instance.security_groups.map {|sg| sg.group_name}.join(', ')
end