Merge "Fix rtd-verify.sh to better validate submodules"
[releng/global-jjb.git] / shell / capture-instance-metadata.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2020 The Linux Foundation and others.
5 #
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 ##############################################################################
11
12 echo "---> capture-instance-metadata.sh"
13
14 # detect if we're in EC2
15 if [ -n "${NOMAD_DC}" ]; then
16     echo "INFO: Running in Nomad, no metadata"
17     exit 0
18 fi
19
20 # AWS not supported, exit
21 cloudtype="$(jq -r .v1.datasource /run/cloud-init/result.json)"
22 if [[ $cloudtype == "DataSourceEc2Local" ]]; then
23    echo "INFO: Running in AWS, not capturing instance metadata"
24    exit 0
25 fi
26
27 # Retrive OpenStack instace metadata APIs at this IP.
28 # The instance id and other metadata is useful for debugging VM.
29 echo "INFO: Running in OpenStack, capturing instance metadata"
30 curl -s http://169.254.169.254/openstack/latest/meta_data.json \
31     | python -mjson.tool > "$WORKSPACE/archives/instance_meta_data.json"