3
MD_URL="http://169.254.169.254/latest"
11
Usage: ${0##*/} [options]
12
-u | --url URL use URL (default: $MD_URL)
13
-h | --help display usage
15
--user-data dump user data
16
--<item> dump 'item' from the metadata service
19
--block-device-mappings dump the block device mappings, space delimited
20
--public-keys dump the public keys
22
with no options given, metadata service will be crawled and
23
dumped. This will not include user-data.
27
error() { echo "$@" 1>&2; }
28
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
31
local under="$1" x="" out="" found=""
36
*/) get_field_list "${under:+${under}/}${x%/}"
37
found="${found} $_RET";;
38
*) found="${found} ${under:+$under/}$x";;
45
curl --fail --silent --max-time "${TIMEOUT}" "$1"
49
local u="$1" t1="" t2="" out=""
52
public-keys|public-keys/)
53
out=$(caturl "$MD_URL/meta-data/$u") ||
54
fail "failed to get $MD_URL/meta-data/$u";
55
# output of public-keys is lines of 'X=keyname'
56
# so we return a carriage return list of the tokens before =
61
_RET="${_RET:+${_RET}${CR}}${t1%/}"
67
t1=${u#public-keys/[0-9]}
68
# t2 will now have 'public-keys/[0-9]'
70
# if t1 has a / (ie, u=public-keys/0=brickies/openssh-keys)
71
# then set t1 to just "/openssh-keys". if not, set it to ""
72
[ "${t1#*/}" = "${t1}" ] && t1="" || t1="/${t1#*/}"
73
u="meta-data/${t2}${t1}"
77
_RET=$(caturl "$MD_URL/$u") ||
78
fail "failed to get ${MD_URL}/$u"
81
local out="" x="" t="" ret=""
84
mdget "placement/availability-zone";;
91
"public-keys/${x}/openssh-key" &&
92
ret="${ret:+${ret}${CR}}${_RET}"
97
block-device-mappings)
98
mdget block-device-mapping
101
mdget "block-device-mapping/$x"
102
ret="${ret:+${ret} }${x}=$_RET";
109
while [ $# -ne 0 ]; do
112
-h|--help) Usage ; exit 0;;
113
--url=*) MD_URL=${cur#*=}; MD_URL=${MD_URL%/};;
114
--url|-u) MD_URL="${next%/}"; shift;;
115
--availability-zone|--public-keys|--block-device-mappings)
116
fields="$fields special_${cur#--}";;
117
--*) fields="$fields ${cur#--}";;
123
if [ -z "$fields" ]; then
133
special_*) special "${f#special_}";;
137
[ $ret -eq 0 ] || fail "failed to get $f"
139
if [ "${_RET#*${CR}}" != "${_RET}" ]; then
140
_RET=$(echo "$_RET" | sed 's,^,|,g')
143
echo "${f#special_}: $_RET"
151
# vi: ts=4 noexpandtab