66import json
77from pathlib import Path
88from typing import Any , cast
9+ from uuid import UUID
910
1011import click
1112
@@ -36,11 +37,13 @@ def _load_items(items_arg: str) -> list[dict[str, Any]]:
3637def bulk_create (items : str ) -> None :
3738 """Bulk-create policies (partial-success semantics)."""
3839 from ai .backend .common .dto .manager .v2 .app_config_policy .request import (
39- AdminAppConfigPolicyItemInput ,
40+ AdminAppConfigPolicyCreateItemInput ,
4041 AdminBulkCreateAppConfigPoliciesInput ,
4142 )
4243
43- parsed = [AdminAppConfigPolicyItemInput .model_validate (item ) for item in _load_items (items )]
44+ parsed = [
45+ AdminAppConfigPolicyCreateItemInput .model_validate (item ) for item in _load_items (items )
46+ ]
4447
4548 async def _run () -> None :
4649 registry = await create_v2_registry (load_v2_config ())
@@ -59,19 +62,18 @@ async def _run() -> None:
5962@click .option (
6063 "--items" ,
6164 required = True ,
62- help = (
63- "JSON list of `{config_name, scope_sources}` items, "
64- "or `@path/to/items.json` to load from file."
65- ),
65+ help = ("JSON list of `{id, scope_sources}` items, or `@path/to/items.json` to load from file." ),
6666)
6767def bulk_update (items : str ) -> None :
6868 """Bulk-update policy scope chains (partial-success semantics)."""
6969 from ai .backend .common .dto .manager .v2 .app_config_policy .request import (
70- AdminAppConfigPolicyItemInput ,
70+ AdminAppConfigPolicyUpdateItemInput ,
7171 AdminBulkUpdateAppConfigPoliciesInput ,
7272 )
7373
74- parsed = [AdminAppConfigPolicyItemInput .model_validate (item ) for item in _load_items (items )]
74+ parsed = [
75+ AdminAppConfigPolicyUpdateItemInput .model_validate (item ) for item in _load_items (items )
76+ ]
7577
7678 async def _run () -> None :
7779 registry = await create_v2_registry (load_v2_config ())
@@ -88,26 +90,27 @@ async def _run() -> None:
8890
8991@app_config_policy .command (name = "bulk-purge" )
9092@click .option (
91- "--config-names " ,
93+ "--ids " ,
9294 required = True ,
93- help = "Comma-separated `config_name`s , or `@path/to/names .json` for a JSON list." ,
95+ help = "Comma-separated policy row UUIDs , or `@path/to/ids .json` for a JSON list." ,
9496)
95- def bulk_purge (config_names : str ) -> None :
96- """Bulk-purge policies by `config_name` (partial-success semantics)."""
97+ def bulk_purge (ids : str ) -> None :
98+ """Bulk-purge policies by row id (partial-success semantics)."""
9799 from ai .backend .common .dto .manager .v2 .app_config_policy .request import (
98100 AdminBulkPurgeAppConfigPoliciesInput ,
99101 )
100102
101- if config_names .startswith ("@" ):
102- names = json .loads (Path (config_names [1 :]).read_text ())
103+ if ids .startswith ("@" ):
104+ raw_ids = json .loads (Path (ids [1 :]).read_text ())
103105 else :
104- names = [n .strip () for n in config_names .split ("," ) if n .strip ()]
106+ raw_ids = [s .strip () for s in ids .split ("," ) if s .strip ()]
107+ parsed_ids = [UUID (s ) for s in raw_ids ]
105108
106109 async def _run () -> None :
107110 registry = await create_v2_registry (load_v2_config ())
108111 try :
109112 result = await registry .app_config_policy .admin_bulk_purge (
110- AdminBulkPurgeAppConfigPoliciesInput (config_names = names ),
113+ AdminBulkPurgeAppConfigPoliciesInput (ids = parsed_ids ),
111114 )
112115 print_result (result )
113116 finally :
0 commit comments