Sha256: 49e3801ae1ae613b97c93a3efb7fd987cbd054f9848c279780e2e3ab0f40461d

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

module Fog
  module AWS
    class EC2

      def volumes(attributes = {})
        Fog::AWS::EC2::Volumes.new({
          :connection => self
        }.merge!(attributes))
      end

      class Volumes < Fog::Collection

        attribute :volume_id
        attribute :instance

        model Fog::AWS::EC2::Volume

        def initialize(attributes)
          @volume_id ||= []
          super
        end

        def all(volume_id = @volume_id)
          data = connection.describe_volumes(volume_id).body
          volumes = Fog::AWS::EC2::Volumes.new({
            :connection => connection,
            :volume_id  => volume_id
          }.merge!(attributes))
          data['volumeSet'].each do |volume|
            volumes << Fog::AWS::EC2::Volume.new({
              :collection => volumes,
              :connection => connection
            }.merge!(volume))
          end
          if instance
            volumes = volumes.select {|volume| volume.instance_id == instance.id}
          end
          volumes
        end

        def get(volume_id)
          if volume_id
            all(volume_id).first
          end
        rescue Excon::Errors::BadRequest
          nil
        end

        def new(attributes = {})
          if instance
            super({ :instance => instance }.merge!(attributes))
          else
            super
          end
        end

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fog-0.0.38 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.37 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.36 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.35 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.34 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.33 lib/fog/aws/models/ec2/volumes.rb