Module: Awspec::Helper::Finder::Ebs

Included in:
Awspec::Helper::Finder
Defined in:
lib/awspec/helper/finder/ebs.rb

Instance Method Summary collapse

Instance Method Details

#find_ebs(volume_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/awspec/helper/finder/ebs.rb', line 6

def find_ebs(volume_id)
  res = ec2_client.describe_volumes({
                                      filters: [{ name: 'volume-id', values: [volume_id] }]
                                    })
  resource = res.volumes.single_resource(volume_id)
  return resource if resource

  res = ec2_client.describe_volumes({
                                      filters: [{ name: 'tag:Name', values: [volume_id] }]
                                    })
  res.volumes.single_resource(volume_id)
end

#select_all_attached_ebsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/awspec/helper/finder/ebs.rb', line 31

def select_all_attached_ebs
  selected = []
  res = ec2_client.describe_volumes

  loop do
    selected += res.volumes.select { |v| v.attachments.count > 0 }
    break if res.next_token.nil?

    res = ec2_client.describe_volumes({
                                        next_token: res.next_token
                                      })
  end

  selected
end

#select_ebs_by_instance_id(id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/awspec/helper/finder/ebs.rb', line 19

def select_ebs_by_instance_id(id)
  res = find_ec2(id)
  volumes = []
  return volumes unless res

  res.block_device_mappings.each do |block|
    volume = find_ebs(block.ebs.volume_id)
    volumes.push(volume) if volume
  end
  volumes
end