forked from bn222/cluster-deployment-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcda.py
executable file
·112 lines (86 loc) · 3.19 KB
/
cda.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
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
from assistedInstaller import AssistedClientAutomation
from assistedInstallerService import AssistedInstallerService
from clustersConfig import ClustersConfig
from clusterDeployer import ClusterDeployer
from isoDeployer import IsoDeployer
from arguments import parse_args
import argparse
import host
from logger import logger
from clusterSnapshotter import ClusterSnapshotter
from virtualBridge import VirBridge
def check_and_cleanup_disk(threshold_gb: int = 10) -> None:
h = host.LocalHost()
_, _, free = h.disk_usage("/")
if free < threshold_gb * 1024 * 1024 * 1024:
h.run("podman image prune -a -f")
def main_deploy_openshift(cc: ClustersConfig, args: argparse.Namespace) -> None:
# Make sure the local virtual bridge base configuration is correct.
local_bridge = VirBridge(host.LocalHost(), cc.local_bridge_config)
local_bridge.configure(api_port=None)
# microshift does not use assisted installer so we don't need this check
if args.url == cc.ip_range[0]:
resume_deployment = "master" not in args.steps
ais = AssistedInstallerService(cc.version, args.url, resume_deployment, cc.proxy, cc.noproxy)
ais.start()
else:
logger.info(f"Will use Assisted Installer running at {args.url}")
ais = None
"""
Here we will use the AssistedClient from the aicli package from:
https://github.com/karmab/aicli
The usage details are here:
https://aicli.readthedocs.io/en/latest/
"""
ai = AssistedClientAutomation(f"{args.url}:8090")
cd = ClusterDeployer(cc, ai, args.steps, args.secrets_path)
if args.teardown or args.teardown_full:
cd.teardown_workers()
cd.teardown_masters()
else:
cd.deploy()
if args.teardown_full and ais:
ais.stop()
def main_deploy_iso(cc: ClustersConfig, args: argparse.Namespace) -> None:
id = IsoDeployer(cc, args.steps)
id.deploy()
def main_deploy(args: argparse.Namespace) -> None:
cc = ClustersConfig(
args.config,
secrets_path=args.secrets_path,
worker_range=args.worker_range,
)
check_and_cleanup_disk(10)
if cc.kind == "openshift":
main_deploy_openshift(cc, args)
else:
main_deploy_iso(cc, args)
def main_snapshot(args: argparse.Namespace) -> None:
args = parse_args()
cc = ClustersConfig(
args.config,
worker_range=args.worker_range,
)
ais = AssistedInstallerService(cc.version, args.url)
ai = AssistedClientAutomation(f"{args.url}:8090")
name = cc.name if args.name is None else args.name
cs = ClusterSnapshotter(cc, ais, ai, name)
if args.loadsave == "load":
cs.import_cluster()
elif args.loadsave == "save":
cs.export_cluster()
else:
logger.error(f"Unexpected action {args.actions}")
def main() -> None:
args = parse_args()
if not (args.config.endswith('.yaml') or args.config.endswith('.yml')):
print("Please specify a yaml configuration file")
raise SystemExit(1)
if args.subcommand == "deploy":
main_deploy(args)
elif args.subcommand == "snapshot":
main_snapshot(args)
if __name__ == "__main__":
main()