Sha256: 371fe0badfc8fe4f90e5417cda1a7625861ba4f243d2625b91efead38869105b

Contents?: true

Size: 1.33 KB

Versions: 28

Compression:

Stored size: 1.33 KB

Contents

module Awspec::Helper
  module Finder
    module Ebs
      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

      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

      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
    end
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
awspec-1.25.1 lib/awspec/helper/finder/ebs.rb
awspec-1.25.0 lib/awspec/helper/finder/ebs.rb
awspec-1.24.4 lib/awspec/helper/finder/ebs.rb
awspec-1.24.3 lib/awspec/helper/finder/ebs.rb
awspec-1.24.2 lib/awspec/helper/finder/ebs.rb
awspec-1.24.1 lib/awspec/helper/finder/ebs.rb
awspec-1.24.0 lib/awspec/helper/finder/ebs.rb
awspec-1.23.0 lib/awspec/helper/finder/ebs.rb
awspec-1.22.1 lib/awspec/helper/finder/ebs.rb
awspec-1.22.0 lib/awspec/helper/finder/ebs.rb
awspec-1.21.1 lib/awspec/helper/finder/ebs.rb
awspec-1.21.0 lib/awspec/helper/finder/ebs.rb
awspec-1.20.0 lib/awspec/helper/finder/ebs.rb
awspec-1.19.2 lib/awspec/helper/finder/ebs.rb
awspec-1.19.1 lib/awspec/helper/finder/ebs.rb
awspec-1.19.0 lib/awspec/helper/finder/ebs.rb
cthiesfork-awspec-1.2.4 lib/awspec/helper/finder/ebs.rb
awspec-api_gateway_extended-1.2.4 lib/awspec/helper/finder/ebs.rb
awspec-api_gateway_extended-1.2.3 lib/awspec/helper/finder/ebs.rb
awspec-1.18.6 lib/awspec/helper/finder/ebs.rb