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