Sha256: 60413794da869b6398917214897d02928f23dd7fc34d9dfc287422b8994473b5

Contents?: true

Size: 1.38 KB

Versions: 20

Compression:

Stored size: 1.38 KB

Contents

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

module Fog
  module AWS
    module EC2

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

      class Real
        def snapshots(attributes = {})
          Fog::AWS::EC2::Snapshots.new({
            :connection => self
          }.merge!(attributes))
        end
      end

      class Snapshots < Fog::Collection

        attribute :snapshot_id
        attribute :volume

        model Fog::AWS::EC2::Snapshot

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

        def all(snapshot_id = @snapshot_id)
          @snapshot_id = snapshot_id
          data = connection.describe_snapshots(snapshot_id).body
          load(data['snapshotSet'])
          if volume
            self.replace(self.select {|snapshot| snapshot.volume_id == volume.id})
          end
          self
        end

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

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

      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fog-0.0.76 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.75 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.74 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.73 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.72 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.71 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.70 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.69 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.68 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.67 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.66 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.65 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.64 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.63 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.62 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.61 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.60 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.59 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.58 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.57 lib/fog/aws/models/ec2/snapshots.rb