Updated delete_cluster() for redshift (#2186)
* Updated the deprecated decorator to allow the "SkipFinalClusterSnapshot" option that aws supports. * FIxed logical mistake on the delete_cluster * Removed an unused exception I put in
This commit is contained in:
parent
8cb4db1896
commit
1fd71fd45a
3 changed files with 50 additions and 11 deletions
|
|
@ -531,14 +531,37 @@ class RedshiftBackend(BaseBackend):
|
|||
setattr(cluster, key, value)
|
||||
|
||||
if new_cluster_identifier:
|
||||
self.delete_cluster(cluster_identifier)
|
||||
dic = {
|
||||
"cluster_identifier": cluster_identifier,
|
||||
"skip_final_snapshot": True,
|
||||
"final_cluster_snapshot_identifier": None
|
||||
}
|
||||
self.delete_cluster(**dic)
|
||||
cluster.cluster_identifier = new_cluster_identifier
|
||||
self.clusters[new_cluster_identifier] = cluster
|
||||
|
||||
return cluster
|
||||
|
||||
def delete_cluster(self, cluster_identifier):
|
||||
def delete_cluster(self, **cluster_kwargs):
|
||||
cluster_identifier = cluster_kwargs.pop("cluster_identifier")
|
||||
cluster_skip_final_snapshot = cluster_kwargs.pop("skip_final_snapshot")
|
||||
cluster_snapshot_identifer = cluster_kwargs.pop("final_cluster_snapshot_identifier")
|
||||
|
||||
if cluster_identifier in self.clusters:
|
||||
if cluster_skip_final_snapshot is False and cluster_snapshot_identifer is None:
|
||||
raise ClientError(
|
||||
"InvalidParameterValue",
|
||||
'FinalSnapshotIdentifier is required for Snapshot copy '
|
||||
'when SkipFinalSnapshot is False'
|
||||
)
|
||||
elif cluster_skip_final_snapshot is False and cluster_snapshot_identifer is not None: # create snapshot
|
||||
cluster = self.describe_clusters(cluster_identifier)[0]
|
||||
self.create_cluster_snapshot(
|
||||
cluster_identifier,
|
||||
cluster_snapshot_identifer,
|
||||
cluster.region,
|
||||
cluster.tags)
|
||||
|
||||
return self.clusters.pop(cluster_identifier)
|
||||
raise ClusterNotFoundError(cluster_identifier)
|
||||
|
||||
|
|
|
|||
|
|
@ -240,8 +240,13 @@ class RedshiftResponse(BaseResponse):
|
|||
})
|
||||
|
||||
def delete_cluster(self):
|
||||
cluster_identifier = self._get_param("ClusterIdentifier")
|
||||
cluster = self.redshift_backend.delete_cluster(cluster_identifier)
|
||||
request_kwargs = {
|
||||
"cluster_identifier": self._get_param("ClusterIdentifier"),
|
||||
"final_cluster_snapshot_identifier": self._get_param("FinalClusterSnapshotIdentifier"),
|
||||
"skip_final_snapshot": self._get_bool_param("SkipFinalClusterSnapshot")
|
||||
}
|
||||
|
||||
cluster = self.redshift_backend.delete_cluster(**request_kwargs)
|
||||
|
||||
return self.get_response({
|
||||
"DeleteClusterResponse": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue