Skip to content

Commit 997653b

Browse files
committed
support GCP metadata
1 parent c652cb4 commit 997653b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

hardware/hardware.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,20 @@ else
130130
fi
131131
echo
132132

133-
echo "Instance type from IMDS (if available):"
134-
curl -s --connect-timeout 1 'http://169.254.169.254/latest/meta-data/instance-type' | tee instance.txt
133+
echo "Instance type from Metadata service (if available):"
134+
AWS_HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 'http://169.254.169.254/latest/meta-data/')
135+
if [[ "$AWS_HTTP_CODE" == "200" ]]; then
136+
AWS_INSTANCE_TYPE=$(curl -s --connect-timeout 1 'http://169.254.169.254/latest/meta-data/instance-type')
137+
echo "$AWS_INSTANCE_TYPE" > instance.txt
138+
exit 0
139+
fi
140+
141+
GCP_HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 -H "Metadata-Flavor: Google" 'http://metadata.google.internal/computeMetadata/v1/instance/')
142+
if [[ "$GCP_HTTP_CODE" == "200" ]]; then
143+
GCP_INSTANCE_TYPE=$(curl -s --connect-timeout 1 -H "Metadata-Flavor: Google" 'http://metadata.google.internal/computeMetadata/v1/instance/machine-type' | awk -F/ '{print $NF}')
144+
echo "$GCP_INSTANCE_TYPE" > instance.txt
145+
exit 0
146+
fi
135147
echo
136148

137149
echo "Uploading the results (if possible)"

0 commit comments

Comments
 (0)