Sha256: 4012a36ec5a1d83467bdf5964f51416d4a12b03bebe1dfef11d4279b7362d134

Contents?: true

Size: 1.66 KB

Versions: 16

Compression:

Stored size: 1.66 KB

Contents

module Fog
  module AWS
    class EC2

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

      class Snapshots < Fog::Collection

        attribute :snapshot_id
        attribute :volume_id

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

        def all(snapshot_id = [])
          data = connection.describe_snapshots(snapshot_id).body
          snapshots = Fog::AWS::EC2::Snapshots.new({
            :connection   => connection,
            :snapshot_id  => snapshot_id
          }.merge!(attributes))
          data['snapshotSet'].each do |snapshot|
            snapshots << Fog::AWS::EC2::Snapshot.new({
              :connection => connection,
              :snapshots  => self
            }.merge!(snapshot))
          end
          if volume_id
            snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume_id}
          end
          snapshots
        end

        def create(attributes = {})
          snapshot = new(attributes)
          snapshot.save
          snapshot
        end

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

        def new(attributes = {})
          snapshot = Fog::AWS::EC2::Snapshot.new(
            attributes.merge!(
              :connection => connection,
              :snapshots  => self
            )
          )
          if volume_id
            snapshot.volume_id = volume_id
          end
          snapshot
        end

        def reload
          all(snapshot_id)
        end

      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
fog-0.0.25 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.24 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.23 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.22 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.21 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.20 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.19 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.18 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.17 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.16 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.15 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.14 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.13 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.12 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.11 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.10 lib/fog/aws/models/ec2/snapshots.rb