Skip to content

Commit b5682db

Browse files
carmstrongmboersma
authored andcommitted
fix(contrib/aws): fail when AMIs can't be found
1 parent e386c24 commit b5682db

1 file changed

Lines changed: 36 additions & 31 deletions

File tree

contrib/aws/gen-json.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
parser.add_argument('--version', help='the CoreOS version to use', default='current')
1111
args = vars(parser.parse_args())
1212

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
1419

1520
CURR_DIR = os.path.dirname(os.path.realpath(__file__))
1621

@@ -81,13 +86,13 @@
8186
'''
8287

8388
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}]})
9196
]
9297

9398
data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r'))
@@ -102,9 +107,9 @@
102107
header = ["#cloud-config", "---"]
103108
dump = yaml.dump(data, default_flow_style=False)
104109

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'))
106111

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")]
108113
template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3))
109114
template['Mappings']['CoreOSAMIs'] = dict(map(lambda n: (n['name'], dict(PV=n['pv'], HVM=n['hvm'])), amis['amis']))
110115

@@ -114,26 +119,26 @@
114119
VPC_ZONES = os.getenv('VPC_ZONES', None)
115120

116121
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(',')
138143

139144
print json.dumps(template)

0 commit comments

Comments
 (0)