Merge pull request #2918 from markparonyan/mypy-api-routes-compute-2

fix(typing): resolve mypy errors in gns3server.api.routes.compute
This commit is contained in:
Jeremy Grossmann 2026-09-29 13:22:22 +02:00 committed by GitHub
commit 3be6da2476
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 29 deletions

View File

@ -22,6 +22,7 @@ through uBridge's ``brctl`` module (see
``gns3server.compute.builtin.nodes.ethernet_switch``). ``gns3server.compute.builtin.nodes.ethernet_switch``).
""" """
from typing import Any
import os import os
from fastapi import APIRouter, Depends, Body, Path, status, HTTPException from fastapi import APIRouter, Depends, Body, Path, status, HTTPException
@ -33,7 +34,9 @@ from gns3server.compute.builtin import Builtin
from gns3server.compute.builtin.nodes.ethernet_switch import EthernetSwitch from gns3server.compute.builtin.nodes.ethernet_switch import EthernetSwitch
from gns3server import schemas from gns3server import schemas
responses = {404: {"model": schemas.ErrorMessage, "description": "Could not find project or Ethernet switch node"}} responses: dict[int | str, dict[str, Any]] = {
404: {"model": schemas.ErrorMessage, "description": "Could not find project or Ethernet switch node"}
}
router = APIRouter(responses=responses) router = APIRouter(responses=responses)
@ -60,17 +63,17 @@ async def create_ethernet_switch(project_id: UUID, node_data: schemas.EthernetSw
""" """
builtin_manager = Builtin.instance() builtin_manager = Builtin.instance()
node_data = jsonable_encoder(node_data, exclude_unset=True) data = jsonable_encoder(node_data, exclude_unset=True)
node = await builtin_manager.create_node( node = await builtin_manager.create_node(
node_data.pop("name"), data.pop("name"),
str(project_id), str(project_id),
node_data.get("node_id"), data.get("node_id"),
console=node_data.get("console"), console=data.get("console"),
console_type=node_data.get("console_type"), console_type=data.get("console_type"),
node_type="ethernet_switch", node_type="ethernet_switch",
ports=node_data.get("ports_mapping"), ports=data.get("ports_mapping"),
) )
node.usage = node_data.get("usage", "") node.usage = data.get("usage", "")
return node.asdict() return node.asdict()
@ -100,16 +103,16 @@ async def update_ethernet_switch(
Update an Ethernet switch. Update an Ethernet switch.
""" """
node_data = jsonable_encoder(node_data, exclude_unset=True) data = jsonable_encoder(node_data, exclude_unset=True)
if "name" in node_data and node.name != node_data["name"]: if "name" in data and node.name != data["name"]:
node.name = node_data["name"] node.name = data["name"]
if "usage" in node_data: if "usage" in data:
node.usage = node_data["usage"] node.usage = data["usage"]
if "ports_mapping" in node_data: if "ports_mapping" in data:
node.ports_mapping = node_data["ports_mapping"] node.ports_mapping = data["ports_mapping"]
await node.update_port_settings() await node.update_port_settings()
if "console_type" in node_data: if "console_type" in data:
node.console_type = node_data["console_type"] node.console_type = data["console_type"]
node.updated() node.updated()
return node.asdict() return node.asdict()

View File

@ -18,6 +18,7 @@
API routes for Frame Relay switch nodes. API routes for Frame Relay switch nodes.
""" """
from typing import Any
import os import os
from fastapi import APIRouter, Depends, Body, Path, status, HTTPException from fastapi import APIRouter, Depends, Body, Path, status, HTTPException
@ -29,7 +30,9 @@ from gns3server import schemas
from gns3server.compute.dynamips import Dynamips from gns3server.compute.dynamips import Dynamips
from gns3server.compute.dynamips.nodes.frame_relay_switch import FrameRelaySwitch from gns3server.compute.dynamips.nodes.frame_relay_switch import FrameRelaySwitch
responses = {404: {"model": schemas.ErrorMessage, "description": "Could not find project or Frame Relay switch node"}} responses: dict[int | str, dict[str, Any]] = {
404: {"model": schemas.ErrorMessage, "description": "Could not find project or Frame Relay switch node"}
}
router = APIRouter(responses=responses) router = APIRouter(responses=responses)
@ -59,13 +62,13 @@ async def create_frame_relay_switch(
# Use the Dynamips Frame Relay switch to simulate this node # Use the Dynamips Frame Relay switch to simulate this node
dynamips_manager = Dynamips.instance() dynamips_manager = Dynamips.instance()
node_data = jsonable_encoder(node_data, exclude_unset=True) data = jsonable_encoder(node_data, exclude_unset=True)
node = await dynamips_manager.create_node( node = await dynamips_manager.create_node(
node_data.pop("name"), data.pop("name"),
str(project_id), str(project_id),
node_data.get("node_id"), data.get("node_id"),
node_type="frame_relay_switch", node_type="frame_relay_switch",
mappings=node_data.get("mappings"), mappings=data.get("mappings"),
) )
return node.asdict() return node.asdict()
@ -99,11 +102,11 @@ async def update_frame_relay_switch(
Update an Frame Relay switch node. Update an Frame Relay switch node.
""" """
node_data = jsonable_encoder(node_data, exclude_unset=True) data = jsonable_encoder(node_data, exclude_unset=True)
if "name" in node_data and node.name != node_data["name"]: if "name" in data and node.name != data["name"]:
await node.set_name(node_data["name"]) await node.set_name(data["name"])
if "mappings" in node_data: if "mappings" in data:
node.mappings = node_data["mappings"] node.mappings = data["mappings"]
node.updated() node.updated()
return node.asdict() return node.asdict()

View File

@ -294,8 +294,6 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
# Baseline: modules with existing type errors (error count at baseline time). # Baseline: modules with existing type errors (error count at baseline time).
# Remove modules from this list one small PR at a time. Never add new ones. # Remove modules from this list one small PR at a time. Never add new ones.
module = [ module = [
"gns3server.api.routes.compute.ethernet_switch_nodes", # 16
"gns3server.api.routes.compute.frame_relay_switch_nodes", # 9
"gns3server.api.routes.compute.iou_nodes", # 15 "gns3server.api.routes.compute.iou_nodes", # 15
"gns3server.api.routes.compute.nat_nodes", # 10 "gns3server.api.routes.compute.nat_nodes", # 10
"gns3server.api.routes.compute.projects", # 7 "gns3server.api.routes.compute.projects", # 7