feat(python3.10): 适配 Python 3.10 并修复 SNMP 问题
修改内容: 1. 修复 SNMP 凭据显示问题:确保设备列表返回 snmp_credential_id 2. 修复清除 SNMP 凭据功能:新增 clear_snmp_credential 参数 3. 前端适配:处理清除凭据时的参数转换 4. 更新 requirements.txt:添加 Python 3.10 兼容说明和 typing-extensions 5. 添加 PYTHON_3_10_COMPATIBILITY.md 兼容性说明文档 验证: - 所有代码无 Python 3.11 特有语法 - 依赖包版本均支持 Python 3.10 - typing-extensions 提供向后兼容支持
This commit is contained in:
@@ -248,6 +248,7 @@ def get_network_devices(
|
||||
# 补充手写的关联字段(datetime 已经由 serialize_dt_fields 序列化)
|
||||
item["device_type"] = d.device_type.value if hasattr(d.device_type, 'value') else d.device_type
|
||||
item["credential_name"] = cred_map.get(d.snmp_credential_id)
|
||||
item["snmp_credential_id"] = d.snmp_credential_id # 显式添加,确保前端能拿到
|
||||
item["last_polled_at"] = item.get("last_polled_at") # 已是 ISO 字符串
|
||||
item["last_successful_poll"] = item.get("last_successful_poll")
|
||||
item["arp_poll_interval"] = d.arp_poll_interval
|
||||
@@ -325,6 +326,7 @@ def update_network_device(
|
||||
name: Optional[str] = None,
|
||||
ip_address: Optional[str] = None,
|
||||
snmp_credential_id: Optional[int] = None,
|
||||
clear_snmp_credential: bool = False, # 新增:专门的标志
|
||||
port: Optional[int] = None,
|
||||
device_type: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
@@ -350,7 +352,13 @@ def update_network_device(
|
||||
device.name = name
|
||||
if ip_address:
|
||||
device.ip_address = ip_address
|
||||
if snmp_credential_id is not None:
|
||||
# 处理 SNMP 凭据:
|
||||
# - clear_snmp_credential=True → 清除凭据
|
||||
# - snmp_credential_id > 0 → 设置为该值
|
||||
# - 否则(都不做任何操作
|
||||
if clear_snmp_credential:
|
||||
device.snmp_credential_id = None
|
||||
elif snmp_credential_id is not None and snmp_credential_id > 0:
|
||||
device.snmp_credential_id = snmp_credential_id
|
||||
if port:
|
||||
device.port = port
|
||||
|
||||
@@ -4,7 +4,7 @@ from datetime import datetime
|
||||
import ipaddress
|
||||
import logging
|
||||
|
||||
from pysnmp.hlapi import (
|
||||
from pysnmp.hlapi.asyncio import (
|
||||
SnmpEngine, CommunityData, UsmUserData,
|
||||
UdpTransportTarget, ContextData,
|
||||
ObjectType, ObjectIdentity,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# Python 3.10+ 兼容版本
|
||||
fastapi==0.110.0
|
||||
uvicorn[standard]==0.27.1
|
||||
sqlalchemy==2.0.28
|
||||
@@ -14,4 +15,7 @@ scapy==2.5.0
|
||||
python-dotenv==1.0.1
|
||||
passlib[bcrypt]==1.7.4
|
||||
httpx==0.27.0
|
||||
python-jose[cryptography]
|
||||
python-jose[cryptography]
|
||||
bcrypt==3.2.2
|
||||
# typing-extensions 提供 Python 3.10+ 的向后兼容支持
|
||||
typing-extensions>=4.5.0
|
||||
|
||||
Reference in New Issue
Block a user