-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgen-json.py
More file actions
executable file
·40 lines (32 loc) · 1.71 KB
/
gen-json.py
File metadata and controls
executable file
·40 lines (32 loc) · 1.71 KB
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
#!/usr/bin/env python
import json
import os
template = json.load(open("deis.template.json",'r'))
with open('../coreos/user-data','r') as f:
lines = f.readlines()
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ '', lines ]
template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3))
VPC_ID = os.getenv('VPC_ID', None)
VPC_SUBNETS = os.getenv('VPC_SUBNETS', None)
VPC_ZONES = os.getenv('VPC_ZONES', None)
if VPC_ID and VPC_SUBNETS and VPC_ZONES and len(VPC_SUBNETS.split(',')) == len(VPC_ZONES.split(',')):
# skip VPC, subnet, route, and internet gateway creation
del template['Resources']['VPC']
del template['Resources']['Subnet1']
del template['Resources']['Subnet2']
del template['Resources']['Subnet1RouteTableAssociation']
del template['Resources']['Subnet2RouteTableAssociation']
del template['Resources']['InternetGateway']
del template['Resources']['GatewayToInternet']
del template['Resources']['PublicRouteTable']
del template['Resources']['PublicRoute']
del template['Resources']['CoreOSServerLaunchConfig']['DependsOn']
del template['Resources']['DeisWebELB']['DependsOn']
# update VpcId fields
template['Resources']['DeisWebELBSecurityGroup']['Properties']['VpcId'] = VPC_ID
template['Resources']['VPCSecurityGroup']['Properties']['VpcId'] = VPC_ID
# update subnets and zones
template['Resources']['CoreOSServerAutoScale']['Properties']['AvailabilityZones'] = VPC_ZONES.split(',')
template['Resources']['CoreOSServerAutoScale']['Properties']['VPCZoneIdentifier'] = VPC_SUBNETS.split(',')
template['Resources']['DeisWebELB']['Properties']['Subnets'] = VPC_SUBNETS.split(',')
print json.dumps(template)