Method: Fog::AWS::RDS::Mock#create_db_instance

Defined in:
lib/fog/aws/requests/rds/create_db_instance.rb

#create_db_instance(db_name, options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fog/aws/requests/rds/create_db_instance.rb', line 50

def create_db_instance(db_name, options={})
  response = Excon::Response.new
  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

  # 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 = {
      #  '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}")
    end
  end

  data =
      {
         "DBInstanceIdentifier"=> db_name,
         "DBName" => options["DBName"],
         "InstanceCreateTime" => nil,
         "AutoMinorVersionUpgrade"=>true,
         "Endpoint"=>{},
         "ReadReplicaDBInstanceIdentifiers"=>[],
         "PreferredMaintenanceWindow"=>"mon:04:30-mon:05:00",
         "Engine"=> options["Engine"],
         "EngineVersion"=> options["EngineVersion"] || "5.5.12",
         "PendingModifiedValues"=>{"MasterUserPassword"=>"****"}, # This clears when is available
         "MultiAZ"=> !!options['MultiAZ'],
         "MasterUsername"=> options["MasterUsername"],
         "DBInstanceClass"=> options["DBInstanceClass"],
         "DBInstanceStatus"=>"creating",
         "BackupRetentionPeriod"=> options["BackupRetentionPeriod"] || 1,
         "AllocatedStorage"=> options["AllocatedStorage"],
         "DBParameterGroups"=> # I think groups should be in the self.data method
                  [{"DBParameterGroupName"=>"default.mysql5.5",
                    "ParameterApplyStatus"=>"in-sync"}],
         "DBSecurityGroups"=>
                  [{"Status"=>"active", 
                    "DBSecurityGroupName"=>"default"}],
         "LicenseModel"=>"general-public-license",
         "PreferredBackupWindow"=>"08:00-08:30",
#                 "ReadReplicaSourceDBInstanceIdentifier" => nil,
#                 "LatestRestorableTime" => nil,
         "AvailabilityZone" => options["AvailabilityZone"],
         "DBSubnetGroupName" => options["DBSubnetGroupName"]
     }


  self.data[:servers][db_name] = data
  response.body = {
    "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
    "CreateDBInstanceResult"=> {"DBInstance"=> data}
  }
  response.status = 200
  # This values aren't showed at creating time but at available time
  self.data[:servers][db_name]["InstanceCreateTime"] = Time.now
  self.data[:tags] ||= {}
  self.data[:tags][db_name] = {}
  response
end