mirror of
https://github.com/Jerryplusy/AI-powered-switches.git
synced 2025-10-14 09:49:19 +00:00
签出测试分支
This commit is contained in:
parent
d11decae6a
commit
1d7939b88b
@ -89,6 +89,7 @@ class DeviceItem(BaseModel):
|
|||||||
class CommandRequest(BaseModel):
|
class CommandRequest(BaseModel):
|
||||||
command: str
|
command: str
|
||||||
devices: List[DeviceItem]
|
devices: List[DeviceItem]
|
||||||
|
test_mode: bool = False
|
||||||
|
|
||||||
@router.post("/parse_command", response_model=dict)
|
@router.post("/parse_command", response_model=dict)
|
||||||
async def parse_command(request: CommandRequest):
|
async def parse_command(request: CommandRequest):
|
||||||
@ -101,6 +102,36 @@ async def parse_command(request: CommandRequest):
|
|||||||
detail=f"以下设备未配置厂商: {names}"
|
detail=f"以下设备未配置厂商: {names}"
|
||||||
)
|
)
|
||||||
try:
|
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)
|
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])
|
config = await ai_service.parse_command(request.command, [d.dict() for d in request.devices])
|
||||||
return {"success": True, "config": config.get("results", [])}
|
return {"success": True, "config": config.get("results", [])}
|
||||||
|
@ -8,7 +8,6 @@ import {
|
|||||||
HStack,
|
HStack,
|
||||||
Portal,
|
Portal,
|
||||||
Select,
|
Select,
|
||||||
Spinner,
|
|
||||||
Text,
|
Text,
|
||||||
Textarea,
|
Textarea,
|
||||||
VStack,
|
VStack,
|
||||||
@ -21,7 +20,6 @@ import FadeInWrapper from '@/components/system/layout/FadeInWrapper';
|
|||||||
import ConfigTool from '@/libs/config/ConfigTool';
|
import ConfigTool from '@/libs/config/ConfigTool';
|
||||||
import { api } from '@/services/api/api';
|
import { api } from '@/services/api/api';
|
||||||
import Notification from '@/libs/system/Notification';
|
import Notification from '@/libs/system/Notification';
|
||||||
import Common from '@/libs/common';
|
|
||||||
|
|
||||||
const testMode = ConfigTool.load().testMode;
|
const testMode = ConfigTool.load().testMode;
|
||||||
|
|
||||||
@ -66,10 +64,15 @@ const ConfigPage = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const performParse = async () =>
|
const performParse = async () =>
|
||||||
await api.parseCommand({
|
testMode
|
||||||
command: inputText,
|
? await api.parseTest({
|
||||||
devices: selectedConfigs,
|
command: inputText,
|
||||||
});
|
devices: selectedConfigs,
|
||||||
|
})
|
||||||
|
: await api.parseCommand({
|
||||||
|
command: inputText,
|
||||||
|
devices: selectedConfigs,
|
||||||
|
});
|
||||||
|
|
||||||
const resultWrapper = await Notification.promise({
|
const resultWrapper = await Notification.promise({
|
||||||
promise: performParse(),
|
promise: performParse(),
|
||||||
@ -120,14 +123,6 @@ const ConfigPage = () => {
|
|||||||
setApplying(true);
|
setApplying(true);
|
||||||
try {
|
try {
|
||||||
const applyOperation = async () => {
|
const applyOperation = async () => {
|
||||||
if (testMode) {
|
|
||||||
await Common.sleep(1000);
|
|
||||||
Notification.success({
|
|
||||||
title: '测试模式成功',
|
|
||||||
description: '配置已模拟应用',
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const applyPromises = selectedDevices.map(async (ip) => {
|
const applyPromises = selectedDevices.map(async (ip) => {
|
||||||
const deviceItem = deviceConfigs[ip];
|
const deviceItem = deviceConfigs[ip];
|
||||||
if (!deviceItem) return;
|
if (!deviceItem) return;
|
||||||
|
@ -47,6 +47,9 @@ export const api = {
|
|||||||
parseCommand: ({ command, devices }) =>
|
parseCommand: ({ command, devices }) =>
|
||||||
axios.post(buildUrl('/api/parse_command'), { 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
|
* @param {string} switch_ip 交换机IP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user