2011-02-27 16:09:12 -05:00
module Fog
module AWS
class RDS
class Real
require 'fog/aws/parsers/rds/create_db_instance'
# create a db instance
# http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
# ==== Parameters
# * DBInstanceIdentifier <~String> - name of the db instance to modify
2012-02-25 18:55:16 -05:00
#
2011-02-27 16:09:12 -05:00
# * AllocatedStorage <~Integer> Storage space, in GB
2012-02-25 18:55:16 -05:00
# * AutoMinorVersionUpgrade <~Boolean> Indicates that minor version upgrades will be applied automatically to the DB Instance during the maintenance window
2011-02-27 16:09:12 -05:00
# * AvailabilityZone <~String> The availability zone to create the instance in
# * BackupRetentionPeriod <~Integer> 0-8 The number of days to retain automated backups.
# * DBInstanceClass <~String> The new compute and memory capacity of the DB Instance
# * DBName <~String> The name of the database to create when the DB Instance is created
2012-02-25 18:55:16 -05:00
# * DBParameterGroupName <~String> The name of the DB Parameter Group to apply to this DB Instance
# * DBSecurityGroups <~Array> A list of DB Security Groups to authorize on this DB Instance
2011-02-27 16:09:12 -05:00
# * Engine <~String> The name of the database engine to be used for this instance.
# * EngineVersion <~String> The version number of the database engine to use.
# * MasterUsername <~String> The db master user
# * MasterUserPassword <~String> The new password for the DB Instance master user
# * MultiAZ <~Boolean> Specifies if the DB Instance is a Multi-AZ deployment
# * Port <~Integer> The port number on which the database accepts connections.
# * PreferredBackupWindow <~String> The daily time range during which automated backups are created if automated backups are enabled
# * PreferredMaintenanceWindow <~String> The weekly time range (in UTC) during which system maintenance can occur, which may result in an outage
2012-08-10 13:03:56 -04:00
# * DBSubnetGroupName <~String> The name, if any, of the VPC subnet for this RDS instance
2011-02-27 16:09:12 -05:00
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
def create_db_instance ( db_name , options = { } )
2012-02-25 18:55:16 -05:00
2011-02-27 16:09:12 -05:00
if security_groups = options . delete ( 'DBSecurityGroups' )
2011-06-20 16:49:37 -04:00
options . merge! ( Fog :: AWS . indexed_param ( 'DBSecurityGroups.member.%d' , [ * security_groups ] ) )
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
request ( {
'Action' = > 'CreateDBInstance' ,
'DBInstanceIdentifier' = > db_name ,
:parser = > Fog :: Parsers :: AWS :: RDS :: CreateDBInstance . new ,
} . merge ( options ) )
end
end
class Mock
def create_db_instance ( db_name , options = { } )
2011-11-29 13:40:36 -05:00
response = Excon :: Response . new
2011-12-02 04:36:10 -05:00
if self . data [ :servers ] and self . data [ :servers ] [ db_name ]
# I don't know how to raise an exception that contains the excon data
#response.status = 400
#response.body = {
# 'Code' => 'DBInstanceAlreadyExists',
# 'Message' => "DB Instance already exists"
#}
#return response
raise Fog :: AWS :: RDS :: IdentifierTaken . new ( " DBInstanceAlreadyExists #{ response . body . to_s } " )
end
2012-02-25 18:55:16 -05:00
2011-11-29 13:40:36 -05:00
# 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?
2011-12-02 04:36:10 -05:00
#response.status = 400
#response.body = {
# 'Code' => 'MissingParameter',
# 'Message' => "The request must contain the parameter #{key}"
#}
#return response
raise Fog :: AWS :: RDS :: NotFound . new ( " The request must contain the parameter #{ key } " )
2011-11-29 13:40:36 -05:00
end
end
2012-02-25 18:55:16 -05:00
2011-11-29 13:40:36 -05:00
data =
2011-11-30 09:06:49 -05:00
{
2011-11-30 14:38:10 -05:00
" DBInstanceIdentifier " = > db_name ,
" DBName " = > options [ " DBName " ] ,
2011-12-22 15:49:27 -05:00
" InstanceCreateTime " = > nil ,
2011-11-29 13:40:36 -05:00
" AutoMinorVersionUpgrade " = > true ,
" Endpoint " = > { } ,
2012-08-03 13:39:45 -04:00
" ReadReplicaDBInstanceIdentifiers " = > [ ] ,
2011-11-29 13:40:36 -05:00
" PreferredMaintenanceWindow " = > " mon:04:30-mon:05:00 " ,
" Engine " = > options [ " Engine " ] ,
2012-08-07 18:27:43 -04:00
" EngineVersion " = > options [ " EngineVersion " ] || " 5.5.12 " ,
2011-11-30 19:08:28 -05:00
" PendingModifiedValues " = > { " MasterUserPassword " = > " **** " } , # This clears when is available
2012-08-15 11:50:56 -04:00
" MultiAZ " = > ! ! options [ 'MultiAZ' ] ,
2011-11-29 13:40:36 -05:00
" MasterUsername " = > options [ " MasterUsername " ] ,
" DBInstanceClass " = > options [ " DBInstanceClass " ] ,
" DBInstanceStatus " = > " creating " ,
" BackupRetentionPeriod " = > options [ " BackupRetentionPeriod " ] || 1 ,
" AllocatedStorage " = > options [ " AllocatedStorage " ] ,
2011-12-27 17:37:04 -05:00
" DBParameterGroups " = > # I think groups should be in the self.data method
2012-08-07 18:27:43 -04:00
[ { " DBParameterGroupName " = > " default.mysql5.5 " ,
2011-11-29 13:40:36 -05:00
" ParameterApplyStatus " = > " in-sync " } ] ,
" DBSecurityGroups " = >
[ { " Status " = > " active " ,
" DBSecurityGroupName " = > " default " } ] ,
" LicenseModel " = > " general-public-license " ,
2011-12-22 15:49:27 -05:00
" PreferredBackupWindow " = > " 08:00-08:30 " ,
# "ReadReplicaSourceDBInstanceIdentifier" => nil,
# "LatestRestorableTime" => nil,
2012-08-30 18:02:17 -04:00
" AvailabilityZone " = > options [ " AvailabilityZone " ] ,
2012-10-29 10:17:19 -04:00
" DBSubnetGroupName " = > options [ " DBSubnetGroupName " ]
2011-11-29 13:40:36 -05:00
}
2012-02-25 18:55:16 -05:00
2011-11-29 13:40:36 -05:00
self . data [ :servers ] [ db_name ] = data
response . body = {
2011-11-30 09:06:49 -05:00
" ResponseMetadata " = > { " RequestId " = > Fog :: AWS :: Mock . request_id } ,
" CreateDBInstanceResult " = > { " DBInstance " = > data }
}
2011-11-29 13:40:36 -05:00
response . status = 200
2011-11-30 14:38:10 -05:00
# This values aren't showed at creating time but at available time
2011-12-22 15:49:27 -05:00
self . data [ :servers ] [ db_name ] [ " InstanceCreateTime " ] = Time . now
2012-10-29 10:17:19 -04:00
self . data [ :tags ] || = { }
self . data [ :tags ] [ db_name ] = { }
2011-11-29 13:40:36 -05:00
response
2011-02-27 16:09:12 -05:00
end
end
end
end
end