feat: get cluster information from redis

feat: loop over all clusters
This commit is contained in:
Magel, Denis
2025-09-18 15:36:39 +02:00
parent b60383071a
commit e8aa7d7df5
3 changed files with 19 additions and 15 deletions

View File

@@ -3,8 +3,6 @@ import logging
from fastapi import APIRouter
from .schema import ConfigReturnSchema, ConfigSchema
from src.database import get_config_from_db
from src.main import shared_redis_conn
logger = logging.getLogger("uvicorn")

View File

@@ -3,9 +3,6 @@ import logging
import httpx
from fastapi import FastAPI
shared_redis_conn = None
requests_client = None
from src.aggregate import aggregate_router
from src.config_upload import config_router

View File

@@ -2,6 +2,8 @@ import logging
from fastapi import Request
import httpx
from src.database import get_config_from_db
def round_bytes(size_in_bytes: int) -> str:
# Helper function to convert bytes to a human-readable format
@@ -13,13 +15,20 @@ def round_bytes(size_in_bytes: int) -> str:
async def get_data_from_ontap(request: Request, logger, hostname: str, username: str, password: str, 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:
try:
logger.debug(f"Fetching data from ONTAP: {url}")
response = await _client.get(url, auth=(username, password))
response = await _client.get(url, auth=(cluster.username, cluster.password))
response.raise_for_status()
return response.json()
except httpx.HTTPError as e:
@@ -30,4 +39,4 @@ async def get_data_from_ontap(request: Request, logger, hostname: str, username:
def setup_logging() -> None:
"""Configure logging for the application"""
logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s] [%(levelname)5s] %(message)s")
print(f"Logger is initialized.")
print("Logger is initialized.")