forked from brianr/uuss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roll
executable file
·58 lines (51 loc) · 2.01 KB
/
roll
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
#!/usr/bin/env python
import argparse
import re
import shlex
import subprocess
import sys
def munge_arg(arg):
if arg[:4] == "prod":
return "production"
if arg[:4] == "stag":
return "staging"
return arg
def munge_args(args):
return [munge_arg(arg) for arg in args]
def parse_args(args):
import argparse
parser = argparse.ArgumentParser(description='Roll UUSS')
parser.add_argument('-e', '--environment',
choices=['production', 'staging', 'next', 'beta', 'release', 'support', 'sandbox', 'alpha'],
help='The environment to roll to',
required=True)
parser.add_argument('-g', '--game',
choices=['india', 'dane', 'rich', 'victoria'],
help="""The game we're deploying for""",
required=True)
parser.add_argument('hosts', metavar="host", type=str, nargs='*',
help='''Host to deploy to. If none given, defaults will be used.''')
return parser.parse_args(args)
def main(args):
args = munge_args(args)
args = parse_args(args)
if args.hosts:
hosts = args.hosts
else:
if args.environment == "production":
hosts = [ host[2] for host in
[ re.split(r'\s+',
# remove comments
re.sub(r'#.*$', r'', line.strip()))
for line
in open('/etc/hosts', 'r').readlines()]
if len(host) > 2 and args.game in host[2] and 'uuss' in host[2] ]
elif args.game in [ "india", "rich" ] or (args.game == "dane" and args.environment in ["release", "next"]):
hosts = [ "%s-%s" % (args.game, args.environment) ]
else:
hosts = [ "dev3" ]
cmd = "./do_roll.sh %s %s" % (args.environment, args.game)
process = subprocess.Popen(shlex.split(cmd) + hosts)
process.wait()
if __name__ == '__main__':
main(sys.argv[1:])