|
10 | 10 | parser.add_argument('--version', help='the CoreOS version to use', default='current') |
11 | 11 | args = vars(parser.parse_args()) |
12 | 12 |
|
13 | | -amis = json.load(urllib.urlopen("http://%(channel)s.release.core-os.net/amd64-usr/%(version)s/coreos_production_ami_all.json" % args)) |
| 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 |
14 | 19 |
|
15 | 20 | CURR_DIR = os.path.dirname(os.path.realpath(__file__)) |
16 | 21 |
|
|
81 | 86 | ''' |
82 | 87 |
|
83 | 88 | new_units = [ |
84 | | - dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}), |
85 | | - dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}), |
86 | | - dict({'name': 'docker.service', 'drop-ins': [{'name': '90-after-docker-volume.conf', 'content': DOCKER_DROPIN}]}), |
87 | | - dict({'name': 'format-etcd-volume.service', 'command': 'start', 'content': FORMAT_ETCD_VOLUME}), |
88 | | - dict({'name': 'media-etcd.mount', 'command': 'start', 'content': MOUNT_ETCD_VOLUME}), |
89 | | - dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}), |
90 | | - 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}]}) |
91 | 96 | ] |
92 | 97 |
|
93 | 98 | data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r')) |
|
102 | 107 | header = ["#cloud-config", "---"] |
103 | 108 | dump = yaml.dump(data, default_flow_style=False) |
104 | 109 |
|
105 | | -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')) |
106 | 111 |
|
107 | | -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")] |
108 | 113 | template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3)) |
109 | 114 | template['Mappings']['CoreOSAMIs'] = dict(map(lambda n: (n['name'], dict(PV=n['pv'], HVM=n['hvm'])), amis['amis'])) |
110 | 115 |
|
|
114 | 119 | VPC_ZONES = os.getenv('VPC_ZONES', None) |
115 | 120 |
|
116 | 121 | if VPC_ID and VPC_SUBNETS and VPC_ZONES and len(VPC_SUBNETS.split(',')) == len(VPC_ZONES.split(',')): |
117 | | - # skip VPC, subnet, route, and internet gateway creation |
118 | | - del template['Resources']['VPC'] |
119 | | - del template['Resources']['Subnet1'] |
120 | | - del template['Resources']['Subnet2'] |
121 | | - del template['Resources']['Subnet1RouteTableAssociation'] |
122 | | - del template['Resources']['Subnet2RouteTableAssociation'] |
123 | | - del template['Resources']['InternetGateway'] |
124 | | - del template['Resources']['GatewayToInternet'] |
125 | | - del template['Resources']['PublicRouteTable'] |
126 | | - del template['Resources']['PublicRoute'] |
127 | | - del template['Resources']['CoreOSServerLaunchConfig']['DependsOn'] |
128 | | - del template['Resources']['DeisWebELB']['DependsOn'] |
129 | | - |
130 | | - # update VpcId fields |
131 | | - template['Resources']['DeisWebELBSecurityGroup']['Properties']['VpcId'] = VPC_ID |
132 | | - template['Resources']['VPCSecurityGroup']['Properties']['VpcId'] = VPC_ID |
133 | | - |
134 | | - # update subnets and zones |
135 | | - template['Resources']['CoreOSServerAutoScale']['Properties']['AvailabilityZones'] = VPC_ZONES.split(',') |
136 | | - template['Resources']['CoreOSServerAutoScale']['Properties']['VPCZoneIdentifier'] = VPC_PRIVATE_SUBNETS.split(',') |
137 | | - 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(',') |
138 | 143 |
|
139 | 144 | print json.dumps(template) |
0 commit comments