Method: Fog::AWS::RDS::Mock#create_db_snapshot

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

#create_db_snapshot(identifier, name) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/aws/requests/rds/create_db_snapshot.rb', line 29

def create_db_snapshot(identifier, name)
  response = Excon::Response.new
  if data[:snapshots][name]
    raise Fog::AWS::RDS::IndentifierTaken.new
  end

  server_data = data[:servers][identifier]
  unless server_data
    raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found")
  end

  # TODO: raise an error if the server isn't in 'available' state

  snapshot_data = {
    'Status'               => 'creating',
    'SnapshotType'         => 'manual', 
    'DBInstanceIdentifier' => identifier,
    'DBSnapshotIdentifier' => name,
    'InstanceCreateTime'   => Time.now
  }
  # Copy attributes from server
  %w(Engine EngineVersion AvailabilityZone AllocatedStorage MasterUsername InstanceCreateTime).each do |key|
    snapshot_data[key] = server_data[key]
  end
  snapshot_data['Port'] = server_data['Endpoint']['Port']

  self.data[:snapshots][name] = snapshot_data

  # TODO: put the server in 'modifying' state

  response.body = {
    "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
    "CreateDBSnapshotResult"=> {"DBSnapshot"=> snapshot_data.dup}
  }
  response.status = 200
  # SnapshotCreateTime is not part of the response.
  self.data[:snapshots][name]['SnapshotCreateTime'] = Time.now
  response

end