Skip to content

Commit 150fc2c

Browse files
authored
Merge pull request ClickHouse#373 from complexsplit/main
Support GCP Metadata
2 parents fcaa12a + 359e939 commit 150fc2c

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

hardware/hardware.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,18 @@ 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+
fi
139+
140+
GCP_HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 1 -H "Metadata-Flavor: Google" 'http://metadata.google.internal/computeMetadata/v1/')
141+
if [[ "$GCP_HTTP_CODE" == "200" ]]; then
142+
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}')
143+
echo "$GCP_INSTANCE_TYPE" > instance.txt
144+
fi
135145
echo
136146

137147
echo "Uploading the results (if possible)"

0 commit comments

Comments
 (0)