This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
gantryd.py
executable file
·86 lines (68 loc) · 2.56 KB
/
gantryd.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
#!/usr/bin/env python
from gantryd.client import GantryDClient
import argparse
import json
ETCD_HOST = '127.0.0.1'
ETCD_PORT = 4001
def run(dclient, args):
""" Runs gantryd. """
dclient.run(args.component)
def getconfig(dclient, args):
""" Prints out the current project configuration stored in etcd. """
config = None
try:
config = dclient.getConfigJSON()
except:
pass
if not config:
print 'No config found'
return
print json.dumps(json.loads(config), sort_keys=True, indent=2, separators=(',', ': '))
def setconfig(dclient, args):
""" Sets the current project configuration stored in etcd. """
if not args.configfile:
print 'Missing configfile parameter'
return
with open(args.configfile, 'r') as f:
dclient.setConfig(json.loads(f.read()))
print 'Configuration updated'
def list_status(dclient, args):
""" Lists the status of all components in gantryd. """
dclient.listStatus()
def mark_updated(dclient, args):
""" Marks a component to be updated. """
dclient.markUpdated(args.component)
def stop(dclient, args):
""" Marks a component to be stopped. """
dclient.stopComponents(args.component)
def kill(dclient, args):
""" Marks a component to be killed. """
dclient.killComponents(args.component)
ACTIONS = {
'run': run,
'getconfig': getconfig,
'setconfig': setconfig,
'list': list_status,
'update': mark_updated,
'stop': stop,
'kill': kill
}
def start():
# Setup the gantryd arguments.
parser = argparse.ArgumentParser(description='gantry continuous deployment system daemon')
parser.add_argument('action', help='The action to perform', choices=ACTIONS.keys())
parser.add_argument('project', help='The name of the project containing the components')
parser.add_argument('configfile', help='The name of the config file. Only applies to setconfig.', nargs='?')
parser.add_argument('-c', help='A component to watch and run', nargs='+', type=str, dest='component')
parser.add_argument('-etcd', help='The etcd endpoint to which the client should connect. Defaults to 127.0.0.1', dest='etcd_host', nargs='?', const=ETCD_HOST)
parser.add_argument('-etcdport', help='The client port of the etcd endpoint. Defaults to 4001.', dest='etcd_port', nargs='?', const=ETCD_PORT)
# Parse the arguments.
args = parser.parse_args()
port = int(args.etcd_port) if args.etcd_port else ETCD_PORT
# Initialize the gantryd client.
dclient = GantryDClient(args.etcd_host or ETCD_HOST, args.project, port)
# Run the action.
action = ACTIONS[args.action]
action(dclient, args)
if __name__ == "__main__":
start()