mirror of
https://github.com/Jerryplusy/AI-powered-switches.git
synced 2025-10-14 17:59:19 +00:00
签出测试分支
This commit is contained in:
parent
d11decae6a
commit
1d7939b88b
@ -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", [])}
|
||||
|
@ -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,10 +64,15 @@ const ConfigPage = () => {
|
||||
|
||||
try {
|
||||
const performParse = async () =>
|
||||
await api.parseCommand({
|
||||
command: inputText,
|
||||
devices: selectedConfigs,
|
||||
});
|
||||
testMode
|
||||
? await api.parseTest({
|
||||
command: inputText,
|
||||
devices: selectedConfigs,
|
||||
})
|
||||
: await api.parseCommand({
|
||||
command: inputText,
|
||||
devices: selectedConfigs,
|
||||
});
|
||||
|
||||
const resultWrapper = await Notification.promise({
|
||||
promise: performParse(),
|
||||
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user