2010-10-04 17:02:08 -04:00
require 'fog/core/collection'
2010-09-08 17:40:02 -04:00
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 AWS
2010-09-08 17:40:02 -04:00
class Compute
2009-09-06 13:48:12 -04:00
class Snapshots < Fog :: Collection
2010-10-04 18:46:12 -04:00
attribute :filters
2009-12-05 17:53:42 -05:00
attribute :volume
2009-09-24 22:18:41 -04:00
2010-09-08 17:40:02 -04:00
model Fog :: AWS :: Compute :: Snapshot
2009-10-30 02:35:28 -04:00
2009-09-28 00:31:15 -04:00
def initialize ( attributes )
2010-11-19 16:45:45 -05:00
self . filters || = { 'RestorableBy' = > 'self' }
2009-09-28 00:31:15 -04:00
super
end
2010-11-19 16:45:45 -05:00
def all ( filters = filters , options = { } )
2010-10-11 16:45:26 -04:00
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 ] }
2010-10-04 18:46:12 -04:00
end
2010-11-19 16:45:45 -05:00
self . filters = filters
2010-10-04 18:46:12 -04:00
data = connection . describe_snapshots ( filters . merge! ( options ) ) . body
2010-03-06 23:02:10 -05:00
load ( data [ 'snapshotSet' ] )
2009-12-05 17:53:42 -05:00
if volume
2010-03-06 23:02:10 -05:00
self . replace ( self . select { | snapshot | snapshot . volume_id == volume . id } )
2009-09-30 01:02:33 -04:00
end
2010-03-06 23:02:10 -05:00
self
2009-09-06 13:48:12 -04:00
end
2010-11-29 18:44:44 -05:00
2009-09-24 22:18:41 -04:00
def get ( snapshot_id )
2009-10-22 23:46:15 -04:00
if snapshot_id
2010-10-04 18:46:12 -04:00
self . class . new ( :connection = > connection ) . 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 = { } )
2009-12-05 17:53:42 -05:00
if volume
2010-04-28 14:56:04 -04:00
super ( { 'volumeId' = > volume . id } . merge! ( attributes ) )
2009-12-05 17:53:42 -05:00
else
super
2009-09-30 01:02:33 -04:00
end
2009-09-06 13:48:12 -04:00
end
end
end
end
end