File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 11import os
2- import json
32import logging
43
54logger = logging .getLogger (__name__ )
@@ -17,7 +16,17 @@ def _detect_region_of_azure_function():
1716
1817
1918def _detect_region_of_azure_vm (http_client ):
20- url = "http://169.254.169.254/metadata/instance?api-version=2021-01-01"
19+ url = (
20+ "http://169.254.169.254/metadata/instance"
21+
22+ # Utilize the "route parameters" feature to obtain region as a string
23+ # https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service?tabs=linux#route-parameters
24+ "/compute/location?format=text"
25+
26+ # Location info is available since API version 2017-04-02
27+ # https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service?tabs=linux#response-1
28+ "&api-version=2021-01-01"
29+ )
2130 logger .info (
2231 "Connecting to IMDS {}. "
2332 "You may want to use a shorter timeout on your http_client" .format (url ))
@@ -29,5 +38,5 @@ def _detect_region_of_azure_vm(http_client):
2938 "IMDS {} unavailable. Perhaps not running in Azure VM?" .format (url ))
3039 return None
3140 else :
32- return json . loads ( resp .text )[ "compute" ][ "location" ]
41+ return resp .text . strip ()
3342
You can’t perform that action at this time.
0 commit comments