backedn dev

This commit is contained in:
Alexey
2025-09-18 14:00:05 +02:00
committed by Magel, Denis
parent fe13e49172
commit 72f738a816
3 changed files with 29 additions and 26 deletions

View File

@@ -6,6 +6,9 @@ import yaml
from pathlib import Path
from dotenv import load_dotenv
from database import setup_db_conn
from schema import ConfigSchema
from typing import List
from pydantic import TypeAdapter
def initialize_config():
load_dotenv()
@@ -14,7 +17,7 @@ def initialize_config():
ENV_REDISHOST = os.getenv('redis_host')
ENV_REDISPORT = os.getenv('redis_port')
log.info(f"Fount 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():
print(f"FATAL: Inventory file {ENV_INVENTORYPATH} is missing or not a file.")
return False
@@ -28,11 +31,12 @@ def initialize_config():
print(f'[INFO] Importing configuration to DB...')
try:
GLOBAL_INVENTORY_VALID = TypeAdapter(List[ConfigSchema]).validate_python(inv)
redis_conn = setup_db_conn(ENV_REDISHOST, ENV_REDISPORT)
redis_conn.hset('cluster_inventory', mapping={'inventory': inventory})
redis_conn.close()
log.info("Configuration has been loaded.")
log.info("Configuration has been loaded.")
return True
except Exception as e: