mirror of
https://github.com/Jerryplusy/AI-powered-switches.git
synced 2025-10-14 09:49:19 +00:00
基础api服务可进行,可扫描网络交换机(已修改相关问题,注意下载Nmap才可扫描交换机网址:https://nmap.org/download.html),添加了配置多台交换机的功能,ensp配置.需用实际设备进一步调试
This commit is contained in:
parent
00de4c3411
commit
31a864b0b0
@ -1,7 +1,7 @@
|
|||||||
# AI-powered-switches Backend
|
# AI-powered-switches Backend
|
||||||
|
|
||||||
这是 AI-powered-switches 的后端服务,基于 `Flask` 构建,提供 `REST API` 接口,用于解析自然语言生成网络交换机配置并下发到设备
|
这是 AI-powered-switches 的后端服务,基于 `Flask` 构建,提供 `REST API` 接口,用于解析自然语言生成网络交换机配置并下发到设备
|
||||||
|
注意下载Nmap才可扫描交换机网址:https://nmap.org/download.html
|
||||||
### 项目结构
|
### 项目结构
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import (APIRouter, HTTPException)
|
||||||
from typing import List
|
from typing import List
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@ -87,3 +87,4 @@ async def apply_config(request: ConfigRequest):
|
|||||||
status_code=500,
|
status_code=500,
|
||||||
detail=f"Failed to apply config: {str(e)}"
|
detail=f"Failed to apply config: {str(e)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import paramiko
|
import paramiko
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import aiofiles
|
||||||
|
from datetime import datetime
|
||||||
from typing import Dict, List, Optional, Union
|
from typing import Dict, List, Optional, Union
|
||||||
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
|
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from paramiko.channel import ChannelFile
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
@ -41,6 +44,7 @@ class SwitchConfigurator:
|
|||||||
is_emulated: bool = False,
|
is_emulated: bool = False,
|
||||||
emulated_delay: float = 2.0
|
emulated_delay: float = 2.0
|
||||||
):
|
):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
初始化配置器
|
初始化配置器
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
class AICommandParseException(HTTPException):
|
class AICommandParseException(HTTPException):
|
||||||
def __init__(self, detail: str):
|
def __init__(self, detail: str):
|
||||||
@ -8,15 +9,28 @@ class AICommandParseException(HTTPException):
|
|||||||
)
|
)
|
||||||
|
|
||||||
class SwitchConfigException(HTTPException):
|
class SwitchConfigException(HTTPException):
|
||||||
def __init__(self, detail: str):
|
def __init__(
|
||||||
|
self,
|
||||||
|
detail: str,
|
||||||
|
status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status_code,
|
||||||
detail=f"Switch configuration error: {detail}"
|
detail=f"Switch error: {detail}"
|
||||||
)
|
)
|
||||||
|
|
||||||
class SiliconFlowAPIException(HTTPException):
|
class ConfigBackupException(SwitchConfigException):
|
||||||
def __init__(self, detail: str):
|
"""配置备份失败异常"""
|
||||||
|
def __init__(self, ip: str):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
detail=f"无法备份设备 {ip} 的配置",
|
||||||
detail=f"SiliconFlow API error: {detail}"
|
recovery_guide="检查设备存储空间或权限"
|
||||||
|
)
|
||||||
|
|
||||||
|
class ConfigRollbackException(SwitchConfigException):
|
||||||
|
"""回滚失败异常"""
|
||||||
|
def __init__(self, ip: str, original_error: str):
|
||||||
|
super().__init__(
|
||||||
|
detail=f"设备 {ip} 回滚失败(原始错误:{original_error})",
|
||||||
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||||
)
|
)
|
@ -8,3 +8,4 @@ loguru>=0.7.0
|
|||||||
python-nmap>=0.7.1
|
python-nmap>=0.7.1
|
||||||
tenacity>=9.1.2
|
tenacity>=9.1.2
|
||||||
typing-extensions>=4.0.0
|
typing-extensions>=4.0.0
|
||||||
|
aiofiles>=24.1.0
|
1
switch_devices.json
Normal file
1
switch_devices.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[]
|
Loading…
x
Reference in New Issue
Block a user