|
1 | 1 | #!/usr/bin/env python |
| 2 | +import argparse |
2 | 3 | import json |
3 | 4 | import os |
| 5 | +import urllib |
4 | 6 | import yaml |
5 | 7 |
|
| 8 | +parser = argparse.ArgumentParser() |
| 9 | +parser.add_argument('--channel', help='the CoreOS channel to use', default='stable') |
| 10 | +parser.add_argument('--version', help='the CoreOS version to use', default='current') |
| 11 | +args = vars(parser.parse_args()) |
| 12 | + |
| 13 | +url = "http://{channel}.release.core-os.net/amd64-usr/{version}/coreos_production_ami_all.json".format(**args) |
| 14 | +try: |
| 15 | + amis = json.load(urllib.urlopen(url)) |
| 16 | +except (IOError, ValueError): |
| 17 | + print "The URL {} is invalid.".format(url) |
| 18 | + raise |
| 19 | + |
6 | 20 | CURR_DIR = os.path.dirname(os.path.realpath(__file__)) |
7 | 21 |
|
8 | 22 | # Add AWS-specific units to the shared user-data |
|
72 | 86 | ''' |
73 | 87 |
|
74 | 88 | new_units = [ |
75 | | - dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}), |
76 | | - dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}), |
77 | | - dict({'name': 'docker.service', 'drop-ins': [{'name': '90-after-docker-volume.conf', 'content': DOCKER_DROPIN}]}), |
78 | | - dict({'name': 'format-etcd-volume.service', 'command': 'start', 'content': FORMAT_ETCD_VOLUME}), |
79 | | - dict({'name': 'media-etcd.mount', 'command': 'start', 'content': MOUNT_ETCD_VOLUME}), |
80 | | - dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}), |
81 | | - dict({'name': 'etcd.service', 'drop-ins': [{'name': '90-after-etcd-volume.conf', 'content': ETCD_DROPIN}]}) |
| 89 | + dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}), |
| 90 | + dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}), |
| 91 | + dict({'name': 'docker.service', 'drop-ins': [{'name': '90-after-docker-volume.conf', 'content': DOCKER_DROPIN}]}), |
| 92 | + dict({'name': 'format-etcd-volume.service', 'command': 'start', 'content': FORMAT_ETCD_VOLUME}), |
| 93 | + dict({'name': 'media-etcd.mount', 'command': 'start', 'content': MOUNT_ETCD_VOLUME}), |
| 94 | + dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}), |
| 95 | + dict({'name': 'etcd.service', 'drop-ins': [{'name': '90-after-etcd-volume.conf', 'content': ETCD_DROPIN}]}) |
82 | 96 | ] |
83 | 97 |
|
84 | 98 | data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r')) |
|
93 | 107 | header = ["#cloud-config", "---"] |
94 | 108 | dump = yaml.dump(data, default_flow_style=False) |
95 | 109 |
|
96 | | -template = json.load(open(os.path.join(CURR_DIR, 'deis.template.json'),'r')) |
| 110 | +template = json.load(open(os.path.join(CURR_DIR, 'deis.template.json'), 'r')) |
97 | 111 |
|
98 | | -template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ "\n", header + dump.split("\n") ] |
| 112 | +template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = ["\n", header + dump.split("\n")] |
99 | 113 | template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3)) |
| 114 | +template['Mappings']['CoreOSAMIs'] = dict(map(lambda n: (n['name'], dict(PV=n['pv'], HVM=n['hvm'])), amis['amis'])) |
100 | 115 |
|
101 | 116 | VPC_ID = os.getenv('VPC_ID', None) |
102 | 117 | VPC_SUBNETS = os.getenv('VPC_SUBNETS', None) |
103 | 118 | VPC_PRIVATE_SUBNETS = os.getenv('VPC_PRIVATE_SUBNETS', VPC_SUBNETS) |
104 | 119 | VPC_ZONES = os.getenv('VPC_ZONES', None) |
105 | 120 |
|
106 | 121 | if VPC_ID and VPC_SUBNETS and VPC_ZONES and len(VPC_SUBNETS.split(',')) == len(VPC_ZONES.split(',')): |
107 | | - # skip VPC, subnet, route, and internet gateway creation |
108 | | - del template['Resources']['VPC'] |
109 | | - del template['Resources']['Subnet1'] |
110 | | - del template['Resources']['Subnet2'] |
111 | | - del template['Resources']['Subnet1RouteTableAssociation'] |
112 | | - del template['Resources']['Subnet2RouteTableAssociation'] |
113 | | - del template['Resources']['InternetGateway'] |
114 | | - del template['Resources']['GatewayToInternet'] |
115 | | - del template['Resources']['PublicRouteTable'] |
116 | | - del template['Resources']['PublicRoute'] |
117 | | - del template['Resources']['CoreOSServerLaunchConfig']['DependsOn'] |
118 | | - del template['Resources']['DeisWebELB']['DependsOn'] |
119 | | - |
120 | | - # update VpcId fields |
121 | | - template['Resources']['DeisWebELBSecurityGroup']['Properties']['VpcId'] = VPC_ID |
122 | | - template['Resources']['VPCSecurityGroup']['Properties']['VpcId'] = VPC_ID |
123 | | - |
124 | | - # update subnets and zones |
125 | | - template['Resources']['CoreOSServerAutoScale']['Properties']['AvailabilityZones'] = VPC_ZONES.split(',') |
126 | | - template['Resources']['CoreOSServerAutoScale']['Properties']['VPCZoneIdentifier'] = VPC_PRIVATE_SUBNETS.split(',') |
127 | | - template['Resources']['DeisWebELB']['Properties']['Subnets'] = VPC_SUBNETS.split(',') |
| 122 | + # skip VPC, subnet, route, and internet gateway creation |
| 123 | + del template['Resources']['VPC'] |
| 124 | + del template['Resources']['Subnet1'] |
| 125 | + del template['Resources']['Subnet2'] |
| 126 | + del template['Resources']['Subnet1RouteTableAssociation'] |
| 127 | + del template['Resources']['Subnet2RouteTableAssociation'] |
| 128 | + del template['Resources']['InternetGateway'] |
| 129 | + del template['Resources']['GatewayToInternet'] |
| 130 | + del template['Resources']['PublicRouteTable'] |
| 131 | + del template['Resources']['PublicRoute'] |
| 132 | + del template['Resources']['CoreOSServerLaunchConfig']['DependsOn'] |
| 133 | + del template['Resources']['DeisWebELB']['DependsOn'] |
| 134 | + |
| 135 | + # update VpcId fields |
| 136 | + template['Resources']['DeisWebELBSecurityGroup']['Properties']['VpcId'] = VPC_ID |
| 137 | + template['Resources']['VPCSecurityGroup']['Properties']['VpcId'] = VPC_ID |
| 138 | + |
| 139 | + # update subnets and zones |
| 140 | + template['Resources']['CoreOSServerAutoScale']['Properties']['AvailabilityZones'] = VPC_ZONES.split(',') |
| 141 | + template['Resources']['CoreOSServerAutoScale']['Properties']['VPCZoneIdentifier'] = VPC_PRIVATE_SUBNETS.split(',') |
| 142 | + template['Resources']['DeisWebELB']['Properties']['Subnets'] = VPC_SUBNETS.split(',') |
128 | 143 |
|
129 | 144 | print json.dumps(template) |
0 commit comments