Class: Inventory::Ec2
- Inherits:
-
Base
- Object
- Base
- Inventory::Ec2
show all
- Defined in:
- lib/inventory/ec2.rb
Instance Method Summary
collapse
Methods inherited from Base
eager_load!, inherited, #initialize, #report, #show, #sort, subclasses, #test_mode
#acm, #cfn, #cw, #eb, #ec2, #ecs, #elbv1, #elbv2, #iam, #pricing, #rds, #route53
Methods included from Shared
#instances, #security_groups
Instance Method Details
#cost(instance) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/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 ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/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), group_names,
]
end
end
|
2
3
4
|
# File 'lib/inventory/ec2.rb', line 2
def
["Name", "Instance Id", "Instance Type", "Platform", "Security Groups"]
end
|
#name_from_tag(instance) ⇒ Object
21
22
23
24
25
|
# File 'lib/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
|
39
40
41
|
# File 'lib/inventory/ec2.rb', line 39
def platform(instance)
instance.platform || "linux"
end
|
#security_group_names(instance) ⇒ Object
27
28
29
|
# File 'lib/inventory/ec2.rb', line 27
def security_group_names(instance)
instance.security_groups.map {|sg| sg.group_name}.join(', ')
end
|