Method: Fog::AWS::RDS::Mock#describe_db_snapshots

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

#describe_db_snapshots(opts = {}) ⇒ Object


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
# File 'lib/fog/aws/requests/rds/describe_db_snapshots.rb', line 37

def describe_db_snapshots(opts={})
  response = Excon::Response.new
  snapshots = self.data[:snapshots].values
  if opts[:identifier]
    snapshots = snapshots.select{|snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier]}
  end

  if opts[:snapshot_id]
    snapshots = snapshots.select{|snapshot| snapshot['DBSnapshotIdentifier'] == opts[:snapshot_id]}
    raise Fog::AWS::RDS::NotFound.new("DBSnapshot #{opts[:snapshot_id]} not found") if snapshots.empty?
  end

  snapshots.each do |snapshot|
    case snapshot['Status']
    when 'creating'
      if Time.now - snapshot['SnapshotCreateTime'] > Fog::Mock.delay
        snapshot['Status'] = 'available'
      end
    end
  end

  # Build response
  response.status = 200
  response.body = {
    "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
    "DescribeDBSnapshotsResult" => { "DBSnapshots" => snapshots }
  }
  response

end