Sha256: 8ce4d279d91776d87e1e190c5191e6a3f52eb98012e8de08ef78274a30f8e648

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 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

        model Fog::AWS::EC2::Snapshot

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

        def all(snapshot_id = @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({
              :collection => snapshots,
              :connection => connection
            }.merge!(snapshot))
          end
          if volume
            snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume.id}
          end
          snapshots
        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

6 entries across 6 versions & 1 rubygems

Version Path
fog-0.0.38 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.37 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.36 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.35 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.34 lib/fog/aws/models/ec2/snapshots.rb
fog-0.0.33 lib/fog/aws/models/ec2/snapshots.rb