2010-10-04 14:02:08 -07:00
|
|
|
require 'fog/core/model'
|
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 Snapshot < Fog::Model
|
|
|
|
|
2010-09-07 11:30:02 -07:00
|
|
|
identity :id, :aliases => 'snapshotId'
|
2009-10-23 22:23:55 -07:00
|
|
|
|
2010-05-08 18:22:43 -07:00
|
|
|
attribute :description
|
2009-09-06 10:48:12 -07:00
|
|
|
attribute :progress
|
2010-09-07 11:30:02 -07:00
|
|
|
attribute :created_at, :aliases => 'startTime'
|
|
|
|
attribute :owner_id, :aliases => 'ownerId'
|
|
|
|
attribute :state, :aliases => 'status'
|
2010-10-12 11:00:59 -07:00
|
|
|
attribute :tags, :aliases => 'tagSet'
|
2010-09-07 11:30:02 -07:00
|
|
|
attribute :volume_id, :aliases => 'volumeId'
|
|
|
|
attribute :volume_size, :aliases => 'volumeSize'
|
2009-09-06 10:48:12 -07:00
|
|
|
|
2009-09-20 09:21:03 -07:00
|
|
|
def destroy
|
2009-12-05 14:53:42 -08:00
|
|
|
requires :id
|
2009-11-21 13:56:39 -08:00
|
|
|
|
2010-11-19 13:45:45 -08:00
|
|
|
connection.delete_snapshot(id)
|
2009-09-06 10:48:12 -07:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-04-23 14:07:49 -07:00
|
|
|
def ready?
|
2010-04-26 12:25:21 -07:00
|
|
|
state == 'completed'
|
2010-04-23 14:07:49 -07:00
|
|
|
end
|
|
|
|
|
2009-09-06 10:48:12 -07:00
|
|
|
def save
|
2010-10-04 16:08:34 -07:00
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :volume_id
|
|
|
|
|
2010-11-19 13:45:45 -08:00
|
|
|
data = connection.create_snapshot(volume_id, description).body
|
2009-09-06 10:48:12 -07:00
|
|
|
new_attributes = data.reject {|key,value| key == 'requestId'}
|
2009-09-29 22:02:33 -07:00
|
|
|
merge_attributes(new_attributes)
|
2009-09-06 10:48:12 -07:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-10-11 13:40:34 -07:00
|
|
|
def volume
|
|
|
|
requires :id
|
2010-11-19 13:45:45 -08:00
|
|
|
connection.describe_volumes(volume_id)
|
2009-09-06 10:48:12 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def volume=(new_volume)
|
2010-11-19 13:45:45 -08:00
|
|
|
self.volume_id = new_volume.volume_id
|
2009-09-06 10:48:12 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|