Sha256: 7d7998ecd5e23bf53b5b801889985df3ffe30bd473854d993bc461d2f1c2b5da

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 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 :server

        model Fog::AWS::EC2::Volume

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

        def all(volume_id = @volume_id)
          @volume_id = volume_id
          data = connection.describe_volumes(volume_id).body
          load(data['volumeSet'])
          if server
            self.replace(self.select {|volume| volume.server_id == server.id})
          end
        end

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

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

      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fog-0.0.52 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.51 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.50 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.49 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.48 lib/fog/aws/models/ec2/volumes.rb