Sha256: 8e0617a72401716f4a5d8b59f8471f760cb6bcc1b61bf6f42a4f87bcf1d6b7d3

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require 'fog/core/collection'
require 'fog/aws/models/compute/snapshot'

module Fog
  module Compute
    class AWS
      class Snapshots < Fog::Collection
        attribute :filters
        attribute :volume

        model Fog::Compute::AWS::Snapshot

        def initialize(attributes)
          self.filters ||= { 'RestorableBy' => 'self' }
          super
        end

        def all(filters_arg = filters, options = {})
          unless filters_arg.is_a?(Hash)
            Fog::Logger.deprecation("all with #{filters_arg.class} param is deprecated, use all('snapshot-id' => []) instead [light_black](#{caller.first})[/]")
            filters_arg = {'snapshot-id' => [*filters_arg]}
          end
          filters = filters_arg
          data = service.describe_snapshots(filters.merge!(options)).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
            self.class.new(:service => service).all('snapshot-id' => snapshot_id).first
          end
        end

        def new(attributes = {})
          if volume
            super({ 'volumeId' => 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-aws-0.1.1 lib/fog/aws/models/compute/snapshots.rb
fog-aws-0.1.0 lib/fog/aws/models/compute/snapshots.rb
fog-aws-0.0.8 lib/fog/aws/models/compute/snapshots.rb
fog-aws-0.0.7 lib/fog/aws/models/compute/snapshots.rb
fog-aws-0.0.6 lib/fog/aws/models/compute/snapshots.rb
fog-aws-0.0.5 lib/fog/aws/models/compute/snapshots.rb