-
Notifications
You must be signed in to change notification settings - Fork 16
/
conf.py
executable file
·86 lines (72 loc) · 2.94 KB
/
conf.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 python3
import argparse
import json
import sys
parser = argparse.ArgumentParser(description='Johanna configuration script')
parser.add_argument('--email', help='Your Admin Email')
parser.add_argument('--accesskey', help='AWS Access Key ID')
parser.add_argument('--secretkey', help='AWS Secret Access Key')
parser.add_argument('--region', help='Choose AWS Region')
parser.add_argument('--az1', help='AWS Availability Zone 1')
parser.add_argument('--az2', help='AWS Availability Zone 2')
parser.add_argument('--template', help='git URL of provisioning template repository')
parser.add_argument('--user', help='RDS User Name')
parser.add_argument('--pw', help='RDS User Password')
if __name__ == '__main__':
options, args = parser.parse_args()
required_args = [
args.accesskey,
args.az1,
args.az2,
args.email,
args.pw,
args.region,
args.secretkey,
args.user
]
for arg in required_args:
if not arg:
parser.print_help()
sys.exit(0)
config = json.loads(open('config_sample.json').read())
# AWS ACCESS KEY ID
config['aws']['AWS_ACCESS_KEY_ID'] = args.accesskey
# AWS SECRET ACCESS KEY
config['aws']['AWS_SECRET_ACCESS_KEY'] = args.secretkey
# AWS REGION
AWS_REGIONS = ['us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', 'eu-central-1', 'ap-southest-1', 'ap-southest-2',
'ap-northeast-1', 'ap-northeast-2', 'ap-south-1', 'sa-east-1']
if args.region not in AWS_REGIONS:
print('Invalid Region Name')
sys.exit(0)
config['aws']['AWS_REGION'] = args.region
# AWS AVAILABILITY ZONE 1
if args.region not in args.az1:
print('Invalid AWS_AVAILABILITY_ZONE_1')
sys.exit(0)
config['aws']['AWS_AVAILABILITY_ZONE_1'] = args.az1
# AWS AVAILABILITY ZONE 2
if args.region not in args.az2:
print('Invalid AWS_AVAILABILITY_ZONE_2')
sys.exit(0)
config['aws']['AWS_AVAILABILITY_ZONE_2'] = args.az2
# AWS TEMPLATE
if args.template and args.template != config['template']['GIT_URL']:
config['template']['GIT_URL'] = args.template
config['elasticbeanstalk']['ENVIRONMENTS'] = []
else:
nova = config['elasticbeanstalk']['ENVIRONMENTS'][0]
nova_cname = nova['CNAME']
nova['HOST'] = '%s.%s.elasticbeanstalk.com' % (nova_cname, args.region)
nova['URL'] = 'http://%s.%s.elasticbeanstalk.com' % (nova_cname, args.region)
nova['AWS_EB_NOTIFICATION_EMAIL'] = args.email
# RDS User Configuration
config['rds']['USER_NAME'] = args.user
config['rds']['USER_PASSWORD'] = args.pw
# VPC Configuration
config['vpc'][0]['AWS_REGION'] = args.region
config['vpc'][0]['AWS_AVAILABILITY_ZONE_1'] = args.az1
config['vpc'][0]['AWS_AVAILABILITY_ZONE_2'] = args.az2
config_file = open('config.json', 'w+')
config_file.write(json.dumps(config, sort_keys=True, indent=2))
config_file.close()