Sha256: fbc7902b71c7948baa17202e173b40c2617b92b93f97b417163cdead7a330eda

Contents?: true

Size: 1.33 KB

Versions: 48

Compression:

Stored size: 1.33 KB

Contents

require 'fog/collection'
require 'fog/aws/models/ec2/volume'

module Fog
  module AWS
    module EC2

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

      class Real
        def volumes(attributes = {})
          Fog::AWS::EC2::Volumes.new({
            :connection => self
          }.merge!(attributes))
        end
      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
          self
        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

48 entries across 48 versions & 1 rubygems

Version Path
fog-0.1.3 lib/fog/aws/models/ec2/volumes.rb
fog-0.1.2 lib/fog/aws/models/ec2/volumes.rb
fog-0.1.1 lib/fog/aws/models/ec2/volumes.rb
fog-0.1.0 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.100 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.99 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.98 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.97 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.96 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.95 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.94 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.93 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.92 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.91 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.90 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.89 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.88 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.87 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.86 lib/fog/aws/models/ec2/volumes.rb
fog-0.0.85 lib/fog/aws/models/ec2/volumes.rb