forked from RedHatInsights/topological_inventory-amazon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.rb
58 lines (51 loc) · 1.99 KB
/
volume.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module TopologicalInventory::Amazon
class Parser
module Volume
def parse_volumes(data, scope)
stack_id = get_from_tags(data.tags, "aws:cloudformation:stack-id")
stack = lazy_find(:orchestration_stacks, :source_ref => stack_id) if stack_id
volume = TopologicalInventoryIngressApiClient::Volume.new(
:source_ref => data.volume_id,
:name => get_from_tags(data.tags, :name) || data.volume_id,
:state => parse_volume_state(data.state),
:source_created_at => data.create_time,
:size => (data.size || 0) * 1024 ** 3,
:volume_type => lazy_find(:volume_types, :source_ref => data.volume_type),
:source_region => lazy_find(:source_regions, :source_ref => scope[:region]),
:subscription => lazy_find_subscription(scope),
:orchestration_stack => stack,
)
collections[:volumes].data << volume
parse_volume_attachments(data)
end
private
def parse_volume_attachments(data)
(data.attachments || []).each do |attachment|
volume_attachment = TopologicalInventoryIngressApiClient::VolumeAttachment.new(
:volume => lazy_find(:volumes, :source_ref => data.volume_id),
:vm => lazy_find(:vms, :source_ref => attachment.instance_id),
:device => attachment.device,
:state => parse_volume_attachment_state(attachment.state),
)
collections[:volume_attachments].data << volume_attachment
end
end
def parse_volume_state(state)
case state
when "creating", "available", "in-use", "deleting", "deleted", "error"
state
else
"unknown"
end
end
def parse_volume_attachment_state(state)
case state
when "attaching", "attached", "detaching"
state
else
"unknown"
end
end
end
end
end