░▒▓████████████████████████████████▓▒░ ░▒▓█ ▓▒░ ░▒▓█ ~ S W A M P ~ ▓▒░ ░▒▓█ ▓▒░ ░▒▓████████████████████████████████▓▒░
pplmvsvm
LOCATION:
/opt/microsoft/dependency-agent/lib/plugins
☗ ROOT
↻ REFRESH
✎ CARVE FLESH
EDITING: AzureMetadata.py
#!/opt/microsoft/dependency-agent/bin/python import sys, os, socket from lib.PropertyMap import PropertyMap from lib.Event import Event from lib import VmssUtils import json import re import traceback from collections import OrderedDict if sys.version_info[0] > 3: raise Exception("Python version not supported: " + sys.version_info) if sys.version_info[0] == 2: from urlparse import urlparse import httplib else: from urllib.parse import urlparse import http.client as httplib def exception_to_string(): exc_type, exc_value, exc_traceback = sys.exc_info() return str(exc_type) + ": " + str(exc_value) + "\nTraceback:\n" + ''.join(traceback.format_tb(exc_traceback)) sharedConfigFile = "/var/lib/waagent/SharedConfig.xml" protocolVersion = 1 instanceMetadataVersion = "2019-08-15" class ImdsEndpoints: def __init__(self): self.imdsEndpointCandidates = ["http://169.254.169.254:80"] self.imdsIndex = 0 envImdsEndpoint = os.getenv("IMDS_ENDPOINT") if envImdsEndpoint is not None: if urlparse(envImdsEndpoint).scheme: self.imdsEndpointCandidates.append(envImdsEndpoint) self.cachedImdsEndpoint = None def get_endpoint(self): if self.cachedImdsEndpoint: return self.cachedImdsEndpoint startIndex = self.imdsIndex while True: uri_s = self.imdsEndpointCandidates[self.imdsIndex] uri = urlparse(uri_s) try: sock = socket.create_connection((uri.hostname, uri.port), timeout=2) self.cachedImdsEndpoint = uri_s return self.cachedImdsEndpoint except: pass self.imdsIndex = (self.imdsIndex + 1) % len(self.imdsEndpointCandidates) if self.imdsIndex == startIndex: break raise Exception("no valid endpoints: " + ", ".join(self.imdsEndpointCandidates)) imds_object = ImdsEndpoints() for event in Event.getEvents(): pid = event.getPid() pm = PropertyMap(pid, protocolVersion) errors = [] messages = [] content = {} try: imds_endpoint = imds_object.get_endpoint() http_url_path = "/metadata/instance?api-version=" + instanceMetadataVersion uri = urlparse(imds_endpoint) request_headers = {'Metadata': 'True'} conn = httplib.HTTPConnection(uri.hostname + ":" + str(uri.port)) conn.request("GET", http_url_path, headers=request_headers) http_response = conn.getresponse() if http_response.status != 200: errors.append("Invalid response from {0}: Status: {1}, Reason: {2}".format(imds_endpoint, http_response.status, http_response.reason)) else: metadata = http_response.read() if len(metadata) == 0: errors.append("No data available from: " + imds_endpoint) else: content["instance"] = json.loads(metadata) except: errors.append("Unexpected error while collecting instance metadata: " + exception_to_string()) try: if not os.path.isfile(sharedConfigFile): errors.append("VM(SS) shared config file " + sharedConfigPath + " does not exist.") else: vmss = VmssUtils.parseVmssConfigFile(sharedConfigFile) if not vmss: errors.append("VM(SS) could not extract shared config File configuration") else: content["vmss"] = vmss except: errors.append("Unexpected error while processing shared config files: " + exception_to_string()) try: content["instanceMetadataVersion"] = instanceMetadataVersion content["errors"] = errors content["messages"] = messages content_json = json.dumps(content, separators=(',',':')) pm.addStringWithCompression("AzureMetadata", content_json) pm.send() except: traceback.print_exc()
CANCEL
Name
Type
Size
Modified
Actions
↩ ..
DIR
—
—
📁 lib/
DIR
—
2026-03-10 17:09
📄 AzureMetadata.py
PY
3.9 KB
2023-11-01 09:12
EDIT