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



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

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/awspec/helper/finder/ebs.rb', line 27

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



16
17
18
19
20
21
22
23
24
25
# File 'lib/awspec/helper/finder/ebs.rb', line 16

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