This repository has been archived by the owner on Apr 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vagrant-toolbox.py
executable file
·103 lines (90 loc) · 5.33 KB
/
vagrant-toolbox.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/python
import os, signal, sys, time
from lib.config import Config
from lib.configs.vagrant_config import VagrantConfig
from lib.utils import Utils
LOG = VagrantConfig.setup(__file__)
def validate_input():
mesos_build = VagrantConfig.mesos_build()
marathon_build = VagrantConfig.marathon_build()
operating_system = VagrantConfig.operating_system()
if operating_system not in VagrantConfig.supported_operating_systems():
Utils.exit_with_cmd_error( __file__,
"Operating system ({}) is not supported. Available values: {}".format(
operating_system,
str(VagrantConfig.supported_operating_systems()) ))
if mesos_build == "":
Utils.exit_with_cmd_error( __file__, "Mesos build version not given. Run mesos-toolbox show-builds to see what the available builds are.")
if marathon_build == "":
Utils.exit_with_cmd_error( __file__, "Marathon build version not given. Run marathon-toolbox show-builds to see what the available builds are.")
mesos_build_name = "{}-{}".format(VagrantConfig.mesos_build(), VagrantConfig.operating_system().replace(":", "-"))
if mesos_build_name not in Utils.list_builds("{}/mesos".format(VagrantConfig.mesos_packages_dir())):
Utils.exit_with_cmd_error( __file__, "Mesos build {} does not exist. Please build that version first with mesos-toolbox.".format(mesos_build_name))
if VagrantConfig.marathon_build() not in Utils.list_builds(VagrantConfig.marathon_packages_dir()):
Utils.exit_with_cmd_error( __file__, "Marathon build {} does not exist. Please build that version first with mesos-toolbox.".format(VagrantConfig.marathon_build()))
def signal_handler(signal, frame):
if Utils.has_processes_running():
Utils.stop_processes()
def get_exports_from_config():
exports = dict()
exports['DEPLOYMENT_NAME'] = VagrantConfig.deployment_name()
exports['CONSENSUS_IPS'] = VagrantConfig.consensus_ips()
exports['MASTER_IPS'] = VagrantConfig.master_ips()
exports['AGENT_IPS'] = VagrantConfig.agent_ips()
exports['CONSENSUS_MEMORY'] = VagrantConfig.consensus_memory()
exports['MASTER_MEMORY'] = VagrantConfig.master_memory()
exports['AGENT_MEMORY'] = VagrantConfig.agent_memory()
exports['TARGET_OS'] = VagrantConfig.operating_system()
exports['MESOS_VERSION'] = VagrantConfig.mesos_build()
exports['MARATHON_VERSION'] = VagrantConfig.marathon_build().replace("v", "", 1)
exports['MESOS_BUILD_DIR'] = "{}/mesos/{}-{}".format(VagrantConfig.mesos_packages_dir(),
VagrantConfig.mesos_build(),
VagrantConfig.operating_system().replace(":", "-"))
exports['MARATHON_BUILD_DIR'] = "{}/{}".format(VagrantConfig.marathon_packages_dir(),
VagrantConfig.marathon_build())
return exports
def vagrant_command(cmd):
validate_input()
signal.signal(signal.SIGINT, signal_handler)
base = os.path.dirname(os.path.abspath(__file__))
command = "cd {}/vagrant".format(base)
exports = get_exports_from_config()
first_master_ip = exports['MASTER_IPS'].split(',')[0]
for key, value in exports.iteritems():
command = "{}; export {}={}".format(command, key, value)
command = "{}; vagrant {}".format(command, cmd)
if VagrantConfig.machine() != "":
command = "{} {}".format(command, VagrantConfig.machine())
result = Utils.cmd(command, True)
if result['ExitCode'] != 0:
Utils.print_result_error(LOG, "Vagrant command execution has failed.", result)
else:
if cmd == "up":
LOG.info("You cluster is up and running \\o/.")
LOG.info("- to access the Mesos UI, point your browser to: http://{}:5050".format(first_master_ip))
LOG.info("- to access the Consul UI, point your browser to: http://{}:8500".format(first_master_ip))
LOG.info("- to access the Marathon UI, point your browser to: http://{}:8080".format(first_master_ip))
## ----------------------------------------------------------------------------------------------
## OPERATIONS:
## ----------------------------------------------------------------------------------------------
def op_destroy(): vagrant_command("destroy -f")
def op_halt(): vagrant_command("halt")
def op_provision(): vagrant_command("provision")
def op_resume(): vagrant_command("resume")
def op_ssh(): vagrant_command("ssh")
def op_status(): vagrant_command("status")
def op_suspend(): vagrant_command("suspend")
def op_up(): vagrant_command("up")
def op_check_this_system():
LOG.info("Checking dependencies:")
LOG.info(" -> Vagrant? : {}".format( "Yes" if Utils.is_vagrant_available() else "No" ))
if __name__ == "__main__":
if "destroy-f" == VagrantConfig.command(): op_destroy()
if "halt" == VagrantConfig.command(): op_halt()
if "provision" == VagrantConfig.command(): op_provision()
if "resume" == VagrantConfig.command(): op_resume()
if "ssh" == VagrantConfig.command(): op_ssh()
if "status" == VagrantConfig.command(): op_status()
if "suspend" == VagrantConfig.command(): op_suspend()
if "up" == VagrantConfig.command(): op_up()
if "check-this-system" == VagrantConfig.command(): op_check_this_system()