Sha256: f5e8b7b7371225ca9d2d07246755d389db7ab40c0226377c702cf30b49da6d19

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

require 'fog/core/collection'
require 'fog/compute/models/aws/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 = filters, options = {})
          unless filters.is_a?(Hash)
            Formatador.display_line("[yellow][WARN] all with #{filters.class} param is deprecated, use all('snapshot-id' => []) instead[/] [light_black](#{caller.first})[/]")
            filters = {'snapshot-id' => [*filters]}
          end
          self.filters = filters
          data = connection.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(:connection => connection).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

7 entries across 7 versions & 3 rubygems

Version Path
brightbox-cli-0.13.1 lib/brightbox-cli/vendor/fog/lib/fog/compute/models/aws/snapshots.rb
brightbox-cli-0.13.0 lib/brightbox-cli/vendor/fog/lib/fog/compute/models/aws/snapshots.rb
fog-0.11.0 lib/fog/compute/models/aws/snapshots.rb
fog-0.10.0 lib/fog/compute/models/aws/snapshots.rb
fog4encbs-0.9.0.1 lib/fog/compute/models/aws/snapshots.rb
fog4encbs-0.9.0 lib/fog/compute/models/aws/snapshots.rb
fog-0.9.0 lib/fog/compute/models/aws/snapshots.rb