-
Notifications
You must be signed in to change notification settings - Fork 5
/
hcp-burner.py
executable file
·103 lines (92 loc) · 4.41 KB
/
hcp-burner.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import time
import importlib
import threading
import signal
from libs.arguments import Arguments
from libs.logging import Logging
from libs.elasticsearch import Elasticsearch
from libs.utils import Utils
if __name__ == "__main__":
arguments = Arguments(os.environ)
logging = Logging(arguments["log_level"], arguments["log_file"])
es = Elasticsearch(logging, arguments["es_url"], arguments["es_index"], arguments["es_insecure"], arguments["es_index_retry"]) if arguments["es_url"] else None
utils = Utils(logging)
logging.info(f"Detected {arguments['platform']} as platform")
try:
if arguments["subplatform"]:
logging.info(f"Detected {arguments['subplatform']} as subplatform, loading its module...")
platform_module_path = "libs.platforms." + arguments["platform"] + "." + arguments["subplatform"] + "." + arguments["subplatform"]
platform_module = importlib.import_module(platform_module_path)
PlatformClass = getattr(platform_module, arguments["subplatform"].capitalize())
platform = PlatformClass(arguments, logging, utils, es)
else:
logging.info(f"Subplatform not detected, loading {arguments['platform']} module...")
platform_module_path = "libs.platforms." + arguments["platform"] + "." + arguments["platform"]
platform_module = importlib.import_module(platform_module_path)
PlatformClass = getattr(platform_module, arguments["platform"].capitalize())
platform = PlatformClass(arguments, logging, utils, es)
except ImportError as err:
logging.error("Module not found)")
logging.error(err)
sys.exit("Exiting...")
except AttributeError as err:
logging.error("Invalid platform class in module")
logging.error(err)
sys.exit("Exiting...")
logging.info(f"Verifying external binaries required by the {arguments['platform']} platform")
for command in platform.environment["commands"]:
utils.verify_cmnd(command)
platform.initialize()
if str(platform.environment['install_clusters']).lower() == "true":
logging.info("Starting capturing Ctrl-C key from this point")
signal.signal(signal.SIGINT, utils.set_force_terminate)
watcher = threading.Thread(target=platform.watcher)
watcher.daemon = True
watcher.start()
install_threads = utils.install_scheduler(platform)
logging.info(f"{len(install_threads)} threads created for installing clusters. Waiting for them to finish")
for thread in install_threads:
try:
thread.join()
except RuntimeError as err:
if "cannot join current thread" in err.args[0]:
# catchs main thread
continue
else:
raise
watcher.join()
if 'enabled' in platform.environment['load'] and str(platform.environment['load']['enabled']).lower() == "true":
# Prometheus takes a lot of time to start after all nodes are ready. we maybe needs to increase this sleep in the future
platform = utils.get_cluster_info(platform)
logging.info("Waiting 5 minutes to allow all clusters to create all pods")
time.sleep(300)
load_threads = utils.load_scheduler(platform)
logging.info(f"{len(load_threads)} threads created to execute workloads. Waiting for them to finish")
for thread in load_threads:
try:
thread.join()
except RuntimeError as err:
if "cannot join current thread" in err.args[0]:
# catchs main thread
continue
else:
raise
if str(platform.environment["cleanup_clusters"]).lower() == "true":
platform = utils.get_cluster_info(platform)
delete_threads = utils.cleanup_scheduler(platform)
logging.info(f"{len(delete_threads)} threads created for deleting clusters. Waiting for them to finish")
for thread in delete_threads:
try:
thread.join()
except RuntimeError as err:
if "cannot join current thread" in err.args[0]:
# catchs main thread
continue
else:
raise
platform.platform_cleanup()
# utils.test_recap(platform)