2011-02-27 16:09:12 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class RDS
|
|
|
|
class Real
|
|
|
|
|
|
|
|
require 'fog/aws/parsers/rds/describe_db_instances'
|
|
|
|
|
|
|
|
# Describe all or specified load db instances
|
|
|
|
# http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html
|
|
|
|
# ==== Parameters
|
|
|
|
# * DBInstanceIdentifier <~String> - ID of instance to retrieve information for. if absent information for all instances is returned
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
def describe_db_instances(identifier=nil, opts={})
|
|
|
|
params = {}
|
|
|
|
params['DBInstanceIdentifier'] = identifier if identifier
|
|
|
|
if opts[:marker]
|
|
|
|
params['Marker'] = opts[:marker]
|
|
|
|
end
|
|
|
|
if opts[:max_records]
|
|
|
|
params['MaxRecords'] = opts[:max_records]
|
|
|
|
end
|
2012-02-25 18:55:16 -05:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
request({
|
|
|
|
'Action' => 'DescribeDBInstances',
|
|
|
|
:parser => Fog::Parsers::AWS::RDS::DescribeDBInstances.new
|
|
|
|
}.merge(params))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
|
|
|
def describe_db_instances(identifier=nil, opts={})
|
2011-11-30 09:06:49 -05:00
|
|
|
response = Excon::Response.new
|
2011-11-30 14:38:10 -05:00
|
|
|
server_set = []
|
2012-02-25 18:55:16 -05:00
|
|
|
if identifier
|
2011-11-30 14:38:10 -05:00
|
|
|
if server = self.data[:servers][identifier]
|
|
|
|
server_set << server
|
2011-11-30 09:06:49 -05:00
|
|
|
else
|
|
|
|
raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found")
|
2011-12-07 13:36:00 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
server_set = self.data[:servers].values
|
2011-11-30 09:06:49 -05:00
|
|
|
end
|
2012-02-25 18:55:16 -05:00
|
|
|
|
2011-11-30 14:38:10 -05:00
|
|
|
server_set.each do |server|
|
|
|
|
case server["DBInstanceStatus"]
|
|
|
|
when "creating"
|
2013-01-28 15:10:39 -05:00
|
|
|
if Time.now - server['InstanceCreateTime'] >= Fog::Mock.delay * 2
|
|
|
|
region = "us-east-1"
|
|
|
|
server["DBInstanceStatus"] = "available"
|
|
|
|
server["AvailabilityZone"] ||= region + 'a'
|
|
|
|
server["Endpoint"] = {"Port"=>3306,
|
|
|
|
"Address"=> Fog::AWS::Mock.rds_address(server["DBInstanceIdentifier"],region) }
|
|
|
|
server["PendingModifiedValues"] = {}
|
|
|
|
end
|
2012-08-03 14:18:52 -04:00
|
|
|
when "rebooting"
|
|
|
|
if Time.now - self.data[:reboot_time] >= Fog::Mock.delay
|
|
|
|
# apply pending modified values
|
2011-12-22 15:49:27 -05:00
|
|
|
server.merge!(server["PendingModifiedValues"])
|
|
|
|
server["PendingModifiedValues"] = {}
|
2012-08-03 14:18:52 -04:00
|
|
|
|
|
|
|
server["DBInstanceStatus"] = 'available'
|
|
|
|
self.data.delete(:reboot_time)
|
2011-12-22 15:49:27 -05:00
|
|
|
end
|
|
|
|
when "modifying"
|
|
|
|
# TODO there are some fields that only applied after rebooting
|
2012-08-03 14:33:54 -04:00
|
|
|
if Time.now - self.data[:modify_time] >= Fog::Mock.delay
|
2011-11-30 19:08:28 -05:00
|
|
|
server.merge!(server["PendingModifiedValues"])
|
|
|
|
server["PendingModifiedValues"] = {}
|
|
|
|
server["DBInstanceStatus"] = 'available'
|
|
|
|
end
|
2011-12-22 15:49:27 -05:00
|
|
|
when "available" # I'm not sure if amazon does this
|
2012-07-20 02:19:54 -04:00
|
|
|
unless server["PendingModifiedValues"].empty?
|
2011-12-22 15:49:27 -05:00
|
|
|
server["DBInstanceStatus"] = 'modifying'
|
|
|
|
end
|
2012-02-25 18:55:16 -05:00
|
|
|
end
|
2011-11-30 14:38:10 -05:00
|
|
|
end
|
2012-02-25 18:55:16 -05:00
|
|
|
|
2011-11-30 14:38:10 -05:00
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
|
|
|
|
"DescribeDBInstancesResult" => { "DBInstances" => server_set }
|
|
|
|
}
|
2011-11-30 09:06:49 -05:00
|
|
|
response
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
2012-02-25 18:55:16 -05:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|