mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-30 07:40:12 +03:00
Merge pull request #2924 from markparonyan/mypy-api-plus
fix(typing): resolve mypy errors in api + compute.dynamips + compute.iou + compute.vpcs + controller
This commit is contained in:
commit
76411f1eb0
@ -19,6 +19,8 @@
|
||||
FastAPI app
|
||||
"""
|
||||
|
||||
from typing import cast
|
||||
|
||||
from fastapi import FastAPI, Request, HTTPException, status
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
@ -118,7 +120,7 @@ def handle_exit(*args, **kwargs):
|
||||
unicorn_exit_handler(*args, **kwargs)
|
||||
|
||||
|
||||
UvicornServer.handle_exit = handle_exit
|
||||
UvicornServer.handle_exit = handle_exit # type: ignore[method-assign]
|
||||
|
||||
|
||||
# Configure self-hosting JavaScript and CSS for docs
|
||||
@ -134,7 +136,7 @@ async def custom_swagger_ui_html():
|
||||
)
|
||||
|
||||
|
||||
@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False)
|
||||
@app.get(cast(str, app.swagger_ui_oauth2_redirect_url), include_in_schema=False)
|
||||
async def swagger_ui_redirect():
|
||||
return get_swagger_ui_oauth2_redirect_html()
|
||||
|
||||
|
||||
@ -1645,7 +1645,7 @@ class Router(BaseNode):
|
||||
await nio.start_packet_capture(output_file, data_link_type)
|
||||
log.debug(
|
||||
'Router "{name}" [{id}]: starting packet capture on port {slot_number}/{port_number}'.format(
|
||||
name=self._name, id=self._id, nio_name=nio.name, slot_number=slot_number, port_number=port_number
|
||||
name=self._name, id=self._id, slot_number=slot_number, port_number=port_number
|
||||
)
|
||||
)
|
||||
|
||||
@ -1685,7 +1685,7 @@ class Router(BaseNode):
|
||||
|
||||
log.debug(
|
||||
'Router "{name}" [{id}]: stopping packet capture on port {slot_number}/{port_number}'.format(
|
||||
name=self._name, id=self._id, nio_name=nio.name, slot_number=slot_number, port_number=port_number
|
||||
name=self._name, id=self._id, slot_number=slot_number, port_number=port_number
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@ -204,9 +204,8 @@ if __name__ == "__main__":
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
fd = open(args.nvram, "rb")
|
||||
nvram = fd.read()
|
||||
fd.close()
|
||||
with open(args.nvram, "rb") as fd:
|
||||
nvram = fd.read()
|
||||
except OSError as err:
|
||||
sys.stderr.write(f"Error reading file: {err}\n")
|
||||
sys.exit(1)
|
||||
@ -218,16 +217,14 @@ if __name__ == "__main__":
|
||||
sys.exit(3)
|
||||
|
||||
try:
|
||||
fd = open(args.startup, "wb")
|
||||
fd.write(startup)
|
||||
fd.close()
|
||||
with open(args.startup, "wb") as out:
|
||||
out.write(startup)
|
||||
if args.private is not None:
|
||||
if private is None:
|
||||
sys.stderr.write("Warning: No private config\n")
|
||||
else:
|
||||
fd = open(args.private, "wb")
|
||||
fd.write(private)
|
||||
fd.close()
|
||||
with open(args.private, "wb") as out:
|
||||
out.write(private)
|
||||
except OSError as err:
|
||||
sys.stderr.write(f"Error writing file: {err}\n")
|
||||
sys.exit(1)
|
||||
|
||||
@ -197,22 +197,17 @@ if __name__ == "__main__":
|
||||
parser.add_argument("private", metavar="private-config", nargs="?", help="private configuration")
|
||||
args = parser.parse_args()
|
||||
|
||||
nvram: bytes | None = None
|
||||
private: bytes | None = None
|
||||
try:
|
||||
if args.create is None:
|
||||
fd = open(args.nvram, "rb")
|
||||
nvram = fd.read()
|
||||
fd.close()
|
||||
else:
|
||||
nvram = None
|
||||
fd = open(args.startup, "rb")
|
||||
startup = fd.read()
|
||||
fd.close()
|
||||
if args.private is None:
|
||||
private = None
|
||||
else:
|
||||
fd = open(args.private, "rb")
|
||||
private = fd.read()
|
||||
fd.close()
|
||||
with open(args.nvram, "rb") as fd:
|
||||
nvram = fd.read()
|
||||
with open(args.startup, "rb") as fd:
|
||||
startup = fd.read()
|
||||
if args.private is not None:
|
||||
with open(args.private, "rb") as fd:
|
||||
private = fd.read()
|
||||
except OSError as err:
|
||||
sys.stderr.write(f"Error reading file: {err}\n")
|
||||
sys.exit(1)
|
||||
@ -224,9 +219,8 @@ if __name__ == "__main__":
|
||||
sys.exit(3)
|
||||
|
||||
try:
|
||||
fd = open(args.nvram, "wb")
|
||||
fd.write(nvram)
|
||||
fd.close()
|
||||
with open(args.nvram, "wb") as out:
|
||||
out.write(nvram)
|
||||
except OSError as err:
|
||||
sys.stderr.write(f"Error writing file: {err}\n")
|
||||
sys.exit(1)
|
||||
|
||||
@ -148,7 +148,11 @@ class VPCSVM(BaseNode):
|
||||
vpcs_path = shutil.which(vpcs_path)
|
||||
return vpcs_path
|
||||
|
||||
@BaseNode.name.setter
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, new_name):
|
||||
"""
|
||||
Sets the name of this VPCS VM.
|
||||
@ -358,7 +362,11 @@ class VPCSVM(BaseNode):
|
||||
if self.is_running():
|
||||
await self.reset_wrap_console()
|
||||
|
||||
@BaseNode.console_type.setter
|
||||
@property
|
||||
def console_type(self):
|
||||
return self._console_type
|
||||
|
||||
@console_type.setter
|
||||
def console_type(self, new_console_type):
|
||||
"""
|
||||
Sets the console type for this VPCS VM.
|
||||
|
||||
@ -51,6 +51,10 @@ class Appliance:
|
||||
def symbol(self):
|
||||
return self._data.get("symbol")
|
||||
|
||||
@symbol.setter
|
||||
def symbol(self, new_symbol):
|
||||
self._data["symbol"] = new_symbol
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._data.get("name")
|
||||
@ -63,10 +67,6 @@ class Appliance:
|
||||
def versions(self):
|
||||
return self._data.get("versions")
|
||||
|
||||
@symbol.setter
|
||||
def symbol(self, new_symbol):
|
||||
self._data["symbol"] = new_symbol
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
|
||||
|
||||
@ -300,13 +300,7 @@ module = [
|
||||
"gns3server.api.routes.controller.projects", # 16
|
||||
"gns3server.api.routes.controller.templates", # 10
|
||||
"gns3server.api.routes.controller.users", # 14
|
||||
"gns3server.api.server", # 2
|
||||
"gns3server.compute.dynamips.nodes.router", # 2
|
||||
"gns3server.compute.iou.utils.iou_export", # 2
|
||||
"gns3server.compute.iou.utils.iou_import", # 2
|
||||
"gns3server.compute.virtualbox.virtualbox_vm", # 1
|
||||
"gns3server.compute.vpcs.vpcs_vm", # 2
|
||||
"gns3server.controller.appliance", # 2
|
||||
"gns3server.controller.appliance_manager", # 5
|
||||
"gns3server.controller.project", # 2
|
||||
"gns3server.db.repositories.api_keys", # 8
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user