def get_ec2_metadata(self, meta_path, default_value=""): if not self.__can_access: _logger.warn("Cannot connect to amazon metadata services in address [%s], return default value. " % _AWS_METADATA_SERVICE_IP) return default_value try: return http_client.load(_AWS_METADATA_SERVICE_URL + "meta-data/" + meta_path) except Exception: _logger.exception("error when loading metadata from aws %s" % meta_path) return default_value
def get_instance_identity_document(self, default_value={}): if not self.__can_access: _logger.warn("Cannot connect to amazon metadata services in address [%s], return default value. " % _AWS_METADATA_SERVICE_IP) return default_value try: doc = http_client.load(_AWS_METADATA_SERVICE_URL + "dynamic/instance-identity/document") return json.loads(doc) except Exception: _logger.exception("error when loading dynamic instance identity document from aws") return default_value
def get_ec2_metadata(self, meta_path, default_value=""): if not self.__can_access: _logger.warn( f"Cannot connect to amazon metadata services in address [{_AWS_METADATA_SERVICE_IP}], return default value. " ) return default_value try: return http_client.load( f"{_AWS_METADATA_SERVICE_URL}meta-data/{meta_path}") except Exception: _logger.exception( f"error when loading metadata from aws {meta_path}") return default_value