github.com/keithballdotnet/deis@v1.0.1-0.20141111034523-a4511c46a6ce/contrib/ec2/gen-json.py (about) 1 #!/usr/bin/env python 2 import json 3 import os 4 5 template = json.load(open("deis.template.json",'r')) 6 7 with open('../coreos/user-data','r') as f: 8 lines = f.readlines() 9 10 template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ '', lines ] 11 template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3)) 12 13 VPC_ID = os.getenv('VPC_ID', None) 14 VPC_SUBNETS = os.getenv('VPC_SUBNETS', None) 15 VPC_ZONES = os.getenv('VPC_ZONES', None) 16 17 if VPC_ID and VPC_SUBNETS and VPC_ZONES and len(VPC_SUBNETS.split(',')) == len(VPC_ZONES.split(',')): 18 # skip VPC, subnet, route, and internet gateway creation 19 del template['Resources']['VPC'] 20 del template['Resources']['Subnet1'] 21 del template['Resources']['Subnet2'] 22 del template['Resources']['Subnet1RouteTableAssociation'] 23 del template['Resources']['Subnet2RouteTableAssociation'] 24 del template['Resources']['InternetGateway'] 25 del template['Resources']['GatewayToInternet'] 26 del template['Resources']['PublicRouteTable'] 27 del template['Resources']['PublicRoute'] 28 del template['Resources']['CoreOSServerLaunchConfig']['DependsOn'] 29 del template['Resources']['DeisWebELB']['DependsOn'] 30 31 # update VpcId fields 32 template['Resources']['DeisWebELBSecurityGroup']['Properties']['VpcId'] = VPC_ID 33 template['Resources']['VPCSecurityGroup']['Properties']['VpcId'] = VPC_ID 34 35 # update subnets and zones 36 template['Resources']['CoreOSServerAutoScale']['Properties']['AvailabilityZones'] = VPC_ZONES.split(',') 37 template['Resources']['CoreOSServerAutoScale']['Properties']['VPCZoneIdentifier'] = VPC_SUBNETS.split(',') 38 template['Resources']['DeisWebELB']['Properties']['Subnets'] = VPC_SUBNETS.split(',') 39 40 print json.dumps(template)