Add concurrent multi-NE CLI exec batch for field sweeps.

execManagedNe can take ne_ids/ume_ne_ids/targets and POST /v1/managed-ne/exec-batch so many show commands run in parallel instead of serial one-NE MCP loops.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-10 23:34:19 +08:00
parent 8a07baa018
commit 9ba4d051dc
8 changed files with 355 additions and 14 deletions

View file

@ -8,12 +8,13 @@ from .db import get_db
from .device_types import SUPPORTED_VENDORS
from .ne_connect import schedule_connect_tests
from .ne_crypto import credentials_configured
from .ne_exec import execute_managed_ne_commands
from .ne_exec import execute_managed_ne_commands, execute_managed_ne_commands_batch
from .ne_schemas import (
BatchAccountApplyRequest,
BatchHopApplyRequest,
ConnectTestRequest,
ManagedNeCreate,
ManagedNeExecBatchRequest,
ManagedNeExecRequest,
ManagedNeUpdate,
)
@ -141,6 +142,22 @@ def api_exec_managed_ne(body: ManagedNeExecRequest, db: Session = Depends(get_db
)
@router.post("/exec-batch")
def api_exec_managed_ne_batch(body: ManagedNeExecBatchRequest):
"""Run read-only CLI on many NEs concurrently (field multi-NE sweeps)."""
targets = None
if body.targets:
targets = [t.model_dump() for t in body.targets]
return execute_managed_ne_commands_batch(
targets=targets,
ne_ids=body.ne_ids,
ume_ne_ids=body.ume_ne_ids,
commands=body.commands,
read_timeout_sec=body.read_timeout_sec,
concurrency=body.concurrency,
)
@router.post("/connect-test")
def api_connect_test(body: ConnectTestRequest, db: Session = Depends(get_db)):
ids = [str(x).strip() for x in body.ids if str(x).strip()]