rebased
This commit is contained in:
11
.env
11
.env
@@ -1,8 +1,3 @@
|
|||||||
# Environment variables for NetApp ONTAP clusters
|
cluster_inventory_path = ../config/inventory.yml
|
||||||
CLUSTER1_HOSTNAME=172.16.57.2
|
redis_host = '172.16.0.208'
|
||||||
CLUSTER1_USERNAME=admin
|
redis_port = '6379'
|
||||||
CLUSTER1_PASSWORD=Netapp12
|
|
||||||
|
|
||||||
CLUSTER2_HOSTNAME=172.16.56.2
|
|
||||||
CLUSTER2_USERNAME=admin
|
|
||||||
CLUSTER2_PASSWORD=Netapp12
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from src.example.router import router as example_router
|
from src.example.router import router as example_router
|
||||||
|
|
||||||
from .aggregate_router import router as aggregate_router
|
from src.aggregate.aggregate_router import router as aggregate_router
|
||||||
|
|
||||||
__all__ = ["example_router", "aggregate_router"]
|
__all__ = ["example_router", "aggregate_router"]
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
from .aggregate_schema import AggregateSchema, MetricEnum
|
from src.aggregate.aggregate_schema import AggregateSchema, MetricEnum
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from ..utils import round_bytes, get_data_from_ontap
|
from src.utils import round_bytes, get_data_from_ontap
|
||||||
|
|
||||||
logger = getLogger("uvicorn")
|
logger = getLogger("uvicorn")
|
||||||
logger.setLevel("DEBUG")
|
logger.setLevel("DEBUG")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import logging
|
|||||||
from redis import Redis, ConnectionError
|
from redis import Redis, ConnectionError
|
||||||
from typing import List
|
from typing import List
|
||||||
from pydantic import TypeAdapter
|
from pydantic import TypeAdapter
|
||||||
from schema import ConfigSchema
|
from src.schema import ConfigSchema
|
||||||
|
|
||||||
|
|
||||||
def setup_db_conn(redishost, redisport: str):
|
def setup_db_conn(redishost, redisport: str):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# contains the router for the aggregate endpoint
|
# contains the router for the aggregate endpoint
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from .schema import ExampleSchema
|
from src.example.schema import ExampleSchema
|
||||||
|
|
||||||
router = APIRouter(tags=["aggregate"])
|
router = APIRouter(tags=["aggregate"])
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
# contains the schema definitions for the aggregate service
|
# contains the schema definitions for the aggregate service
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class ExampleSchema(BaseModel):
|
class ExampleSchema(BaseModel):
|
||||||
example_field: str
|
example_field: str
|
||||||
another_field: int
|
another_field: int
|
||||||
|
|
||||||
|
|
||||||
class ClusterCreds(BaseModel):
|
class ClusterCreds(BaseModel):
|
||||||
"""A structure to hold basic auth cluster credentials for a cluster"""
|
"""A structure to hold basic auth cluster credentials for a cluster"""
|
||||||
|
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
hostname: str = None
|
hostname: str = None
|
||||||
|
|||||||
@@ -5,35 +5,36 @@ import yaml
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from database import setup_db_conn
|
from src.database import setup_db_conn
|
||||||
from schema import ConfigSchema
|
from src.schema import ConfigSchema
|
||||||
from typing import List
|
from typing import List
|
||||||
from pydantic import TypeAdapter
|
from pydantic import TypeAdapter
|
||||||
|
|
||||||
|
|
||||||
def initialize_config():
|
def initialize_config():
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
log = logging.getLogger('uvicorn')
|
log = logging.getLogger("uvicorn")
|
||||||
ENV_INVENTORYPATH = os.getenv('cluster_inventory_path')
|
ENV_INVENTORYPATH = os.getenv("cluster_inventory_path")
|
||||||
ENV_REDISHOST = os.getenv('redis_host')
|
ENV_REDISHOST = os.getenv("redis_host")
|
||||||
ENV_REDISPORT = os.getenv('redis_port')
|
ENV_REDISPORT = os.getenv("redis_port")
|
||||||
|
|
||||||
log.info(f"Found Cluster Inventory file at: {ENV_INVENTORYPATH}")
|
log.info(f"Found Cluster Inventory file at: {ENV_INVENTORYPATH}")
|
||||||
if not ENV_INVENTORYPATH or not Path(ENV_INVENTORYPATH).is_file():
|
if not ENV_INVENTORYPATH or not Path(ENV_INVENTORYPATH).is_file():
|
||||||
print(f"FATAL: Inventory file {ENV_INVENTORYPATH} is missing or not a file.")
|
print(f"FATAL: Inventory file {ENV_INVENTORYPATH} is missing or not a file.")
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
with open(ENV_INVENTORYPATH, 'r') as f:
|
with open(ENV_INVENTORYPATH, "r") as f:
|
||||||
inv = yaml.safe_load(f)
|
inv = yaml.safe_load(f)
|
||||||
inventory = json.dumps(inv)
|
inventory = json.dumps(inv)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"FATAL: Cannot read inventory file {ENV_INVENTORYPATH}. Err: {e}")
|
print(f"FATAL: Cannot read inventory file {ENV_INVENTORYPATH}. Err: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print(f'[INFO] Importing configuration to DB...')
|
print(f"[INFO] Importing configuration to DB...")
|
||||||
try:
|
try:
|
||||||
GLOBAL_INVENTORY_VALID = TypeAdapter(List[ConfigSchema]).validate_python(inv)
|
GLOBAL_INVENTORY_VALID = TypeAdapter(List[ConfigSchema]).validate_python(inv)
|
||||||
redis_conn = setup_db_conn(ENV_REDISHOST, ENV_REDISPORT)
|
redis_conn = setup_db_conn(ENV_REDISHOST, ENV_REDISPORT)
|
||||||
redis_conn.hset('cluster_inventory', mapping={'inventory': inventory})
|
redis_conn.hset("cluster_inventory", mapping={"inventory": inventory})
|
||||||
redis_conn.close()
|
redis_conn.close()
|
||||||
|
|
||||||
log.info("Configuration has been loaded.")
|
log.info("Configuration has been loaded.")
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ from src.config import config_router
|
|||||||
|
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
from database import setup_db_conn, get_config_from_db
|
from .database import setup_db_conn, get_config_from_db
|
||||||
from src.initialize import initialize_config
|
from src.initialize import initialize_config
|
||||||
from utils import setup_logging
|
from .utils import setup_logging
|
||||||
|
|
||||||
logger = logging.getLogger("uvicorn")
|
logger = logging.getLogger("uvicorn")
|
||||||
logger.info("Starting application")
|
logger.info("Starting application")
|
||||||
|
|||||||
Reference in New Issue
Block a user