签出测试分支

This commit is contained in:
Jerry 2025-09-10 15:20:32 +08:00
parent d11decae6a
commit 1d7939b88b
3 changed files with 43 additions and 14 deletions

View File

@ -89,6 +89,7 @@ class DeviceItem(BaseModel):
class CommandRequest(BaseModel):
command: str
devices: List[DeviceItem]
test_mode: bool = False
@router.post("/parse_command", response_model=dict)
async def parse_command(request: CommandRequest):
@ -101,6 +102,36 @@ async def parse_command(request: CommandRequest):
detail=f"以下设备未配置厂商: {names}"
)
try:
if request.test_mode:
return {
"success": True,
"config": [
{
"device": {
"name": "交换机 1",
"ip": "172.17.99.207",
"vendor": "huawei",
"username": "NONE",
"password": "NONE"
},
"config": {
"type": "vlan",
"vlan_id": 114,
"commands": [
"system-view",
"vlan 114",
"quit",
"interface GigabitEthernet 0/0/1",
"port link-type access",
"port default vlan 114",
"quit",
"save",
"Y"
]
}
}
]
}
ai_service = AIService(settings.SILICONFLOW_API_KEY, settings.SILICONFLOW_API_URL)
config = await ai_service.parse_command(request.command, [d.dict() for d in request.devices])
return {"success": True, "config": config.get("results", [])}

View File

@ -8,7 +8,6 @@ import {
HStack,
Portal,
Select,
Spinner,
Text,
Textarea,
VStack,
@ -21,7 +20,6 @@ import FadeInWrapper from '@/components/system/layout/FadeInWrapper';
import ConfigTool from '@/libs/config/ConfigTool';
import { api } from '@/services/api/api';
import Notification from '@/libs/system/Notification';
import Common from '@/libs/common';
const testMode = ConfigTool.load().testMode;
@ -66,7 +64,12 @@ const ConfigPage = () => {
try {
const performParse = async () =>
await api.parseCommand({
testMode
? await api.parseTest({
command: inputText,
devices: selectedConfigs,
})
: await api.parseCommand({
command: inputText,
devices: selectedConfigs,
});
@ -120,14 +123,6 @@ const ConfigPage = () => {
setApplying(true);
try {
const applyOperation = async () => {
if (testMode) {
await Common.sleep(1000);
Notification.success({
title: '测试模式成功',
description: '配置已模拟应用',
});
return;
}
const applyPromises = selectedDevices.map(async (ip) => {
const deviceItem = deviceConfigs[ip];
if (!deviceItem) return;

View File

@ -47,6 +47,9 @@ export const api = {
parseCommand: ({ command, devices }) =>
axios.post(buildUrl('/api/parse_command'), { command, devices }),
parseTest: ({ command, devices }) =>
axios.post(buildUrl('/api/parse_command'), { command, devices, test_mode: true }),
/**
* 应用配置
* @param {string} switch_ip 交换机IP