Files
getDomain/domain-api/app/services/ops_execution_capability_service.py
2026-04-18 23:52:51 +08:00

80 lines
2.7 KiB
Python

from __future__ import annotations
from app.services.ops_action_executor_core import STRUCTURED_ACTIONS
_LOCAL_RUNTIME_ONLY_ACTIONS = {
"runtime.push_sync",
"runtime.pull_tasks",
}
_REMOTE_AGENT_ONLY_ACTIONS = {
"delivery.queue.flush",
"delivery.queue.replay",
"delivery.queue.discard",
}
_LOCAL_RUNTIME_ACTIONS = set(STRUCTURED_ACTIONS) | _LOCAL_RUNTIME_ONLY_ACTIONS | {"deploy.release"}
_SSH_ACTIONS = set(STRUCTURED_ACTIONS) | {"deploy.release"}
_REMOTE_AGENT_ACTIONS = set(STRUCTURED_ACTIONS) | _REMOTE_AGENT_ONLY_ACTIONS | {"deploy.release"}
_CONTROL_PLANE_ACTIONS = {
"node.bootstrap",
}
def supports_local_runtime_action(action: str) -> bool:
return str(action or "").strip() in _LOCAL_RUNTIME_ACTIONS
def supports_ssh_action(action: str) -> bool:
return str(action or "").strip() in _SSH_ACTIONS
def supports_remote_agent_action(action: str) -> bool:
return str(action or "").strip() in _REMOTE_AGENT_ACTIONS
def supports_control_plane_action(action: str) -> bool:
return str(action or "").strip() in _CONTROL_PLANE_ACTIONS
def validate_action_execution_mode(
action: str,
execution_mode: str,
*,
target_node_code: str = "",
current_node_code: str = "",
) -> tuple[bool, str]:
normalized_action = str(action or "").strip()
normalized_mode = str(execution_mode or "remote-agent").strip() or "remote-agent"
normalized_target_node_code = str(target_node_code or "").strip()
normalized_current_node_code = str(current_node_code or "").strip()
if normalized_mode == "local-runtime":
if not supports_local_runtime_action(normalized_action):
return False, f"{normalized_action} 当前不支持 local-runtime 执行方式。"
if (
normalized_target_node_code
and normalized_current_node_code
and normalized_target_node_code != normalized_current_node_code
):
return False, "local-runtime 仅支持当前控制面本机节点。"
return True, ""
if normalized_mode == "control-plane":
if not supports_control_plane_action(normalized_action):
return False, f"{normalized_action} 当前不支持 control-plane 执行方式。"
return True, ""
if normalized_mode == "ssh":
if not supports_ssh_action(normalized_action):
return False, f"{normalized_action} 当前不支持 ssh 执行方式。"
return True, ""
if normalized_mode == "remote-agent":
if not supports_remote_agent_action(normalized_action):
return False, f"{normalized_action} 当前不支持 remote-agent 执行方式。"
return True, ""
return False, f"未知执行方式: {normalized_mode}"