Sha256: 53b6d36bce3b27b71e62d32ccdddd0c9b84ad78de62474cd284eb0c03c1f8bf3

Contents?: true

Size: 1.5 KB

Versions: 33

Compression:

Stored size: 1.5 KB

Contents

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

module Fog
  module AWS
    module EC2

      module Collections
        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 Fog::Errors::NotFound
          nil
        end

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

      end

    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
fog-0.2.30 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.28 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.27 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.26 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.25 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.24 lib/fog/aws/models/ec2/snapshots.rb
tecnh-fog-0.2.23.vpc lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.23 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.22 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.21 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.20 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.19 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.18 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.17 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.16 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.15 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.14 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.13 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.12 lib/fog/aws/models/ec2/snapshots.rb
fog-0.2.11 lib/fog/aws/models/ec2/snapshots.rb