refactor: added async await to ONTAP call

This commit is contained in:
Magel, Denis
2025-09-18 13:39:22 +02:00
parent e8efde9892
commit fc71950039
4 changed files with 33 additions and 17 deletions

View File

@@ -9,15 +9,16 @@ def round_bytes(size_in_bytes: int) -> str:
return f"{size_in_bytes:.2f}EB"
def get_data_from_ontap(logger, hostname: str, username: str, password: str, endpoint: str, query_string: str = ""):
async def get_data_from_ontap(client, logger, hostname: str, username: str, password: str, endpoint: str, query_string: str = ""):
url = f"https://{hostname}/api/{endpoint}"
if query_string:
url += f"?{query_string}"
try:
logger.debug(f"Fetching data from ONTAP: {url}")
response = httpx.get(url, auth=(username, password), verify=False)
response.raise_for_status()
return response.json()
except httpx.HTTPError as e:
logger.error(f"HTTP error occurred: {e}")
return None
async with client as _client:
try:
logger.debug(f"Fetching data from ONTAP: {url}")
response = await _client.get(url, auth=(username, password))
response.raise_for_status()
return response.json()
except httpx.HTTPError as e:
logger.error(f"HTTP error occurred: {e}")
return None