Automatically resolve AMI ID to use

This commit is contained in:
Jérôme Petazzoni
2017-04-14 15:32:03 -05:00
parent b0f566538d
commit 27ea268026
2 changed files with 17 additions and 30 deletions

View File

@@ -3,7 +3,7 @@
usage() {
cat >&2 <<__
usage: find-ubuntu-ami.sh [ <filter>... ] [ <sorting> ]
usage: find-ubuntu-ami.sh [ <filter>... ] [ <sorting> ] [ <options> ]
where:
<filter> is pair of key and substring to search
-r <region>
@@ -14,7 +14,7 @@ where:
-d <date>
-i <image>
-k <kernel>
<sorting> is on of:
<sorting> is one of:
-R by region
-N by name
-V by version
@@ -23,6 +23,8 @@ where:
-D by date
-I by image
-K by kernel
<options> can be:
-q just show AMI
protip for Docker orchestration workshop admin:
./find-ubuntu-ami.sh -t hvm:ebs -r \$AWS_REGION -v 15.10 -N
@@ -30,7 +32,7 @@ __
exit 1
}
args=`getopt hr:n:v:a:t:d:i:k:RNVATDIK $*`
args=`getopt hr:n:v:a:t:d:i:k:RNVATDIKq $*`
if [ $? != 0 ] ; then
echo >&2
usage
@@ -47,6 +49,8 @@ kernel=
sort=date
quiet=
set -- $args
for a ; do
case "$a" in
@@ -69,6 +73,8 @@ for a ; do
-D) sort=date ;;
-I) sort=image ;;
-K) sort=kernel ;;
-q) quiet=y ;;
--) shift ; break ;;
*) continue ;;
@@ -119,13 +125,17 @@ escape_spaces() {
url=http://cloud-images.ubuntu.com/locator/ec2/releasesTable
{
echo REGION NAME VERSION ARCH TYPE DATE IMAGE KERNEL
[ "$quiet" ] || echo REGION NAME VERSION ARCH TYPE DATE IMAGE KERNEL
curl -s $url | fix_json | jq "`jq_query`" | trim_quotes | escape_spaces | tr \| ' '
} |
while read region name version arch type date image kernel ; do
image=${image%<*}
image=${image#*>}
echo "$region|$name|$version|$arch|$type|$date|$image|$kernel"
if [ "$quiet" ]; then
echo $image
else
echo "$region|$name|$version|$arch|$type|$date|$image|$kernel"
fi
done | column -t -s \|

View File

@@ -192,7 +192,7 @@ sync_keys() {
}
suggest_amis() {
scripts/find-ubuntu-ami.sh -r $AWS_DEFAULT_REGION -a amd64 -v 16.04 -t hvm:ebs -N
scripts/find-ubuntu-ami.sh -r $AWS_DEFAULT_REGION -a amd64 -v 16.04 -t hvm:ebs -N -q
}
get_token() {
@@ -203,30 +203,7 @@ get_token() {
}
get_ami() {
# using find-ubuntu-ami script in `trainer-tools/scripts`:
#AMI=$(./scripts/find-ubuntu-ami.sh -r $AWS_DEFAULT_REGION -a amd64 -v 15.10 -t hvm:ebs -N | grep -v ^REGION | head -1 | awk '{print $7}')
#AMI=$(suggest_amis | grep -v ^REGION | head -1 | awk '{print $7}')
case $AWS_DEFAULT_REGION in
eu-central-1)
AMI=ami-82cf0aed
;;
eu-west-1)
AMI=ami-07174474
;;
us-east-1)
AMI=ami-2808313f
;;
us-east-2)
AMI=ami-1b772d7e
;;
us-west-1)
AMI=ami-dab5e0ba
;;
us-west-2)
AMI=ami-9ee24ffe
;;
esac
echo $AMI
suggest_amis | head -1
}