38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
# contains the business logic for aggregates
|
|
|
|
from typing import List
|
|
|
|
from fastapi import Request
|
|
from src.aggregate.aggregate_schema import AggregateSchema, MetricEnum
|
|
from logging import getLogger
|
|
from src.utils import round_bytes, get_data_from_ontap
|
|
|
|
logger = getLogger("uvicorn")
|
|
logger.setLevel("DEBUG")
|
|
|
|
|
|
async def get_aggregates(request: Request, metric: str = "relative") -> List[AggregateSchema]:
|
|
# Dummy data for demonstration
|
|
# 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")
|
|
if metric == MetricEnum.relative:
|
|
__aggregates = sorted(__aggregates, key=lambda r: r["space"]["block_storage"].get("used_percent"), reverse=True)
|
|
elif metric == MetricEnum.absolute:
|
|
__aggregates = sorted(__aggregates, key=lambda r: r["space"]["block_storage"].get("available"), reverse=False)
|
|
|
|
aggregates: list = [
|
|
AggregateSchema(
|
|
aggregate=a["name"],
|
|
node=a["node"]["name"],
|
|
available=a["space"]["block_storage"]["available"],
|
|
available_str=round_bytes(a["space"]["block_storage"]["available"]),
|
|
)
|
|
for a in __aggregates
|
|
]
|
|
|
|
return aggregates
|