1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

promote read replicas

This commit is contained in:
Benjamin Chadwick 2014-04-15 17:33:16 -04:00
parent 911ec7c5a8
commit 1d296d6ee1
3 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,34 @@
module Fog
module Parsers
module AWS
module RDS
require 'fog/aws/parsers/rds/db_parser'
class PromoteReadReplica < Fog::Parsers::AWS::RDS::DbParser
def reset
@response = { 'PromoteReadReplicaResult' => {}, 'ResponseMetadata' => {} }
super
end
def start_element(name, attrs = [])
super
end
def end_element(name)
case name
when 'DBInstance'
@response['PromoteReadReplicaResult']['DBInstance'] = @db_instance
@db_instance = fresh_instance
when 'RequestId'
@response['ResponseMetadata'][name] = value
else
super
end
end
end
end
end
end
end

View file

@ -56,6 +56,8 @@ module Fog
request :describe_db_log_files
request :download_db_logfile_portion
request :promote_read_replica
model_path 'fog/aws/models/rds'
model :server

View file

@ -0,0 +1,61 @@
module Fog
module AWS
class RDS
class Real
require 'fog/aws/parsers/rds/promote_read_replica'
# promote a read replica to a writable RDS instance
# http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_PromoteReadReplica.html
# ==== Parameters
# * DBInstanceIdentifier <~String> - The DB Instance identifier for the DB Instance to be deleted.
# * BackupRetentionPeriod <~Integer> - The number of days to retain automated backups. Range: 0-8.
# Setting this parameter to a positive number enables backups.
# Setting this parameter to 0 disables automated backups.
# * PreferredBackupWindow <~String> - The daily time range during which automated backups are created if
# automated backups are enabled, using the BackupRetentionPeriod parameter.
# Default: A 30-minute window selected at random from an 8-hour block of time per region.
# See the Amazon RDS User Guide for the time blocks for each region from which the default backup windows are assigned.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
def promote_read_replica(identifier, backup_retention_period = nil, preferred_backup_window = nil)
params = {}
params['BackupRetentionPeriod'] = backup_retention_period if backup_retention_period
params['PreferredBackupWindow'] = preferred_backup_window if preferred_backup_window
request({
'Action' => 'PromoteReadReplica',
'DBInstanceIdentifier' => identifier,
:parser => Fog::Parsers::AWS::RDS::DeleteDBInstance.new
}.merge(params))
end
end
class Mock
def promote_read_replica(identifier, backup_retention_period = nil, preferred_backup_window = nil)
response = Excon::Response.new
unless skip_snapshot
create_db_snapshot(identifier, snapshot_identifier)
end
if server_set = self.data[:servers].delete(identifier)
response.status = 200
response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
"PromoteReadReplicaResult" => { "DBInstance" => server_set }
}
response
else
raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found")
end
end
end
end
end
end