File: delete_db_cluster.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (55 lines) | stat: -rw-r--r-- 2,144 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
module Fog
  module AWS
    class RDS
      class Real
        require 'fog/aws/parsers/rds/delete_db_cluster'

        # delete a database cluster
        #
        # @see http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DeleteDBCluster.html
        #
        # ==== Parameters ====
        # * DBClusterIdentifier <~String> - The DB cluster identifier for the DB cluster to be deleted
        # * FinalDBSnapshotIdentifier <~String> - The DB cluster snapshot identifier of the new DB cluster snapshot created when SkipFinalSnapshot is set to false
        # * SkipFinalSnapshot <~Boolean> - Determines whether a final DB cluster snapshot is created before the DB cluster is deleted
        #
        # ==== Returns ====
        # * response<~Excon::Response>
        #   * body<~Hash>

        def delete_db_cluster(identifier, snapshot_identifier, skip_snapshot = false)
          params = {}
          params["FinalDBSnapshotIdentifier"] = snapshot_identifier if snapshot_identifier
          request({
            'Action'              => 'DeleteDBCluster',
            'DBClusterIdentifier' => identifier,
            'SkipFinalSnapshot'   => skip_snapshot,
          }.merge(params))
        end
      end

      class Mock
        def delete_db_cluster(identifier, snapshot_identifier, skip_snapshot = false)
          response = Excon::Response.new

          cluster = self.data[:clusters][identifier] || raise(Fog::AWS::RDS::NotFound.new("DBCluster #{identifier} not found"))

          raise Fog::AWS::RDS::Error.new("InvalidDBClusterStateFault => Cluster cannot be deleted, it still contains DB instances in non-deleting state.") if cluster["DBClusterMembers"].any?

          unless skip_snapshot
            create_db_cluster_snapshot(identifier, snapshot_identifier)
          end

          self.data[:clusters].delete(identifier)

          response.status = 200
          response.body   = {
            "ResponseMetadata"      => { "RequestId" => Fog::AWS::Mock.request_id },
            "DeleteDBClusterResult" => { "DBCluster" => cluster}
          }
          response
        end
      end
    end
  end
end