Check if ${NOMAD_DC} is undefined or unset
[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 # detect if we're in AWS
21 if grep -qi amazon /sys/devices/virtual/dmi/id/bios_vendor ; then
22     echo "INFO: Running in AWS, not capturing instance metadata"
23     exit 0
24 fi
25
26 # Retrive OpenStack instace metadata APIs at this IP.
27 # The instance id and other metadata is useful for debugging VM.
28 echo "INFO: Running in OpenStack, capturing instance metadata"
29 curl -s http://169.254.169.254/openstack/latest/meta_data.json \
30     | python -mjson.tool > "$WORKSPACE/archives/instance_meta_data.json"