Skip to content

Commit f37aeac

Browse files
committed
Merge pull request #4549 from helgi/aws-amis
ref(contrib/aws): wrap coreos ami fetching into a function
2 parents 29b6c0b + cb867a0 commit f37aeac

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

contrib/aws/gen-json.py

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

13-
url = "http://{channel}.release.core-os.net/amd64-usr/{version}/coreos_production_ami_all.json".format(**args)
14-
try:
15-
amis = json.load(urllib2.urlopen(url))
16-
except (IOError, ValueError):
17-
print "The URL {} is invalid.".format(url)
18-
raise
19-
2013
CURR_DIR = os.path.dirname(os.path.realpath(__file__))
2114

2215
# Add AWS-specific units to the shared user-data
@@ -85,6 +78,16 @@
8578
After=prepare-etcd-data-directory.service
8679
'''
8780

81+
def coreos_amis(channel, version):
82+
url = "http://{channel}.release.core-os.net/amd64-usr/{version}/coreos_production_ami_all.json".format(channel=channel, version=version)
83+
try:
84+
amis = json.load(urllib2.urlopen(url))
85+
except (IOError, ValueError):
86+
print "The URL {} is invalid.".format(url)
87+
raise
88+
89+
return dict(map(lambda n: (n['name'], dict(PV=n['pv'], HVM=n['hvm'])), amis['amis']))
90+
8891
new_units = [
8992
dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}),
9093
dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}),
@@ -112,7 +115,7 @@
112115

113116
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = ["\n", header + dump.split("\n")]
114117
template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3))
115-
template['Mappings']['CoreOSAMIs'] = dict(map(lambda n: (n['name'], dict(PV=n['pv'], HVM=n['hvm'])), amis['amis']))
118+
template['Mappings']['CoreOSAMIs'] = coreos_amis(args['channel'], args['version'])
116119

117120
VPC_ID = os.getenv('VPC_ID', None)
118121
VPC_SUBNETS = os.getenv('VPC_SUBNETS', None)

0 commit comments

Comments
 (0)