Skip to content

Commit

Permalink
stash prints
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed Jan 22, 2024
1 parent f2c536e commit 0d236c7
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
class AzureVMResourceDetector(ResourceDetector):
# pylint: disable=no-self-use
def detect(self) -> "Resource":
print("begin detect")
attributes = {}
metadata_json = (
_AzureVMMetadataServiceRequestor().get_azure_vm_metadata()
Expand All @@ -60,26 +61,31 @@ def detect(self) -> "Resource":
] = _AzureVMMetadataServiceRequestor().get_attribute_from_metadata(
metadata_json, attribute_key
)
print("end detect")
return Resource(attributes)


class _AzureVMMetadataServiceRequestor:
def get_azure_vm_metadata(self): # pylint: disable=no-self-use
print("begin get_azure_vm_metadata")
request = Request(_AZURE_VM_METADATA_ENDPOINT)
request.add_header("Metadata", "True")
try:
with urlopen(request, timeout=10) as response:
return loads(response.read())
except URLError:
# Not on Azure VM
print("end get_azure_vm_metadata")
return None
except Exception as e: # pylint: disable=broad-except,invalid-name
_logger.exception("Failed to receive Azure VM metadata: %s", e)
print("end get_azure_vm_metadata")
return None

def get_attribute_from_metadata(
self, metadata_json, attribute_key
): # pylint: disable=no-self-use
print("begin get_attribute_from_metadata")
ams_value = ""
if attribute_key == _AZURE_VM_SCALE_SET_NAME_ATTRIBUTE:
ams_value = metadata_json["vmScaleSetName"]
Expand All @@ -106,4 +112,5 @@ def get_attribute_from_metadata(
ams_value = metadata_json["osType"]
elif attribute_key == ResourceAttributes.OS_VERSION:
ams_value = metadata_json["version"]
print("end get_attribute_from_metadata")
return ams_value

0 comments on commit 0d236c7

Please sign in to comment.