2010-03-16 18:46:21 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class AWS
|
2010-03-16 18:46:21 -04:00
|
|
|
class Real
|
2009-08-20 22:26:14 -04:00
|
|
|
|
2011-08-24 21:37:00 -04:00
|
|
|
require 'fog/aws/parsers/compute/create_snapshot'
|
2010-06-12 18:31:17 -04:00
|
|
|
|
2009-08-20 22:26:14 -04: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 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-20 22:26:14 -04: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 12:31:56 -04:00
|
|
|
#
|
|
|
|
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSnapshot.html]
|
2010-05-08 18:16:35 -04:00
|
|
|
def create_snapshot(volume_id, description = nil)
|
2010-03-16 01:15:33 -04:00
|
|
|
request(
|
2010-05-08 18:16:35 -04:00
|
|
|
'Action' => 'CreateSnapshot',
|
|
|
|
'Description' => description,
|
|
|
|
'VolumeId' => volume_id,
|
2011-06-16 19:28:54 -04:00
|
|
|
:parser => Fog::Parsers::Compute::AWS::CreateSnapshot.new
|
2010-03-16 01:15:33 -04:00
|
|
|
)
|
2009-08-20 22:26:14 -04:00
|
|
|
end
|
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
|
2010-03-16 18:46:21 -04:00
|
|
|
class Mock
|
2011-10-06 16:49:28 -04:00
|
|
|
|
2010-11-29 18:44:44 -05:00
|
|
|
#
|
|
|
|
# Usage
|
|
|
|
#
|
|
|
|
# AWS[:compute].create_snapshot("vol-f7c23423", "latest snapshot")
|
|
|
|
#
|
2011-10-06 16:49:28 -04:00
|
|
|
|
2010-05-08 21:13:33 -04:00
|
|
|
def create_snapshot(volume_id, description = nil)
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2011-05-19 18:35:33 -04:00
|
|
|
if volume = self.data[:volumes][volume_id]
|
2009-08-20 22:26:14 -04:00
|
|
|
response.status = 200
|
|
|
|
snapshot_id = Fog::AWS::Mock.snapshot_id
|
|
|
|
data = {
|
2010-05-08 21:13:33 -04:00
|
|
|
'description' => description,
|
2011-05-19 18:35:33 -04:00
|
|
|
'ownerId' => self.data[:owner_id],
|
2010-05-05 17:22:22 -04:00
|
|
|
'progress' => nil,
|
2009-08-20 22:26:14 -04:00
|
|
|
'snapshotId' => snapshot_id,
|
|
|
|
'startTime' => Time.now,
|
|
|
|
'status' => 'pending',
|
2010-05-08 21:13:33 -04:00
|
|
|
'volumeId' => volume_id,
|
|
|
|
'volumeSize' => volume['size']
|
2009-08-20 22:26:14 -04:00
|
|
|
}
|
2011-05-19 18:35:33 -04:00
|
|
|
self.data[:snapshots][snapshot_id] = data
|
2009-08-20 22:26:14 -04:00
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id
|
|
|
|
}.merge!(data)
|
|
|
|
else
|
|
|
|
response.status = 400
|
2009-11-20 14:08:08 -05:00
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
2009-08-20 22:26:14 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|