in cvm-attestation/src/ImdsClient.py [0:0]
def get_region_from_compute_metadata(self):
"""
Get the region from the compute metadata.
Returns:
str: The region string if available, otherwise None.
"""
self.log.info("Retrieving region from compute metadata...")
self.log.debug(f"Using metadata URL: {COMPUTE_METADATA_URL}")
try:
response = self._send_request_with_retries(
method='get',
url=COMPUTE_METADATA_URL,
headers=METADATA_HEADERS,
exception_class=MetadataException
)
location = response.text.strip()
if location:
return location
else:
self.log.error("Received empty response for compute metadata region.")
return None
except (requests.exceptions.RequestException, MetadataException) as e:
self.log.error(f"Error retrieving compute metadata: {e}", exc_info=True)
return None
except Exception as e:
self.log.error(f"Unexpected error retrieving region: {e}", exc_info=True)
return None