diff --git a/src/aggregate/aggregate_service.py b/src/aggregate/aggregate_service.py index 48c03a8..2e652b2 100644 --- a/src/aggregate/aggregate_service.py +++ b/src/aggregate/aggregate_service.py @@ -1,7 +1,7 @@ # contains the business logic for aggregates from typing import List - +from pprint import pprint from fastapi import Request from src.aggregate.aggregate_schema import AggregateSchema, MetricEnum from logging import getLogger @@ -16,9 +16,8 @@ async def get_aggregates(request: Request, metric: str = "relative") -> List[Agg # You can use the metric parameter to filter or modify results as needed # For now, just return the same data and show metric usage logger.debug(f"Metric used: {metric}") - __aggregates = await get_data_from_ontap(request, logger, "172.16.57.2", "admin", "Netapp12", "storage/aggregates", "fields=name,uuid,space,node,home_node") - logger.debug(__aggregates) - __aggregates = __aggregates.get("records") + __aggregates = await get_data_from_ontap(request, logger, "storage/aggregates", "fields=name,uuid,space,node,home_node") + pprint(__aggregates) if metric == MetricEnum.relative: __aggregates = sorted(__aggregates, key=lambda r: r["space"]["block_storage"].get("used_percent"), reverse=True) elif metric == MetricEnum.absolute: diff --git a/src/utils.py b/src/utils.py index 84cec77..94d11b6 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,7 +1,7 @@ import logging from fastapi import Request import httpx - +from pprint import pprint from src.database import get_config_from_db @@ -14,26 +14,29 @@ def round_bytes(size_in_bytes: int) -> str: return f"{size_in_bytes:.2f}EB" -async def get_data_from_ontap(request: Request, logger, hostname: str, username: str, password: str, endpoint: str, query_string: str = ""): +async def get_data_from_ontap(request: Request, logger, endpoint: str, query_string: str = ""): # get clusters from redis - url = f"https://{hostname}/api/{endpoint}" - if query_string: - url += f"?{query_string}" redis_conn = request.state.redis_conn config = get_config_from_db(redis_conn) logger.debug("Got the config from REDIS: %s", config) - for cluster in config: - async with request.state.requests_client as _client: + results = [] + async with request.state.requests_client as _client: + for cluster in config: + print(f"\n\n looping, {cluster}") + url = f"https://{cluster.hostname}/api/{endpoint}" + if query_string: + url += f"?{query_string}" try: logger.debug(f"Fetching data from ONTAP: {url}") response = await _client.get(url, auth=(cluster.username, cluster.password)) response.raise_for_status() - return response.json() + results.extend(response.json()["records"]) except httpx.HTTPError as e: logger.error(f"HTTP error occurred: {e}") return None + return results def setup_logging() -> None: