2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2020 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
12 echo "---> capture-instance-metadata.sh"
14 # shellcheck disable=SC1090
17 lf-activate-venv python3.8 lftools
19 # detect if we're in EC2
20 if [ -n "${NOMAD_DC}" ]; then
21 echo "INFO: Running in Nomad, no metadata"
25 if [[ ! -f /run/cloud-init/result.json ]]; then
26 echo "INFO: Running in unsupported cloud, no metadata"
30 # AWS not supported, exit
31 cloudtype="$(jq -r .v1.datasource /run/cloud-init/result.json)"
32 if [[ $cloudtype == "DataSourceEc2Local" ]]; then
33 echo "INFO: Running in AWS, not capturing instance metadata"
37 # Retrive OpenStack instace metadata APIs at this IP.
38 # The instance id and other metadata is useful for debugging VM.
39 echo "INFO: Running in OpenStack, capturing instance metadata"
40 curl -s http://169.254.169.254/openstack/latest/meta_data.json \
41 | python -mjson.tool > "$WORKSPACE/archives/instance_meta_data.json"