1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/compute/snapshots.rb

53 lines
1.3 KiB
Ruby
Raw Normal View History

2010-10-04 17:02:08 -04:00
require 'fog/core/collection'
require 'fog/aws/models/compute/snapshot'
2010-03-16 18:46:21 -04:00
2009-09-06 13:48:12 -04:00
module Fog
module Compute
class AWS
2009-09-06 13:48:12 -04:00
class Snapshots < Fog::Collection
attribute :filters
attribute :volume
2009-09-24 22:18:41 -04:00
model Fog::Compute::AWS::Snapshot
def initialize(attributes)
self.filters ||= { 'RestorableBy' => 'self' }
super
end
def all(filters = filters, options = {})
unless filters.is_a?(Hash)
Fog::Logger.deprecation("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 = service.describe_snapshots(filters.merge!(options)).body
load(data['snapshotSet'])
if volume
self.replace(self.select {|snapshot| snapshot.volume_id == volume.id})
2009-09-30 01:02:33 -04:00
end
self
2009-09-06 13:48:12 -04:00
end
2009-09-24 22:18:41 -04:00
def get(snapshot_id)
2009-10-22 23:46:15 -04:00
if snapshot_id
self.class.new(:service => service).all('snapshot-id' => snapshot_id).first
2009-10-22 23:46:15 -04:00
end
2009-09-24 22:18:41 -04:00
end
2009-09-06 13:48:12 -04:00
def new(attributes = {})
if volume
super({ 'volumeId' => volume.id }.merge!(attributes))
else
super
2009-09-30 01:02:33 -04:00
end
2009-09-06 13:48:12 -04:00
end
end
end
end
end