4
4
Delete infrastructure for a cluster without using Terraform. Useful for CI clusters.
5
5
6
6
Usage:
7
- delete-cluster.py PREFIX
7
+ delete-cluster.py PREFIX [--force]
8
8
9
9
Where PREFIX is the string at the start of the resource's names.
10
- It will list matching resources and prompt to confirm deletion .
10
+ If --force is provided, it will delete all resources without confirmation .
11
11
"""
12
12
13
- import sys , json , subprocess , pprint
13
+ import sys , json , subprocess
14
14
15
15
16
16
CLUSTER_RESOURCES = ['server' , 'port' , 'volume' ]
17
17
18
- def delete_cluster (cluster_prefix ):
18
+ def delete_cluster (cluster_prefix , force = False ):
19
19
to_delete = {}
20
20
for resource_type in CLUSTER_RESOURCES :
21
21
to_delete [resource_type ] = []
@@ -29,7 +29,8 @@ def delete_cluster(cluster_prefix):
29
29
except :
30
30
print (resource_type , item )
31
31
raise
32
- if input ('Delete these (y/n)?:' ) == 'y' :
32
+
33
+ if force or input ('Delete these (y/n)?:' ) == 'y' :
33
34
for resource_type in CLUSTER_RESOURCES :
34
35
items = [v ['ID' ] for v in to_delete [resource_type ]]
35
36
if items :
@@ -40,7 +41,10 @@ def delete_cluster(cluster_prefix):
40
41
print ('Cancelled - no resources deleted' )
41
42
42
43
if __name__ == '__main__' :
43
- if len (sys .argv ) != 2 :
44
+ if len (sys .argv ) < 2 or len ( sys . argv ) > 3 :
44
45
print ('ERROR: Incorrect argument(s).\n ' + __doc__ )
45
46
exit (1 )
46
- delete_cluster (sys .argv [1 ])
47
+ force_flag = '--force' in sys .argv
48
+ cluster_prefix = sys .argv [1 ]
49
+ delete_cluster (cluster_prefix , force_flag )
50
+
0 commit comments