feat: get cluster information from redis
feat: loop over all clusters
This commit is contained in:
@@ -3,8 +3,6 @@ import logging
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from .schema import ConfigReturnSchema, ConfigSchema
|
from .schema import ConfigReturnSchema, ConfigSchema
|
||||||
from src.database import get_config_from_db
|
|
||||||
from src.main import shared_redis_conn
|
|
||||||
|
|
||||||
logger = logging.getLogger("uvicorn")
|
logger = logging.getLogger("uvicorn")
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ import logging
|
|||||||
import httpx
|
import httpx
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
shared_redis_conn = None
|
|
||||||
requests_client = None
|
|
||||||
|
|
||||||
from src.aggregate import aggregate_router
|
from src.aggregate import aggregate_router
|
||||||
from src.config_upload import config_router
|
from src.config_upload import config_router
|
||||||
|
|
||||||
|
|||||||
13
src/utils.py
13
src/utils.py
@@ -2,6 +2,8 @@ import logging
|
|||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
from src.database import get_config_from_db
|
||||||
|
|
||||||
|
|
||||||
def round_bytes(size_in_bytes: int) -> str:
|
def round_bytes(size_in_bytes: int) -> str:
|
||||||
# Helper function to convert bytes to a human-readable format
|
# 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 = ""):
|
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}"
|
url = f"https://{hostname}/api/{endpoint}"
|
||||||
if query_string:
|
if query_string:
|
||||||
url += f"?{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:
|
async with request.state.requests_client as _client:
|
||||||
try:
|
try:
|
||||||
logger.debug(f"Fetching data from ONTAP: {url}")
|
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()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
except httpx.HTTPError as e:
|
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:
|
def setup_logging() -> None:
|
||||||
"""Configure logging for the application"""
|
"""Configure logging for the application"""
|
||||||
logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s] [%(levelname)5s] %(message)s")
|
logging.basicConfig(level=logging.DEBUG, format="[%(asctime)s] [%(levelname)5s] %(message)s")
|
||||||
print(f"Logger is initialized.")
|
print("Logger is initialized.")
|
||||||
|
|||||||
Reference in New Issue
Block a user