-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcleanup-nodes.py
executable file
·61 lines (42 loc) · 1.55 KB
/
cleanup-nodes.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
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import sys
import json
from datetime import datetime
from openstack_cloud import OpenstackCloud
def load_output(output_filename):
with open(output_filename) as f:
# Read the file
output = json.load(f)
return output
def cleanup_enterprise(cloud_config, enterprise):
ret = {}
ret["cleanup_start"] = str(datetime.now())
match cloud_config['cloud_type'].lower():
case 'openstack':
print("Using openstack cloud")
cloud = OpenstackCloud(cloud_config)
case _:
print("Cannot find cloud type: " + cloud_config['cloud_type'])
ret['cleanup'] = cloud.cleanup_enterprise(enterprise)
ret["cleanup_end"] = str(datetime.now())
return ret
def main():
if len(sys.argv) != 2:
print("Usage: " + sys.argv[0] + " post-deploy-output.json ")
sys.exit(1)
output_filename = sys.argv[1]
json_output = load_output(output_filename)
cloud_config = json_output['backend_config']
enterprise = json_output['enterprise_to_build']
json_output["cleanup_start_time"] = str(datetime.now())
print("Cleaning up nodes.")
cleanup_results = cleanup_enterprise(cloud_config, enterprise)
print("Cleaning up, completed.")
json_output['cleanup_results'] = cleanup_results
json_output["cleanup_end_time"] = str(datetime.now())
print("Enterprise cleaned. Writing output to cleanup-output.json.")
with open("cleanup-output.json", "w") as f:
json.dump(json_output, f)
return
if __name__ == '__main__':
main()