From b8885d7d73108c5c4b31087163d292c43c143133 Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 18 Sep 2025 18:01:06 +0200 Subject: [PATCH] tags dev --- src/.env | 3 +++ src/aggregate/aggregate_router.py | 11 +++++++++-- src/aggregate/aggregate_schema.py | 8 ++++++++ src/aggregate/aggregate_service.py | 26 ++++++++++++++++++++++++-- src/initialize.py | 2 +- 5 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/.env diff --git a/src/.env b/src/.env new file mode 100644 index 0000000..e3d8000 --- /dev/null +++ b/src/.env @@ -0,0 +1,3 @@ +cluster_inventory_path = ./config/inventory.yml +redis_host = '172.16.0.208' +redis_port = '6379' \ No newline at end of file diff --git a/src/aggregate/aggregate_router.py b/src/aggregate/aggregate_router.py index 81864e3..4948a1b 100644 --- a/src/aggregate/aggregate_router.py +++ b/src/aggregate/aggregate_router.py @@ -1,6 +1,6 @@ # contains the router for the aggregates endpoint from fastapi import APIRouter, Query, Request -from typing import List +from typing import List, Dict from .aggregate_schema import AggregateSchema, MetricEnum from .aggregate_service import get_aggregates @@ -13,4 +13,11 @@ async def aggregates_endpoint( request: Request, metric: MetricEnum = Query(MetricEnum.relative, description="Metric type"), ): - return await get_aggregates(request, metric) + # Extract tag parameters from query string + tags: Dict[str, str] = {} + for param_name, param_value in request.query_params.items(): + if param_name.startswith("tag."): + tag_key = param_name[4:] + tags[tag_key] = param_value + + return await get_aggregates(request, metric, tags) diff --git a/src/aggregate/aggregate_schema.py b/src/aggregate/aggregate_schema.py index d197e4f..9578f5f 100644 --- a/src/aggregate/aggregate_schema.py +++ b/src/aggregate/aggregate_schema.py @@ -13,3 +13,11 @@ class AggregateSchema(BaseModel): class MetricEnum(str, Enum): relative = "relative" absolute = "absolute" + +TAG2REST = { +'worm_compliance': { 'snaplock_type': 'compliance' }, +'worm_enterprise': { 'snaplock_type': 'enterprise' }, +'flash': { 'block_storage.storage_type': 'ssd' }, +'hdd': { 'block_storage.storage_type': 'hdd' }, +'mcc': { 'block_storage.mirror.enabled': 'true' } +} \ No newline at end of file diff --git a/src/aggregate/aggregate_service.py b/src/aggregate/aggregate_service.py index 16ed304..3a58315 100644 --- a/src/aggregate/aggregate_service.py +++ b/src/aggregate/aggregate_service.py @@ -1,6 +1,6 @@ # contains the business logic for aggregates -from typing import List +from typing import List, Dict from pprint import pprint from fastapi import Request from src.aggregate.aggregate_schema import AggregateSchema, MetricEnum @@ -10,12 +10,34 @@ from src.utils import round_bytes, get_data_from_ontap logger = getLogger("uvicorn") logger.setLevel("DEBUG") +# TAG2REST = { +# 'worm_compliance': { 'snaplock_type': 'compliance' }, +# 'worm_enterprise': { 'snaplock_type': 'enterprise' }, +# 'flash': { 'block_storage.storage_type': 'ssd' }, +# 'hdd': { 'block_storage.storage_type': 'hdd' }, +# 'mcc': { 'block_storage.mirror.enabled': 'true' } +# } -async def get_aggregates(request: Request, metric: str = "relative") -> List[AggregateSchema]: +# { +# "flash": "production", +# "performance": "gold", +# "worm": "compliance" +# } + +async def get_aggregates(request: Request, metric: str = "relative", tags: Dict[str, str] = None) -> 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}") + logger.debug(f"Tags used: {tags}") + + # convert tags to ONTAP filter + # filter_str = "" + # if tags: + # str_filter_parts = [f"tag.{key} eq '{value}'" for key, value in tags.items()] + # param_str = "&".join([f"{TAG2REST[key]}" for key, value in tags.items()]) + + __aggregates = await get_data_from_ontap(request, logger, "storage/aggregates", "fields=*") pprint(__aggregates) if metric == MetricEnum.relative: diff --git a/src/initialize.py b/src/initialize.py index b6c6298..5f4c43f 100644 --- a/src/initialize.py +++ b/src/initialize.py @@ -30,7 +30,7 @@ def initialize_config(): print(f"FATAL: Cannot read inventory file {ENV_INVENTORYPATH}. Err: {e}") return False - print(f"[INFO] Importing configuration to DB...") + log.info(f"Importing configuration to DB...") try: GLOBAL_INVENTORY_VALID = TypeAdapter(List[ConfigSchema]).validate_python(inv) redis_conn = setup_db_conn(ENV_REDISHOST, ENV_REDISPORT)