Sha256: 746085abb940b27a657fda145e426d0e432ed96a63b808d30a7946080a67543b

Contents?: true

Size: 1.67 KB

Versions: 21

Compression:

Stored size: 1.67 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 :owner,         'Owner'
        attribute :restorable_by, 'RestorableBy'
        attribute :snapshot_id
        attribute :volume

        model Fog::AWS::EC2::Snapshot

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

        def all(snapshot_id = @snapshot_id, options = {})
          options = {
            'Owner' => @owner || 'self',
            'RestorableBy' => @restorable_by
          }
          options = options.reject {|key,value| value.nil? || value.to_s.empty?}
          merge_attributes(options)
          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({ 'volumeId' => volume.id }.merge!(attributes))
          else
            super
          end
        end

      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

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