Skip to content

Commit f949553

Browse files
authored
Update delete-cluster.py to allow --force flag
1 parent 9001626 commit f949553

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

dev/delete-cluster.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
Delete infrastructure for a cluster without using Terraform. Useful for CI clusters.
55
66
Usage:
7-
delete-cluster.py PREFIX
7+
delete-cluster.py PREFIX [--force]
88
99
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.
1111
"""
1212

13-
import sys, json, subprocess, pprint
13+
import sys, json, subprocess
1414

1515

1616
CLUSTER_RESOURCES = ['server', 'port', 'volume']
1717

18-
def delete_cluster(cluster_prefix):
18+
def delete_cluster(cluster_prefix, force=False):
1919
to_delete = {}
2020
for resource_type in CLUSTER_RESOURCES:
2121
to_delete[resource_type] = []
@@ -29,7 +29,8 @@ def delete_cluster(cluster_prefix):
2929
except:
3030
print(resource_type, item)
3131
raise
32-
if input('Delete these (y/n)?:') == 'y':
32+
33+
if force or input('Delete these (y/n)?:') == 'y':
3334
for resource_type in CLUSTER_RESOURCES:
3435
items = [v['ID'] for v in to_delete[resource_type]]
3536
if items:
@@ -40,7 +41,10 @@ def delete_cluster(cluster_prefix):
4041
print('Cancelled - no resources deleted')
4142

4243
if __name__ == '__main__':
43-
if len(sys.argv) != 2:
44+
if len(sys.argv) < 2 or len(sys.argv) > 3:
4445
print('ERROR: Incorrect argument(s).\n' + __doc__)
4546
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

Comments
 (0)