mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
snapshot mocks
This commit is contained in:
parent
2c25fae5f1
commit
96895338dc
4 changed files with 190 additions and 68 deletions
|
@ -7,7 +7,14 @@ module Fog
|
|||
@data
|
||||
end
|
||||
def self.reset_data
|
||||
@data = { :deleted_at => {}, :addresses => {}, :key_pairs => {}, :security_groups => {}, :volumes => {} }
|
||||
@data = {
|
||||
:deleted_at => {},
|
||||
:addresses => {},
|
||||
:key_pairs => {},
|
||||
:security_groups => {},
|
||||
:snapshots => {},
|
||||
:volumes => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,28 +1,65 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
# Create a snapshot of an EBS volume and store it in S3
|
||||
#
|
||||
# ==== Parameters
|
||||
# * volume_id<~String> - Id of EBS volume to snapshot
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * 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
|
||||
def create_snapshot(volume_id)
|
||||
request({
|
||||
'Action' => 'CreateSnapshot',
|
||||
'VolumeId' => volume_id
|
||||
}, Fog::Parsers::AWS::EC2::CreateSnapshot.new)
|
||||
end
|
||||
|
||||
# Create a snapshot of an EBS volume and store it in S3
|
||||
#
|
||||
# ==== Parameters
|
||||
# * volume_id<~String> - Id of EBS volume to snapshot
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * 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
|
||||
def create_snapshot(volume_id)
|
||||
request({
|
||||
'Action' => 'CreateSnapshot',
|
||||
'VolumeId' => volume_id
|
||||
}, Fog::Parsers::AWS::EC2::CreateSnapshot.new)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def create_snapshot(volume_id)
|
||||
response = Fog::Response.new
|
||||
if Fog::AWS::EC2.data[:volumes][volume_id]
|
||||
response.status = 200
|
||||
snapshot_id = Fog::AWS::Mock.snapshot_id
|
||||
data = {
|
||||
'progress' => '',
|
||||
'snapshotId' => snapshot_id,
|
||||
'startTime' => Time.now,
|
||||
'status' => 'pending',
|
||||
'volumeId' => volume_id
|
||||
}
|
||||
Fog::AWS::EC2.data[:snapshots][snapshot_id] = data
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id
|
||||
}.merge!(data)
|
||||
else
|
||||
response.status = 400
|
||||
raise(Fog::Errors.status_error(200, 400, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,24 +1,53 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
# Delete a snapshot of an EBS volume that you own
|
||||
#
|
||||
# ==== Parameters
|
||||
# * snapshot_id<~String> - ID of snapshot to delete
|
||||
# ==== Returns
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def delete_snapshot(snapshot_id)
|
||||
request({
|
||||
'Action' => 'DeleteSnapshot',
|
||||
'SnapshotId' => snapshot_id
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
end
|
||||
|
||||
# Delete a snapshot of an EBS volume that you own
|
||||
#
|
||||
# ==== Parameters
|
||||
# * snapshot_id<~String> - ID of snapshot to delete
|
||||
# ==== Returns
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'return'<~Boolean> - success?
|
||||
def delete_snapshot(snapshot_id)
|
||||
request({
|
||||
'Action' => 'DeleteSnapshot',
|
||||
'SnapshotId' => snapshot_id
|
||||
}, Fog::Parsers::AWS::EC2::Basic.new)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def delete_snapshot(snapshot_id)
|
||||
response = Fog::Response.new
|
||||
if snapshot = Fog::AWS::EC2.data[:snapshots].delete(snapshot_id)
|
||||
response.status = true
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
else
|
||||
response.status = 400
|
||||
raise(Fog::Errors.status_error(200, 400, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,29 +1,78 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
# Describe all or specified snapshots
|
||||
#
|
||||
# ==== Parameters
|
||||
# * snapshot_id<~Array> - List of snapshots to describe, defaults to all
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'snapshotSet'<~Array>:
|
||||
# * 'progress'<~String>: The percentage progress of the snapshot
|
||||
# * 'snapshotId'<~String>: Id of the snapshot
|
||||
# * 'startTime'<~Time>: Timestamp of when snapshot was initiated
|
||||
# * 'status'<~String>: Snapshot state, in ['pending', 'completed']
|
||||
# * 'volumeId'<~String>: Id of volume that snapshot contains
|
||||
def describe_snapshots(snapshot_id = [])
|
||||
params = indexed_params('SnapshotId', snapshot_id)
|
||||
request({
|
||||
'Action' => 'DescribeSnapshots'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeSnapshots.new)
|
||||
end
|
||||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
# Describe all or specified snapshots
|
||||
#
|
||||
# ==== Parameters
|
||||
# * snapshot_id<~Array> - List of snapshots to describe, defaults to all
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'requestId'<~String> - Id of request
|
||||
# * 'snapshotSet'<~Array>:
|
||||
# * 'progress'<~String>: The percentage progress of the snapshot
|
||||
# * 'snapshotId'<~String>: Id of the snapshot
|
||||
# * 'startTime'<~Time>: Timestamp of when snapshot was initiated
|
||||
# * 'status'<~String>: Snapshot state, in ['pending', 'completed']
|
||||
# * 'volumeId'<~String>: Id of volume that snapshot contains
|
||||
def describe_snapshots(snapshot_id = [])
|
||||
params = indexed_params('SnapshotId', snapshot_id)
|
||||
request({
|
||||
'Action' => 'DescribeSnapshots'
|
||||
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeSnapshots.new)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def describe_snapshots(snapshot_id = [])
|
||||
response = Fog::Response.new
|
||||
snapshot_id = [*snapshot_id]
|
||||
if snapshot_id != []
|
||||
snapshot_set = Fog::AWS::EC2.data[:snapshots].reject {|key,value| !snapshot_id.include?(key)}.values
|
||||
else
|
||||
snapshot_set = Fog::AWS::EC2.data[:snapshots].values
|
||||
end
|
||||
|
||||
snapshot_set.each do |snapshot|
|
||||
case snapshot['status']
|
||||
when 'creating'
|
||||
if Time.now - volume['createTime'] > 2
|
||||
snapshot['progress'] = '100%'
|
||||
snapshot['status'] = 'completed'
|
||||
else
|
||||
snapshot['progress'] = '50%'
|
||||
snapshot['status'] = 'in progress'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if snapshot_id.length == 0 || snapshot_id.length == snapshot_set.length
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'snapshotSet' => snapshot_set
|
||||
}
|
||||
else
|
||||
response.status = 400
|
||||
raise(Fog::Errors.status_error(200, 400, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue