mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
mock create_db_instance
This commit is contained in:
parent
f15bf2554a
commit
47cac2b71b
3 changed files with 89 additions and 3 deletions
|
@ -218,6 +218,10 @@ module Fog
|
|||
def self.volume_id
|
||||
"vol-#{Fog::Mock.random_hex(8)}"
|
||||
end
|
||||
|
||||
def self.rds_address(db_name,region)
|
||||
"#{db_name}.#{Fog::Mock.random_letters(rand(12) + 4)}.#{region}.rds.amazonaws.com"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,9 +57,42 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def initialize(options={})
|
||||
Fog::Mock.not_implemented
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, region|
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
hash[region] = Hash.new do |region_hash, key|
|
||||
region_hash[key] = {
|
||||
:servers => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
|
||||
@aws_access_key_id = options[:aws_access_key_id]
|
||||
|
||||
@region = options[:region] || 'us-east-1'
|
||||
|
||||
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
|
||||
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@region][@aws_access_key_id]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data[@region].delete(@aws_access_key_id)
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -47,7 +47,56 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def create_db_instance(db_name, options={})
|
||||
Fog::Mock.not_implemented
|
||||
response = Excon::Response.new
|
||||
# These are the required parameters according to the API
|
||||
required_params = %w{AllocatedStorage DBInstanceClass Engine MasterUserPassword MasterUsername }
|
||||
required_params.each do |key|
|
||||
unless options.has_key?(key) and options[key] and !options[key].to_s.empty?
|
||||
response.status = 400
|
||||
#response.body['Message'] = "The request must contain the parameter #{key}"
|
||||
response.body = {
|
||||
'Code' => 'MissingParameter'
|
||||
}
|
||||
response.body['Message'] = "The request must contain the parameter #{key}"
|
||||
return response
|
||||
end
|
||||
end
|
||||
|
||||
data =
|
||||
{"CreateDBInstanceResult"=>
|
||||
{"DBInstance"=>
|
||||
{#"created_at" => Time.now,
|
||||
"AutoMinorVersionUpgrade"=>true,
|
||||
"Endpoint"=>{},
|
||||
"ReadReplicaDBInstanceIdentifiers"=>[],
|
||||
"PreferredMaintenanceWindow"=>"mon:04:30-mon:05:00",
|
||||
"Engine"=> options["Engine"],
|
||||
"EngineVersion"=> options["EngineVersion"] || "5.1.57",
|
||||
"PendingModifiedValues"=>{"MasterUserPassword"=>"****"},
|
||||
"MultiAZ"=>false,
|
||||
"MasterUsername"=> options["MasterUsername"],
|
||||
"DBInstanceClass"=> options["DBInstanceClass"],
|
||||
"DBInstanceStatus"=>"creating",
|
||||
"BackupRetentionPeriod"=> options["BackupRetentionPeriod"] || 1,
|
||||
"DBInstanceIdentifier"=> db_name,
|
||||
"AllocatedStorage"=> options["AllocatedStorage"],
|
||||
"DBParameterGroups"=> # I think groups shoul be in the self.data method
|
||||
[{"DBParameterGroupName"=>"default.mysql5.1",
|
||||
"ParameterApplyStatus"=>"in-sync"}],
|
||||
"DBSecurityGroups"=>
|
||||
[{"Status"=>"active",
|
||||
"DBSecurityGroupName"=>"default"}],
|
||||
"LicenseModel"=>"general-public-license",
|
||||
"PreferredBackupWindow"=>"08:00-08:30"}}
|
||||
}
|
||||
|
||||
|
||||
self.data[:servers][db_name] = data
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }
|
||||
}.merge!(data)
|
||||
response.status = 200
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue