-
-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from tekken/rds_snapshot_improvements
Rds snapshot improvements
- Loading branch information
Showing
6 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Fog | ||
module Parsers | ||
module AWS | ||
module RDS | ||
require 'fog/aws/parsers/rds/snapshot_parser' | ||
|
||
class CopyDBSnapshot < Fog::Parsers::AWS::RDS::SnapshotParser | ||
def reset | ||
@response = { 'CopyDBSnapshotResult' => {}, 'ResponseMetadata' => {} } | ||
super | ||
end | ||
|
||
def start_element(name, attrs = []) | ||
super | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'DBSnapshot' then | ||
@response['CopyDBSnapshotResult']['DBSnapshot'] = @db_snapshot | ||
@db_snapshot = fresh_snapshot | ||
when 'RequestId' | ||
@response['ResponseMetadata'][name] = value | ||
else | ||
super | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Fog | ||
module Parsers | ||
module AWS | ||
module RDS | ||
class ModifyDbSnapshotAttribute < Fog::Parsers::Base | ||
def reset | ||
@response = { 'ModifyDbSnapshotAttributeResult' => {}, 'ResponseMetadata' => {} } | ||
end | ||
|
||
def start_element(name, attrs = []) | ||
super | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'RequestId' | ||
@response['ResponseMetadata'][name] = value | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Fog | ||
module AWS | ||
class RDS | ||
class Real | ||
require 'fog/aws/parsers/rds/copy_db_snapshot' | ||
|
||
# Copy a db snapshot | ||
# | ||
# ==== Parameters | ||
# * source_db_snapshot_identifier<~String> - Id of db snapshot | ||
# * target_db_snapshot_identifier<~String> - Desired Id of the db snapshot copy | ||
# * 'copy_tags'<~Boolean> - true to copy all tags from the source DB snapshot to the target DB snapshot; otherwise false. | ||
# | ||
# ==== Returns | ||
# * response<~Excon::Response>: | ||
# * body<~Hash>: | ||
# | ||
# {Amazon API Reference}[http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CopyDBSnapshot.html] | ||
def copy_db_snapshot(source_db_snapshot_identifier, target_db_snapshot_identifier, copy_tags = false) | ||
request( | ||
'Action' => 'CopyDBSnapshot', | ||
'SourceDBSnapshotIdentifier' => source_db_snapshot_identifier, | ||
'TargetDBSnapshotIdentifier' => target_db_snapshot_identifier, | ||
'CopyTags' => copy_tags, | ||
:parser => Fog::Parsers::AWS::RDS::CopyDBSnapshot.new | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
# | ||
# Usage | ||
# | ||
# Fog::AWS[:rds].copy_db_snapshot("snap-original-id", "snap-backup-id", true) | ||
# | ||
|
||
def copy_db_snapshot(source_db_snapshot_identifier, target_db_snapshot_identifier, copy_tags = false) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
snapshot_id = Fog::AWS::Mock.snapshot_id | ||
data = { | ||
'snapshotId' => snapshot_id, | ||
} | ||
self.data[:snapshots][snapshot_id] = data | ||
response.body = { | ||
'requestId' => Fog::AWS::Mock.request_id | ||
}.merge!(data) | ||
response | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Fog | ||
module AWS | ||
class RDS | ||
class Real | ||
require 'fog/aws/parsers/rds/modify_db_snapshot_attribute' | ||
|
||
# Modify db snapshot attributes | ||
# | ||
# ==== Parameters | ||
# * db_snapshot_identifier<~String> - Id of snapshot to modify | ||
# * attributes<~Hash>: | ||
# * 'Add.MemberId'<~Array> - One or more account ids to grant rds create permission to | ||
# * 'Remove.MemberId'<~Array> - One or more account ids to revoke rds create permission from | ||
# | ||
# {Amazon API Reference}[http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBSnapshotAttribute.html] | ||
# | ||
def modify_db_snapshot_attribute(db_snapshot_identifier, attributes) | ||
params = {} | ||
params.merge!(Fog::AWS.indexed_param('ValuesToAdd.member.%d', attributes['Add.MemberId'] || [])) | ||
params.merge!(Fog::AWS.indexed_param('ValuesToRemove.member.%d', attributes['Remove.MemberId'] || [])) | ||
request({ | ||
'Action' => 'ModifyDBSnapshotAttribute', | ||
'DBSnapshotIdentifier' => db_snapshot_identifier, | ||
:idempotent => true, | ||
'AttributeName' => "restore", | ||
:parser => Fog::Parsers::AWS::RDS::ModifyDbSnapshotAttribute.new | ||
}.merge!(params)) | ||
end | ||
end | ||
class Mock | ||
# | ||
# Usage | ||
# | ||
# Fog::AWS[:rds].modify_db_snapshot_attribute("snap-identifier", {"Add.MemberId"=>"389480430104"}) | ||
# | ||
|
||
def modify_db_snapshot_attribute(db_snapshot_identifier, attributes) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
response.body = { | ||
'requestId' => Fog::AWS::Mock.request_id | ||
}.merge!(data) | ||
response | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Shindo.tests('Fog::Rds[:aws] | db snapshot requests', ['aws']) do | ||
|
||
@snapshot_format = { | ||
'AllocatedStorage' => Integer, | ||
'AvailabilityZone' => Fog::Nullable::String, | ||
'Engine' => String, | ||
'EngineVersion' => String, | ||
'InstanceCreateTime' => Time, | ||
'DBInstanceIdentifier' => String, | ||
'Iops' => Fog::Nullable::Integer, | ||
'MasterUsername' => String, | ||
'Port' => Fog::Nullable::Integer, | ||
'Status' => String, | ||
'StorageType' => String, | ||
'SnapshotType' => String | ||
} | ||
|
||
@snapshots_format = { | ||
'requestId' => String | ||
} | ||
|
||
@snapshot_copy_result = { | ||
'requestId' => String, | ||
'snapshotId' => String | ||
} | ||
|
||
@rds_identity = "test_rds" | ||
response = Fog::AWS[:rds].create_db_instance(@rds_identity,{ | ||
"DBInstanceClass"=>"db.m3.xlarge", | ||
"Engine"=>"PostgreSQL", | ||
"AllocatedStorage"=>100, | ||
"MasterUserPassword"=>"password", | ||
"MasterUsername"=>"username" | ||
}) | ||
|
||
@rds = Fog::AWS[:rds].servers.get(@rds_identity) | ||
|
||
tests('success') do | ||
@snapshot_id = "testRdsSnapshot" | ||
tests("#create_snapshot(#{@rds.identity})").formats(@snapshot_format) do | ||
Fog::AWS[:rds].create_db_snapshot(@rds.identity,@snapshot_id).body["CreateDBSnapshotResult"]["DBSnapshot"] | ||
end | ||
|
||
Fog.wait_for { Fog::AWS[:rds].snapshots.get(@snapshot_id) } | ||
Fog::AWS[:rds].snapshots.get(@snapshot_id).wait_for { ready? } | ||
|
||
tests("#modify_db_snapshot_attribute").formats(@snapshots_format) do | ||
Fog::AWS[:rds].modify_db_snapshot_attribute(@snapshot_id, {"Add.MemberId"=>["389480430104"]}).body | ||
end | ||
|
||
tests("#copy_db_snapshot (#{@snapshot_id}, target_snapshot_id)").formats(@snapshot_copy_result) do | ||
data = Fog::AWS[:rds].copy_db_snapshot(@snapshot_id, "target_snapshot_id").body | ||
pp data.inspect | ||
data | ||
end | ||
end | ||
tests('failure') do | ||
|
||
tests("#delete_snapshot('snap-00000000')").raises(Fog::AWS::RDS::NotFound) do | ||
Fog::AWS[:rds].delete_db_snapshot(@rds.identity) | ||
end | ||
|
||
end | ||
|
||
@rds.destroy | ||
|
||
end |