forked from keikoproj/minion-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minion_manager.py
61 lines (49 loc) · 2.3 KB
/
minion_manager.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
"""The main entry point for the minion-manager."""
import argparse
import sys
import logging
from cloud_broker import Broker
logger = logging.getLogger("minion_manager")
logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s " +
"%(threadName)s: %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
stream=sys.stdout, level=logging.INFO)
def validate_usr_args(usr_args):
"""
Validates the arguments provided by the user.
"""
assert usr_args.cloud.lower() == "aws", "Only AWS is currently supported."
assert usr_args.cluster_name != None, "Cluster name is required"
if "profile" not in usr_args:
usr_args.profile = None
def run():
"""
Parses user provided arguments and validates them. Asserts if any of
the provided arguments is incorrect.
"""
parser = argparse.ArgumentParser(description="Manage the minions in a " +
"K8S cluster")
parser.add_argument("--region", help="Region in which the cluster exists",
required=True)
parser.add_argument("--cloud", default="aws",
help="Cloud provider (only AWS as of now)")
parser.add_argument("--profile", help="Credentials profile to use")
parser.add_argument("--refresh-interval-seconds", default="300",
help="Interval in seconds at which to query AWS")
parser.add_argument("--cluster-name", required=True, help="Name of the Kubernetes cluster. Get's used for identifying ASGs")
parser.add_argument("--monitor-nodes", default=False,
help="Check if nodes are 'Ready' and terminate if not")
usr_args = parser.parse_args()
validate_usr_args(usr_args)
logger.info("Starting minion-manager for cluster: %s, in region " +
"%s for cloud provider %s", usr_args.cluster_name,
usr_args.region, usr_args.cloud)
if usr_args.cloud == "aws":
minion_manager = Broker.get_impl_object(
usr_args.cloud, usr_args.cluster_name, usr_args.region, int(usr_args.refresh_interval_seconds),
aws_profile=usr_args.profile, monitor_nodes=usr_args.monitor_nodes)
minion_manager.run()
# A journey of a thousand miles ...
if __name__ == "__main__":
run()