feat: added functionality inside GET/aggregates

This commit is contained in:
Magel, Denis
2025-09-18 12:16:30 +02:00
parent 1592333ef8
commit e8efde9892
4 changed files with 54 additions and 18 deletions

23
src/utils.py Normal file
View File

@@ -0,0 +1,23 @@
import httpx
def round_bytes(size_in_bytes: int) -> str:
# Helper function to convert bytes to a human-readable format
for unit in ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]:
if size_in_bytes < 1024:
return f"{size_in_bytes:.2f}{unit}"
size_in_bytes /= 1024
return f"{size_in_bytes:.2f}EB"
def get_data_from_ontap(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