1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-26 02:57:04 +00:00
mailinabox/tools/get_ubuntu_ami.py
2013-08-20 22:27:32 -04:00

27 lines
606 B
Python

import sys, json, re
# Arguments:
region, version, arch, instance_type = sys.argv[1:]
# Read bytes from stdin.
dat = sys.stdin.read()
# Be flexible. The Ubuntu AMI list is invalid JSON by having a comma
# following the last element in a list.
dat = re.sub(r",(\s*)\]", r"\1]", dat)
# Parse JSON.
dat = json.loads(dat)
for item in dat["aaData"]:
if item[0] == region and item[2] == version and item[3] == arch and item[4] == instance_type:
ami_link = item[6]
# The field comes in the form of <a href="...">ami-id</a>
ami_link = re.sub(r"<.*?>", "", ami_link)
print(ami_link)
break