tags dev
This commit is contained in:
3
src/.env
Normal file
3
src/.env
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
cluster_inventory_path = ./config/inventory.yml
|
||||||
|
redis_host = '172.16.0.208'
|
||||||
|
redis_port = '6379'
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# contains the router for the aggregates endpoint
|
# contains the router for the aggregates endpoint
|
||||||
from fastapi import APIRouter, Query, Request
|
from fastapi import APIRouter, Query, Request
|
||||||
from typing import List
|
from typing import List, Dict
|
||||||
from .aggregate_schema import AggregateSchema, MetricEnum
|
from .aggregate_schema import AggregateSchema, MetricEnum
|
||||||
from .aggregate_service import get_aggregates
|
from .aggregate_service import get_aggregates
|
||||||
|
|
||||||
@@ -13,4 +13,11 @@ async def aggregates_endpoint(
|
|||||||
request: Request,
|
request: Request,
|
||||||
metric: MetricEnum = Query(MetricEnum.relative, description="Metric type"),
|
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)
|
||||||
|
|||||||
@@ -13,3 +13,11 @@ class AggregateSchema(BaseModel):
|
|||||||
class MetricEnum(str, Enum):
|
class MetricEnum(str, Enum):
|
||||||
relative = "relative"
|
relative = "relative"
|
||||||
absolute = "absolute"
|
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' }
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# contains the business logic for aggregates
|
# contains the business logic for aggregates
|
||||||
|
|
||||||
from typing import List
|
from typing import List, Dict
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
from src.aggregate.aggregate_schema import AggregateSchema, MetricEnum
|
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 = getLogger("uvicorn")
|
||||||
logger.setLevel("DEBUG")
|
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
|
# Dummy data for demonstration
|
||||||
# You can use the metric parameter to filter or modify results as needed
|
# You can use the metric parameter to filter or modify results as needed
|
||||||
# For now, just return the same data and show metric usage
|
# For now, just return the same data and show metric usage
|
||||||
logger.debug(f"Metric used: {metric}")
|
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=*")
|
__aggregates = await get_data_from_ontap(request, logger, "storage/aggregates", "fields=*")
|
||||||
pprint(__aggregates)
|
pprint(__aggregates)
|
||||||
if metric == MetricEnum.relative:
|
if metric == MetricEnum.relative:
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ def initialize_config():
|
|||||||
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...")
|
log.info(f"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)
|
||||||
|
|||||||
Reference in New Issue
Block a user