fog-aws 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +4 -0
  4. data/README.md +1 -1
  5. data/gemfiles/Gemfile-edge +5 -0
  6. data/lib/fog/aws/models/compute/security_group.rb +4 -4
  7. data/lib/fog/aws/models/rds/cluster.rb +93 -0
  8. data/lib/fog/aws/models/rds/cluster_snapshots.rb +48 -0
  9. data/lib/fog/aws/models/rds/clusters.rb +23 -0
  10. data/lib/fog/aws/models/rds/parameters.rb +15 -0
  11. data/lib/fog/aws/models/rds/server.rb +29 -11
  12. data/lib/fog/aws/models/rds/servers.rb +4 -0
  13. data/lib/fog/aws/models/rds/snapshot.rb +36 -17
  14. data/lib/fog/aws/parsers/rds/create_db_cluster.rb +32 -0
  15. data/lib/fog/aws/parsers/rds/create_db_cluster_snapshot.rb +33 -0
  16. data/lib/fog/aws/parsers/rds/db_cluster_parser.rb +71 -0
  17. data/lib/fog/aws/parsers/rds/db_cluster_snapshot_parser.rb +32 -0
  18. data/lib/fog/aws/parsers/rds/db_parameter_parser.rb +30 -0
  19. data/lib/fog/aws/parsers/rds/db_parser.rb +2 -1
  20. data/lib/fog/aws/parsers/rds/delete_db_cluster.rb +32 -0
  21. data/lib/fog/aws/parsers/rds/delete_db_cluster_snapshot.rb +32 -0
  22. data/lib/fog/aws/parsers/rds/describe_db_cluster_snapshots.rb +34 -0
  23. data/lib/fog/aws/parsers/rds/describe_db_clusters.rb +34 -0
  24. data/lib/fog/aws/parsers/rds/describe_engine_default_parameters.rb +34 -0
  25. data/lib/fog/aws/parsers/rds/restore_db_instance_from_db_snapshot.rb +2 -2
  26. data/lib/fog/aws/parsers/rds/snapshot_parser.rb +6 -13
  27. data/lib/fog/aws/rds.rb +25 -0
  28. data/lib/fog/aws/requests/compute/describe_availability_zones.rb +5 -2
  29. data/lib/fog/aws/requests/rds/create_db_cluster.rb +98 -0
  30. data/lib/fog/aws/requests/rds/create_db_cluster_snapshot.rb +68 -0
  31. data/lib/fog/aws/requests/rds/create_db_instance.rb +42 -4
  32. data/lib/fog/aws/requests/rds/create_db_snapshot.rb +1 -1
  33. data/lib/fog/aws/requests/rds/delete_db_cluster.rb +55 -0
  34. data/lib/fog/aws/requests/rds/delete_db_cluster_snapshot.rb +43 -0
  35. data/lib/fog/aws/requests/rds/delete_db_instance.rb +9 -0
  36. data/lib/fog/aws/requests/rds/delete_db_snapshot.rb +2 -1
  37. data/lib/fog/aws/requests/rds/describe_db_cluster_snapshots.rb +66 -0
  38. data/lib/fog/aws/requests/rds/describe_db_clusters.rb +54 -0
  39. data/lib/fog/aws/requests/rds/describe_db_instances.rb +4 -0
  40. data/lib/fog/aws/requests/rds/describe_db_parameters.rb +15 -1
  41. data/lib/fog/aws/requests/rds/describe_engine_default_parameters.rb +40 -0
  42. data/lib/fog/aws/requests/rds/modify_db_instance.rb +52 -49
  43. data/lib/fog/aws/requests/rds/modify_db_parameter_group.rb +28 -1
  44. data/lib/fog/aws/requests/rds/restore_db_instance_from_db_snapshot.rb +63 -2
  45. data/lib/fog/aws/version.rb +1 -1
  46. data/tests/models/rds/cluster_tests.rb +54 -0
  47. data/tests/models/rds/clusters_tests.rb +5 -0
  48. data/tests/models/rds/helper.rb +13 -0
  49. data/tests/models/rds/server_tests.rb +3 -3
  50. data/tests/models/rds/servers_tests.rb +18 -0
  51. data/tests/requests/compute/instance_tests.rb +2 -3
  52. data/tests/requests/rds/cluster_snapshot_tests.rb +43 -0
  53. data/tests/requests/rds/cluster_tests.rb +37 -0
  54. data/tests/requests/rds/helper.rb +84 -0
  55. data/tests/requests/rds/instance_tests.rb +16 -4
  56. data/tests/requests/rds/parameter_group_tests.rb +1 -1
  57. data/tests/requests/rds/parameter_request_tests.rb +0 -2
  58. metadata +27 -3
@@ -22,7 +22,7 @@ module Fog
22
22
  def describe_availability_zones(filters = {})
23
23
  unless filters.is_a?(Hash)
24
24
  Fog::Logger.deprecation("describe_availability_zones with #{filters.class} param is deprecated, use describe_availability_zones('zone-name' => []) instead [light_black](#{caller.first})[/]")
25
- filters = {'public-ip' => [*filters]}
25
+ filters = {'zone-name' => [*filters]}
26
26
  end
27
27
  params = Fog::AWS.indexed_filters(filters)
28
28
  request({
@@ -37,7 +37,7 @@ module Fog
37
37
  def describe_availability_zones(filters = {})
38
38
  unless filters.is_a?(Hash)
39
39
  Fog::Logger.deprecation("describe_availability_zones with #{filters.class} param is deprecated, use describe_availability_zones('zone-name' => []) instead [light_black](#{caller.first})[/]")
40
- filters = {'public-ip' => [*filters]}
40
+ filters = {'zone-name' => [*filters]}
41
41
  end
42
42
 
43
43
  response = Excon::Response.new
@@ -69,6 +69,9 @@ module Fog
69
69
  {"messageSet" => [], "regionName" => "ap-northeast-1", "zoneName" => "ap-northeast-1a", "zoneState" => "available"},
70
70
  {"messageSet" => [], "regionName" => "ap-northeast-1", "zoneName" => "ap-northeast-1b", "zoneState" => "available"},
71
71
 
72
+ {"messageSet" => [], "regionName" => "ap-northeast-2", "zoneName" => "ap-northeast-2a", "zoneState" => "available"},
73
+ {"messageSet" => [], "regionName" => "ap-northeast-2", "zoneName" => "ap-northeast-2b", "zoneState" => "available"},
74
+
72
75
  {"messageSet" => [], "regionName" => "ap-southeast-1", "zoneName" => "ap-southeast-1a", "zoneState" => "available"},
73
76
  {"messageSet" => [], "regionName" => "ap-southeast-1", "zoneName" => "ap-southeast-1b", "zoneState" => "available"},
74
77
 
@@ -0,0 +1,98 @@
1
+ module Fog
2
+ module AWS
3
+ class RDS
4
+ class Real
5
+ require 'fog/aws/parsers/rds/create_db_cluster'
6
+
7
+ # Create a db cluster
8
+ #
9
+ # @see http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html
10
+ #
11
+ # ==== Parameters ====
12
+ # * AvailabilityZones<~Array> - A list of EC2 Availability Zones that instances in the DB cluster can be created in
13
+ # * BackupRetentionPeriod<~String> - The number of days for which automated backups are retained
14
+ # * CharacterSetName<~String> - A value that indicates that the DB cluster should be associated with the specified CharacterSet
15
+ # * DatabaseName<~String> - The name for your database of up to 8 alpha-numeric characters. If you do not provide a name, Amazon RDS will not create a database in the DB cluster you are creating
16
+ # * DBClusterIdentifier<~String> - The DB cluster identifier. This parameter is stored as a lowercase string
17
+ # * DBClusterParameterGroupName<~String> - The name of the DB cluster parameter group to associate with this DB cluster
18
+ # * DBSubnetGroupName<~String> - A DB subnet group to associate with this DB cluster
19
+ # * Engine<~String> - The name of the database engine to be used for this DB cluster
20
+ # * EngineVersion<~String> - The version number of the database engine to use
21
+ # * KmsKeyId<~String> - The KMS key identifier for an encrypted DB cluster
22
+ # * MasterUsername<~String> - The name of the master user for the client DB cluster
23
+ # * MasterUserPassword<~String> - The password for the master database user
24
+ # * OptionGroupName<~String> - A value that indicates that the DB cluster should be associated with the specified option group
25
+ # * Port<~Integer> - The port number on which the instances in the DB cluster accept connections
26
+ # * PreferredBackupWindow<~String> - The daily time range during which automated backups are created if automated backups are enabled using the BackupRetentionPeriod parameter
27
+ # * PreferredMaintenanceWindow<~String> - The weekly time range during which system maintenance can occur, in Universal Coordinated Time (UTC)
28
+ # * StorageEncrypted<~Boolean> - Specifies whether the DB cluster is encrypted
29
+ # * Tags<~Array> - A list of tags
30
+ # * VpcSecurityGroups<~Array> - A list of EC2 VPC security groups to associate with this DB cluster
31
+ #
32
+ # ==== Returns ====
33
+ # * response<~Excon::Response>:
34
+ # * body<~Hash>:
35
+
36
+ def create_db_cluster(cluster_name, options={})
37
+ if security_groups = options.delete('VpcSecurityGroups')
38
+ options.merge!(Fog::AWS.indexed_param('VpcSecurityGroupIds.member.%d', [*security_groups]))
39
+ end
40
+
41
+ request({
42
+ 'Action' => 'CreateDBCluster',
43
+ 'DBClusterIdentifier' => cluster_name,
44
+ :parser => Fog::Parsers::AWS::RDS::CreateDBCluster.new,
45
+ }.merge(options))
46
+ end
47
+ end
48
+
49
+ class Mock
50
+ def create_db_cluster(cluster_name, options={})
51
+ response = Excon::Response.new
52
+ if self.data[:clusters][cluster_name]
53
+ raise Fog::AWS::RDS::IdentifierTaken.new("DBClusterAlreadyExists")
54
+ end
55
+
56
+ required_params = %w(Engine MasterUsername MasterUserPassword)
57
+ required_params.each do |key|
58
+ unless options.key?(key) && options[key] && !options[key].to_s.empty?
59
+ raise Fog::AWS::RDS::NotFound.new("The request must contain the parameter #{key}")
60
+ end
61
+ end
62
+
63
+ vpc_security_groups = Array(options.delete("VpcSecurityGroups")).map do |group_id|
64
+ {"VpcSecurityGroupId" => group_id }
65
+ end
66
+
67
+ data = {
68
+ 'AllocatedStorage' => "1",
69
+ 'BackupRetentionPeriod' => (options["BackupRetentionPeriod"] || 35).to_s,
70
+ 'ClusterCreateTime' => Time.now,
71
+ 'DBClusterIdentifier' => cluster_name,
72
+ 'DBClusterMembers' => [],
73
+ 'DBClusterParameterGroup' => options['DBClusterParameterGroup'] || "default.aurora5.6",
74
+ 'DBSubnetGroup' => options["DBSubnetGroup"] || "default",
75
+ 'Endpoint' => "#{cluster_name}.cluster-#{Fog::Mock.random_hex(8)}.#{@region}.rds.amazonaws.com",
76
+ 'Engine' => options["Engine"] || "aurora5.6",
77
+ 'EngineVersion' => options["EngineVersion"] || "5.6.10a",
78
+ 'MasterUsername' => options["MasterUsername"],
79
+ 'Port' => options["Port"] || "3306",
80
+ 'PreferredBackupWindow' => options["PreferredBackupWindow"] || "04:45-05:15",
81
+ 'PreferredMaintenanceWindow' => options["PreferredMaintenanceWindow"] || "sat:05:56-sat:06:26",
82
+ 'Status' => "available",
83
+ 'StorageEncrypted' => options["StorageEncrypted"] || false,
84
+ 'VpcSecurityGroups' => vpc_security_groups,
85
+ }
86
+
87
+ self.data[:clusters][cluster_name] = data
88
+ response.body = {
89
+ "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
90
+ "CreateDBClusterResult" => { "DBCluster" => data.dup.reject { |k,v| k == 'ClusterCreateTime' } }
91
+ }
92
+ response.status = 200
93
+ response
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,68 @@
1
+ module Fog
2
+ module AWS
3
+ class RDS
4
+ class Real
5
+ require 'fog/aws/parsers/rds/create_db_cluster_snapshot'
6
+
7
+ # create a snapshot of a db cluster
8
+ # http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBClusterSnapshot.html
9
+ #
10
+ # ==== Parameters ====
11
+ # * DBClusterIdentifier<~String> - The identifier of the DB cluster to create a snapshot for
12
+ # * DBClusterSnapshotIdentifier<~String> - The identifier of the DB cluster snapshot
13
+ # * Tags<~Array> - The tags to be assigned to the DB cluster snapshot
14
+ #
15
+ # ==== Returns ====
16
+ # * response<~Excon::Response>:
17
+ # * body<~Hash>:
18
+
19
+ def create_db_cluster_snapshot(identifier, name)
20
+ request(
21
+ 'Action' => 'CreateDBClusterSnapshot',
22
+ 'DBClusterIdentifier' => identifier,
23
+ 'DBClusterSnapshotIdentifier' => name,
24
+ :parser => Fog::Parsers::AWS::RDS::CreateDBClusterSnapshot.new
25
+ )
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def create_db_cluster_snapshot(identifier, name)
31
+ response = Excon::Response.new
32
+
33
+ if data[:cluster_snapshots][name]
34
+ raise Fog::AWS::RDS::IdentifierTaken.new
35
+ end
36
+
37
+ cluster = self.data[:clusters][identifier]
38
+
39
+ raise Fog::AWS::RDS::NotFound.new("DBCluster #{identifier} not found") unless cluster
40
+
41
+ data = {
42
+ 'AllocatedStorage' => cluster['AllocatedStorage'].to_i,
43
+ 'ClusterCreateTime' => cluster['ClusterCreateTime'],
44
+ 'DBClusterIdentifier' => identifier,
45
+ 'DBClusterSnapshotIdentifier' => name,
46
+ 'Engine' => cluster['Engine'],
47
+ 'EngineVersion' => cluster['EngineVersion'],
48
+ 'LicenseModel' => cluster['Engine'],
49
+ 'MasterUsername' => cluster['MasterUsername'],
50
+ 'SnapshotCreateTime' => Time.now,
51
+ 'SnapshotType' => 'manual',
52
+ 'StorageEncrypted' => cluster["StorageEncrypted"],
53
+ 'Status' => 'creating',
54
+ }
55
+
56
+ self.data[:cluster_snapshots][name] = data
57
+
58
+ response.body = {
59
+ "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
60
+ "CreateDBClusterSnapshotResult" => { "DBClusterSnapshot" => data.dup },
61
+ }
62
+ self.data[:cluster_snapshots][name]['SnapshotCreateTime'] = Time.now
63
+ response
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -65,7 +65,8 @@ module Fog
65
65
  end
66
66
 
67
67
  # These are the required parameters according to the API
68
- required_params = %w{AllocatedStorage DBInstanceClass Engine MasterUserPassword MasterUsername }
68
+ required_params = %w(DBInstanceClass Engine)
69
+ required_params += %w{AllocatedStorage DBInstanceClass Engine MasterUserPassword MasterUsername } unless options["DBClusterIdentifier"]
69
70
  required_params.each do |key|
70
71
  unless options.key?(key) and options[key] and !options[key].to_s.empty?
71
72
  #response.status = 400
@@ -84,6 +85,16 @@ module Fog
84
85
 
85
86
  ec2 = Fog::Compute::AWS::Mock.data[@region][@aws_access_key_id]
86
87
 
88
+ db_parameter_groups = if pg_name = options.delete("DBParameterGroupName")
89
+ group = self.data[:parameter_groups][pg_name]
90
+ if group
91
+ [{"DBParameterGroupName" => pg_name, "ParameterApplyStatus" => "in-sync" }]
92
+ else
93
+ raise Fog::AWS::RDS::NotFound.new("Parameter group does not exist")
94
+ end
95
+ else
96
+ [{ "DBParameterGroupName" => "default.mysql5.5", "ParameterApplyStatus" => "in-sync" }]
97
+ end
87
98
  db_security_group_names = Array(options.delete("DBSecurityGroups"))
88
99
  rds_security_groups = self.data[:security_groups].values
89
100
  ec2_security_groups = ec2[:security_groups].values
@@ -109,17 +120,44 @@ module Fog
109
120
  {"Status" => "active", "VpcSecurityGroupId" => group_id }
110
121
  end
111
122
 
123
+ if options["Engine"] == "aurora" && ! options["DBClusterIdentifier"]
124
+ raise Fog::AWS::RDS::Error.new("InvalidParameterStateValue => Standalone instances for this engine are not supported")
125
+ end
126
+
127
+ if cluster_id = options["DBClusterIdentifier"]
128
+ if vpc_security_groups.any?
129
+ raise Fog::AWS::RDS::Error.new("InvalidParameterCombination => The requested DB Instance will be a member of a DB Cluster and its vpc security group should not be set directly.")
130
+ end
131
+
132
+ if options["MultiAZ"]
133
+ raise Fog::AWS::RDS::Error.new("InvalidParameterCombination => VPC Multi-AZ DB Instances are not available for engine: aurora")
134
+ end
135
+
136
+ %w(AllocatedStorage BackupRetentionPeriod MasterUsername MasterUserPassword).each do |forbidden|
137
+ raise Fog::AWS::RDS::Error.new("InvalidParameterCombination => The requested DB Instance will be a member of a DB Cluster and its #{forbidden} should not be set directly.") if options[forbidden]
138
+ end
139
+
140
+ options["StorageType"] = "aurora"
141
+
142
+ cluster = self.data[:clusters][cluster_id]
143
+
144
+ member = {"DBInstanceIdentifier" => db_name, "master" => cluster['DBClusterMembers'].empty?}
145
+ cluster['DBClusterMembers'] << member
146
+ self.data[:clusters][cluster_id] = cluster
147
+ end
148
+
112
149
  data = {
113
150
  "AllocatedStorage" => options["AllocatedStorage"],
114
151
  "AutoMinorVersionUpgrade" => options["AutoMinorVersionUpgrade"].nil? ? true : options["AutoMinorVersionUpgrade"],
115
152
  "AvailabilityZone" => options["AvailabilityZone"],
116
153
  "BackupRetentionPeriod" => options["BackupRetentionPeriod"] || 1,
117
154
  "CACertificateIdentifier" => "rds-ca-2015",
155
+ "DBClusterIdentifier" => options["DBClusterIdentifier"],
118
156
  "DBInstanceClass" => options["DBInstanceClass"],
119
157
  "DBInstanceIdentifier" => db_name,
120
158
  "DBInstanceStatus" =>"creating",
121
159
  "DBName" => options["DBName"],
122
- "DBParameterGroups" => [{ "DBParameterGroupName" => "default.mysql5.5", "ParameterApplyStatus" => "in-sync" }],
160
+ "DBParameterGroups" => db_parameter_groups,
123
161
  "DBSecurityGroups" => db_security_groups,
124
162
  "DBSubnetGroupName" => options["DBSubnetGroupName"],
125
163
  "Endpoint" =>{},
@@ -128,14 +166,14 @@ module Fog
128
166
  "InstanceCreateTime" => nil,
129
167
  "Iops" => options["Iops"],
130
168
  "LicenseModel" => "general-public-license",
131
- "MasterUsername" => options["MasterUsername"],
169
+ "MasterUsername" => cluster_id ? cluster["MasterUsername"] : options["MasterUsername"],
132
170
  "MultiAZ" => !!options["MultiAZ"],
133
171
  "PendingModifiedValues" => { "MasterUserPassword" => "****" }, # This clears when is available
134
172
  "PreferredBackupWindow" => options["PreferredBackupWindow"] || "08:00-08:30",
135
173
  "PreferredMaintenanceWindow" => options["PreferredMaintenanceWindow"] || "mon:04:30-mon:05:00",
136
174
  "PubliclyAccessible" => !!options["PubliclyAccessible"],
137
175
  "ReadReplicaDBInstanceIdentifiers" => [],
138
- "StorageEncrypted" => options["StorageEncrypted"] || false,
176
+ "StorageEncrypted" => cluster_id ? cluster["StorageEncrypted"] : (options["StorageEncrypted"] || false),
139
177
  "StorageType" => options["StorageType"] || "standard",
140
178
  "VpcSecurityGroups" => vpc_security_groups,
141
179
  }
@@ -45,7 +45,7 @@ module Fog
45
45
  'InstanceCreateTime' => Time.now
46
46
  }
47
47
  # Copy attributes from server
48
- %w(Engine EngineVersion AvailabilityZone AllocatedStorage Iops MasterUsername InstanceCreateTime).each do |key|
48
+ %w(Engine EngineVersion AvailabilityZone AllocatedStorage Iops MasterUsername InstanceCreateTime StorageType).each do |key|
49
49
  snapshot_data[key] = server_data[key]
50
50
  end
51
51
  snapshot_data['Port'] = server_data['Endpoint']['Port']
@@ -0,0 +1,55 @@
1
+ module Fog
2
+ module AWS
3
+ class RDS
4
+ class Real
5
+ require 'fog/aws/parsers/rds/delete_db_cluster'
6
+
7
+ # delete a database cluster
8
+ #
9
+ # @see http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DeleteDBCluster.html
10
+ #
11
+ # ==== Parameters ====
12
+ # * DBClusterIdentifier <~String> - The DB cluster identifier for the DB cluster to be deleted
13
+ # * FinalDBSnapshotIdentifier <~String> - The DB cluster snapshot identifier of the new DB cluster snapshot created when SkipFinalSnapshot is set to false
14
+ # * SkipFinalSnapshot <~Boolean> - Determines whether a final DB cluster snapshot is created before the DB cluster is deleted
15
+ #
16
+ # ==== Returns ====
17
+ # * response<~Excon::Response>
18
+ # * body<~Hash>
19
+
20
+ def delete_db_cluster(identifier, snapshot_identifier, skip_snapshot = false)
21
+ params = {}
22
+ params["FinalDBSnapshotIdentifier"] = snapshot_identifier if snapshot_identifier
23
+ request({
24
+ 'Action' => 'DeleteDBCluster',
25
+ 'DBClusterIdentifier' => identifier,
26
+ 'SkipFinalSnapshot' => skip_snapshot,
27
+ }.merge(params))
28
+ end
29
+ end
30
+
31
+ class Mock
32
+ def delete_db_cluster(identifier, snapshot_identifier, skip_snapshot = false)
33
+ response = Excon::Response.new
34
+
35
+ cluster = self.data[:clusters][identifier] || raise(Fog::AWS::RDS::NotFound.new("DBCluster #{identifier} not found"))
36
+
37
+ raise Fog::AWS::RDS::Error.new("InvalidDBClusterStateFault => Cluster cannot be deleted, it still contains DB instances in non-deleting state.") if cluster["DBClusterMembers"].any?
38
+
39
+ unless skip_snapshot
40
+ create_db_cluster_snapshot(identifier, snapshot_identifier)
41
+ end
42
+
43
+ self.data[:clusters].delete(identifier)
44
+
45
+ response.status = 200
46
+ response.body = {
47
+ "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
48
+ "DeleteDBClusterResult" => { "DBCluster" => cluster}
49
+ }
50
+ response
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,43 @@
1
+ module Fog
2
+ module AWS
3
+ class RDS
4
+ class Real
5
+ require 'fog/aws/parsers/rds/delete_db_cluster_snapshot'
6
+
7
+ # delete a db cluster snapshot
8
+ # http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DeleteDBClusterSnapshot.html
9
+ #
10
+ # ==== Parameters ====
11
+ # * DBClusterSnapshotIdentifier<~String> - The identifier of the DB cluster snapshot to delete
12
+ #
13
+ # ==== Returns ====
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+
17
+ def delete_db_cluster_snapshot(name)
18
+ request(
19
+ 'Action' => 'DeleteDBClusterSnapshot',
20
+ 'DBClusterSnapshotIdentifier' => name,
21
+ :parser => Fog::Parsers::AWS::RDS::DeleteDBClusterSnapshot.new
22
+ )
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def delete_db_cluster_snapshot(name)
28
+ response = Excon::Response.new
29
+ snapshot = self.data[:cluster_snapshots].delete(name)
30
+
31
+ raise Fog::AWS::RDS::NotFound.new("DBClusterSnapshotNotFound => #{name} not found") unless snapshot
32
+
33
+ response.status = 200
34
+ response.body = {
35
+ "ResponseMetadata" => {"RequestId" => Fog::AWS::Mock.request_id},
36
+ "DeleteDBClusterSnapshotResult" => {"DBClusterSnapshot" => snapshot}
37
+ }
38
+ response
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -37,11 +37,20 @@ module Fog
37
37
  unless skip_snapshot
38
38
  if server_set["ReadReplicaSourceDBInstanceIdentifier"]
39
39
  raise Fog::AWS::RDS::Error.new("InvalidParameterCombination => FinalDBSnapshotIdentifier can not be specified when deleting a replica instance")
40
+ elsif server_set["DBClusterIdentifier"]
41
+ raise Fog::AWS::RDS::Error.new("InvalidParameterCombination => FinalDBSnapshotIdentifier can not be specified when deleting a cluster instance")
40
42
  else
41
43
  create_db_snapshot(identifier, snapshot_identifier)
42
44
  end
43
45
  end
44
46
 
47
+ cluster = self.data[:clusters].values.detect { |c| c["DBClusterMembers"].any? { |m| m["DBInstanceIdentifier"] == identifier } }
48
+
49
+ if cluster
50
+ cluster["DBClusterMembers"].delete_if { |v| v["DBInstanceIdentifier"] == identifier }
51
+ self.data[:clusters][cluster["DBClusterIdentifier"]] = cluster
52
+ end
53
+
45
54
  self.data[:servers].delete(identifier)
46
55
 
47
56
  response.status = 200
@@ -26,8 +26,9 @@ module Fog
26
26
  # TODO: raise error if snapshot isn't 'available'
27
27
  response = Excon::Response.new
28
28
  snapshot_data = self.data[:snapshots].delete(name)
29
+ snapshot_data = self.data[:cluster_snapshots].delete(name) unless snapshot_data
29
30
 
30
- raise Fog::AWS::RDS::NotFound.new("DBSnapshtoNotFound => #{name} not found") unless snapshot_data
31
+ raise Fog::AWS::RDS::NotFound.new("DBSnapshotNotFound => #{name} not found") unless snapshot_data
31
32
 
32
33
  response.status = 200
33
34
  response.body = {
@@ -0,0 +1,66 @@
1
+ module Fog
2
+ module AWS
3
+ class RDS
4
+ class Real
5
+ require 'fog/aws/parsers/rds/describe_db_cluster_snapshots'
6
+
7
+ # Describe all or specified db cluster snapshots
8
+ # http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBClusterSnapshots.html
9
+ #
10
+ # ==== Parameters ====
11
+ # * DBClusterIdentifier<~String> - A DB cluster identifier to retrieve the list of DB cluster snapshots for
12
+ # * DBClusterSnapshotIdentifier<~String> - A specific DB cluster snapshot identifier to describe
13
+ # * SnapshotType<~String> - The type of DB cluster snapshots that will be returned. Values can be automated or manual
14
+ #
15
+ # ==== Returns ====
16
+ # * response<~Excon::Response>:
17
+ # * body<~Hash>:
18
+
19
+ def describe_db_cluster_snapshots(opts={})
20
+ params = {}
21
+ params['SnapshotType'] = opts[:type] if opts[:type]
22
+ params['DBClusterIdentifier'] = opts[:identifier] if opts[:identifier]
23
+ params['DBClusterSnapshotIdentifier'] = opts[:snapshot_id] if opts[:snapshot_id]
24
+ params['Marker'] = opts[:marker] if opts[:marker]
25
+ params['MaxRecords'] = opts[:max_records] if opts[:max_records]
26
+ request({
27
+ 'Action' => 'DescribeDBClusterSnapshots',
28
+ :parser => Fog::Parsers::AWS::RDS::DescribeDBClusterSnapshots.new
29
+ }.merge(params))
30
+ end
31
+ end
32
+
33
+ class Mock
34
+ def describe_db_cluster_snapshots(opts={})
35
+ response = Excon::Response.new
36
+ snapshots = self.data[:cluster_snapshots].values
37
+
38
+ if opts[:identifier]
39
+ snapshots = snapshots.select { |snapshot| snapshot['DBClusterIdentifier'] == opts[:identifier] }
40
+ end
41
+
42
+ if opts[:snapshot_id]
43
+ snapshots = snapshots.select { |snapshot| snapshot['DBClusterSnapshotIdentifier'] == opts[:snapshot_id] }
44
+ raise Fog::AWS::RDS::NotFound.new("DBClusterSnapshot #{opts[:snapshot_id]} not found") if snapshots.empty?
45
+ end
46
+
47
+ snapshots.each do |snapshot|
48
+ case snapshot['Status']
49
+ when 'creating'
50
+ if Time.now - snapshot['SnapshotCreateTime'] > Fog::Mock.delay
51
+ snapshot['Status'] = 'available'
52
+ end
53
+ end
54
+ end
55
+
56
+ response.status = 200
57
+ response.body = {
58
+ 'ResponseMetadata' => { "RequestId" => Fog::AWS::Mock.request_id },
59
+ 'DescribeDBClusterSnapshotsResult' => { 'DBClusterSnapshots' => snapshots }
60
+ }
61
+ response
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end