2010-03-16 15:46:21 -07:00
|
|
|
module Fog
|
2011-06-16 16:28:54 -07:00
|
|
|
module Compute
|
|
|
|
class AWS
|
2010-03-16 15:46:21 -07:00
|
|
|
class Real
|
2009-08-20 19:26:14 -07:00
|
|
|
|
2011-08-24 20:37:00 -05:00
|
|
|
require 'fog/aws/parsers/compute/create_snapshot'
|
2010-06-12 15:31:17 -07:00
|
|
|
|
2009-08-20 19:26:14 -07:00
|
|
|
# Create a snapshot of an EBS volume and store it in S3
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * volume_id<~String> - Id of EBS volume to snapshot
|
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 18:48:49 -08:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-20 19:26:14 -07:00
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'progress'<~String> - The percentage progress of the snapshot
|
|
|
|
# * 'requestId'<~String> - id of request
|
|
|
|
# * 'snapshotId'<~String> - id of snapshot
|
|
|
|
# * 'startTime'<~Time> - timestamp when snapshot was initiated
|
|
|
|
# * 'status'<~String> - state of snapshot
|
|
|
|
# * 'volumeId'<~String> - id of volume snapshot targets
|
2011-05-19 09:31:56 -07:00
|
|
|
#
|
|
|
|
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSnapshot.html]
|
2010-05-08 15:16:35 -07:00
|
|
|
def create_snapshot(volume_id, description = nil)
|
2010-03-15 22:15:33 -07:00
|
|
|
request(
|
2010-05-08 15:16:35 -07:00
|
|
|
'Action' => 'CreateSnapshot',
|
|
|
|
'Description' => description,
|
|
|
|
'VolumeId' => volume_id,
|
2011-06-16 16:28:54 -07:00
|
|
|
:parser => Fog::Parsers::Compute::AWS::CreateSnapshot.new
|
2010-03-15 22:15:33 -07:00
|
|
|
)
|
2009-08-20 19:26:14 -07:00
|
|
|
end
|
|
|
|
|
2009-07-13 19:14:59 -07:00
|
|
|
end
|
|
|
|
|
2010-03-16 15:46:21 -07:00
|
|
|
class Mock
|
2011-10-06 13:49:28 -07:00
|
|
|
|
2010-11-29 18:44:44 -05:00
|
|
|
#
|
|
|
|
# Usage
|
|
|
|
#
|
|
|
|
# AWS[:compute].create_snapshot("vol-f7c23423", "latest snapshot")
|
|
|
|
#
|
2011-10-06 13:49:28 -07:00
|
|
|
|
2010-05-08 18:13:33 -07:00
|
|
|
def create_snapshot(volume_id, description = nil)
|
2009-11-20 11:08:08 -08:00
|
|
|
response = Excon::Response.new
|
2011-05-19 15:35:33 -07:00
|
|
|
if volume = self.data[:volumes][volume_id]
|
2009-08-20 19:26:14 -07:00
|
|
|
response.status = 200
|
|
|
|
snapshot_id = Fog::AWS::Mock.snapshot_id
|
|
|
|
data = {
|
2010-05-08 18:13:33 -07:00
|
|
|
'description' => description,
|
2011-05-19 15:35:33 -07:00
|
|
|
'ownerId' => self.data[:owner_id],
|
2010-05-05 14:22:22 -07:00
|
|
|
'progress' => nil,
|
2009-08-20 19:26:14 -07:00
|
|
|
'snapshotId' => snapshot_id,
|
|
|
|
'startTime' => Time.now,
|
|
|
|
'status' => 'pending',
|
2010-05-08 18:13:33 -07:00
|
|
|
'volumeId' => volume_id,
|
|
|
|
'volumeSize' => volume['size']
|
2009-08-20 19:26:14 -07:00
|
|
|
}
|
2011-05-19 15:35:33 -07:00
|
|
|
self.data[:snapshots][snapshot_id] = data
|
2009-08-20 19:26:14 -07:00
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id
|
|
|
|
}.merge!(data)
|
|
|
|
else
|
|
|
|
response.status = 400
|
2009-11-20 11:08:08 -08:00
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
2009-08-20 19:26:14 -07:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 19:14:59 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|