-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzzDelRedC.py
53 lines (40 loc) · 1.41 KB
/
zzDelRedC.py
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
import boto3
import configparser
import os
import sys
import pytz
from datetime import datetime
utc=pytz.UTC
class Printer():
"""Print things to stdout on one line dynamically"""
def __init__(self,data):
sys.stdout.write("\r\x1b[K"+data.__str__())
sys.stdout.flush()
config = configparser.ConfigParser()
config.read("dwh.cfg")
os.environ['AWS_ACCESS_KEY_ID']=config['AWS']['KEY']
os.environ['AWS_SECRET_ACCESS_KEY']=config['AWS']['SECRET']
client = boto3.client("redshift", region_name="eu-central-1")
cid = config["Red"]["DWH_CLUSTER_IDENTIFIER"]
snn_base = "sbmd-final-snapshot"
snn = snn_base + "-" + datetime.now().strftime("%y-%m-%d-%H-%M")
#steer whether do create a final snappshot on delete
if sys.argv[1] == "with":
response = client.delete_cluster(
ClusterIdentifier=cid,
SkipFinalClusterSnapshot=False,
FinalClusterSnapshotIdentifier=snn,
FinalClusterSnapshotRetentionPeriod=-1
)
else:
response = client.delete_cluster(
ClusterIdentifier=cid,
SkipFinalClusterSnapshot=True,
FinalClusterSnapshotRetentionPeriod=1
)
dbdesc = client.describe_clusters(ClusterIdentifier=cid)
dbstate = dbdesc["Clusters"][0]["ClusterStatus"]
while dbstate:
dbdesc = client.describe_clusters(ClusterIdentifier=cid)
dbstate = dbdesc["Clusters"][0]["ClusterStatus"]
Printer(dbstate)