mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
refactor: ruff autofixes
This commit is contained in:
455 files changed
+12322
-14762
No files matched your search
@@ -17,96 +17,86 @@
|
||||
import socket
|
||||
|
||||
from enum import Enum
|
||||
from pydantic import (
|
||||
ConfigDict,
|
||||
BaseModel,
|
||||
Field,
|
||||
SecretStr,
|
||||
FilePath,
|
||||
DirectoryPath,
|
||||
field_validator,
|
||||
model_validator
|
||||
)
|
||||
from pydantic import ConfigDict, BaseModel, Field, SecretStr, FilePath, DirectoryPath, field_validator, model_validator
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
class ControllerSettings(BaseModel):
|
||||
|
||||
jwt_secret_key: Optional[str] = Field(
|
||||
None,
|
||||
description="Secret key used to sign the JWT authentication tokens "
|
||||
"(normally managed via the secrets directory, not the configuration file)")
|
||||
"(normally managed via the secrets directory, not the configuration file)",
|
||||
)
|
||||
jwt_algorithm: str = Field("HS256", description="Algorithm used to sign the JWT tokens")
|
||||
jwt_access_token_expire_minutes: int = Field(
|
||||
1440, description="Lifetime of the JWT access tokens in minutes (24 hours by default)")
|
||||
1440, description="Lifetime of the JWT access tokens in minutes (24 hours by default)"
|
||||
)
|
||||
jwt_refresh_token_expire_minutes: int = Field(
|
||||
43200, description="Lifetime of the JWT refresh tokens in minutes (30 days by default)")
|
||||
43200, description="Lifetime of the JWT refresh tokens in minutes (30 days by default)"
|
||||
)
|
||||
default_admin_username: str = Field(
|
||||
"admin",
|
||||
description="Username of the super admin account seeded when the controller database is created; "
|
||||
"changing it has no effect until the database is re-created (which resets the account)")
|
||||
"changing it has no effect until the database is re-created (which resets the account)",
|
||||
)
|
||||
default_admin_password: SecretStr = Field(
|
||||
SecretStr("admin"),
|
||||
description="Password of the super admin account seeded when the controller database is created; "
|
||||
"changing it has no effect until the database is re-created (which resets the account)")
|
||||
"changing it has no effect until the database is re-created (which resets the account)",
|
||||
)
|
||||
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
|
||||
|
||||
|
||||
class VPCSSettings(BaseModel):
|
||||
|
||||
vpcs_path: str = Field("vpcs", description="VPCS executable location, default: search in PATH")
|
||||
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
|
||||
|
||||
|
||||
class DynamipsSettings(BaseModel):
|
||||
|
||||
allocate_aux_console_ports: bool = Field(
|
||||
False, description="Allocate auxiliary console ports on IOS routers")
|
||||
allocate_aux_console_ports: bool = Field(False, description="Allocate auxiliary console ports on IOS routers")
|
||||
mmap_support: bool = Field(
|
||||
True, description="Use memory-mapped flash files (mmap) to lower the memory usage of routers")
|
||||
True, description="Use memory-mapped flash files (mmap) to lower the memory usage of routers"
|
||||
)
|
||||
dynamips_path: str = Field("dynamips", description="Dynamips executable location, default: search in PATH")
|
||||
sparse_memory_support: bool = Field(
|
||||
True, description="Use sparse memory allocation to lower the memory usage of routers")
|
||||
True, description="Use sparse memory allocation to lower the memory usage of routers"
|
||||
)
|
||||
ghost_ios_support: bool = Field(
|
||||
True, description="Enable Ghost IOS support to share memory between identical IOS images")
|
||||
True, description="Enable Ghost IOS support to share memory between identical IOS images"
|
||||
)
|
||||
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
|
||||
|
||||
|
||||
class IOUSettings(BaseModel):
|
||||
|
||||
iourc_path: Optional[str] = Field(
|
||||
None, description="Path of your .iourc file, the file is searched in $HOME/.iourc if not provided")
|
||||
None, description="Path of your .iourc file, the file is searched in $HOME/.iourc if not provided"
|
||||
)
|
||||
license_check: bool = Field(
|
||||
True,
|
||||
description="Validate the iourc license file (if disabled, IOU will not start and no errors "
|
||||
"will be shown when the license is invalid)")
|
||||
"will be shown when the license is invalid)",
|
||||
)
|
||||
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
|
||||
|
||||
|
||||
class QemuSettings(BaseModel):
|
||||
|
||||
enable_monitor: bool = Field(
|
||||
True, description="Use the Qemu monitor feature to communicate with Qemu VMs")
|
||||
enable_monitor: bool = Field(True, description="Use the Qemu monitor feature to communicate with Qemu VMs")
|
||||
monitor_host: str = Field("127.0.0.1", description="IP used to listen for the monitor")
|
||||
enable_hardware_acceleration: bool = Field(
|
||||
True, description="Enable hardware acceleration (KVM)")
|
||||
enable_hardware_acceleration: bool = Field(True, description="Enable hardware acceleration (KVM)")
|
||||
require_hardware_acceleration: bool = Field(
|
||||
False, description="Require hardware acceleration in order to start VMs")
|
||||
allow_unsafe_options: bool = Field(
|
||||
False, description="Allow unsafe additional command line options")
|
||||
ovmf_firmware_dir: str = Field(
|
||||
"/usr/share/OVMF", description="Path to the OVMF firmware directory")
|
||||
False, description="Require hardware acceleration in order to start VMs"
|
||||
)
|
||||
allow_unsafe_options: bool = Field(False, description="Allow unsafe additional command line options")
|
||||
ovmf_firmware_dir: str = Field("/usr/share/OVMF", description="Path to the OVMF firmware directory")
|
||||
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
|
||||
|
||||
|
||||
class VirtualBoxSettings(BaseModel):
|
||||
|
||||
vboxmanage_path: Optional[str] = None
|
||||
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
|
||||
|
||||
|
||||
class VMwareSettings(BaseModel):
|
||||
|
||||
vmrun_path: Optional[str] = None
|
||||
vmnet_start_range: int = Field(2, ge=1, le=255)
|
||||
vmnet_end_range: int = Field(255, ge=1, le=255) # should be limited to 19 on Windows
|
||||
@@ -121,15 +111,15 @@ class VMwareSettings(BaseModel):
|
||||
|
||||
|
||||
class WebWiresharkSettings(BaseModel):
|
||||
|
||||
enabled: bool = Field(
|
||||
True, description="Enable the Web Wireshark feature (container-based Wireshark in the browser)")
|
||||
image: str = Field(
|
||||
"gns3/web-wireshark:latest", description="Docker image for the Web Wireshark containers")
|
||||
True, description="Enable the Web Wireshark feature (container-based Wireshark in the browser)"
|
||||
)
|
||||
image: str = Field("gns3/web-wireshark:latest", description="Docker image for the Web Wireshark containers")
|
||||
network_subnet: str = Field(
|
||||
"172.31.0.0/22",
|
||||
description="Docker network subnet for the Web Wireshark containers (change it if it conflicts "
|
||||
"with your existing network)")
|
||||
"with your existing network)",
|
||||
)
|
||||
memory: str = Field("2g", description='Memory limit per container (e.g. "512m", "2g")')
|
||||
cpus: float = Field(1.0, description="CPU cores per container (e.g. 1.0, 2.0)")
|
||||
pids_limit: int = Field(1000, description="Process limit per container")
|
||||
@@ -137,13 +127,11 @@ class WebWiresharkSettings(BaseModel):
|
||||
|
||||
|
||||
class ServerProtocol(str, Enum):
|
||||
|
||||
http = "http"
|
||||
https = "https"
|
||||
|
||||
|
||||
class UbridgeControlTransport(str, Enum):
|
||||
|
||||
# TCP control channel: -H host:port. ubridge now binds loopback by default,
|
||||
# so this is reachable only locally. Retained for backward compatibility.
|
||||
tcp = "tcp"
|
||||
@@ -153,7 +141,6 @@ class UbridgeControlTransport(str, Enum):
|
||||
|
||||
|
||||
class BuiltinSymbolTheme(str, Enum):
|
||||
|
||||
classic = "Classic"
|
||||
affinity_square_blue = "Affinity-square-blue"
|
||||
affinity_square_red = "Affinity-square-red"
|
||||
@@ -164,20 +151,20 @@ class BuiltinSymbolTheme(str, Enum):
|
||||
|
||||
|
||||
class ServerSettings(BaseModel):
|
||||
|
||||
local: bool = Field(
|
||||
False,
|
||||
description="Local server mode, set by the --local command line argument (not meant to be set by hand)")
|
||||
False, description="Local server mode, set by the --local command line argument (not meant to be set by hand)"
|
||||
)
|
||||
enable_http_auth: bool = Field(True, description="Enable compute HTTP authentication")
|
||||
name: str = Field(
|
||||
f"{socket.gethostname()} (controller)",
|
||||
description="Server name, default is what is returned by socket.gethostname()")
|
||||
protocol: ServerProtocol = Field(
|
||||
ServerProtocol.http, description="Protocol used by the server: http or https")
|
||||
description="Server name, default is what is returned by socket.gethostname()",
|
||||
)
|
||||
protocol: ServerProtocol = Field(ServerProtocol.http, description="Protocol used by the server: http or https")
|
||||
host: str = Field("0.0.0.0", description="IP address where the server listens for connections")
|
||||
port: int = Field(3080, gt=0, le=65535, description="HTTP port used to control the server")
|
||||
secrets_dir: Optional[DirectoryPath] = Field(
|
||||
None, description="Directory where secrets are stored (e.g. the JWT secret key)")
|
||||
None, description="Directory where secrets are stored (e.g. the JWT secret key)"
|
||||
)
|
||||
certfile: Optional[FilePath] = Field(None, description="SSL certificate file, requires enable_ssl")
|
||||
certkey: Optional[FilePath] = Field(None, description="SSL key file, requires enable_ssl")
|
||||
enable_ssl: bool = Field(False, description="Enable SSL encryption")
|
||||
@@ -189,80 +176,98 @@ class ServerSettings(BaseModel):
|
||||
resources_path: Optional[str] = Field(
|
||||
None,
|
||||
description="Path where files like built-in appliances and Docker resources are stored "
|
||||
"(defaults to the local user data directory)")
|
||||
"(defaults to the local user data directory)",
|
||||
)
|
||||
default_symbol_theme: BuiltinSymbolTheme = Field(
|
||||
BuiltinSymbolTheme.affinity_square_blue,
|
||||
description='Default symbol theme, e.g. "Classic" or "Affinity-square-blue"')
|
||||
allow_raw_images: bool = Field(
|
||||
True, description="Allow raw images to be uploaded to the server")
|
||||
auto_discover_images: bool = Field(
|
||||
True, description="Automatically discover images in the images directory")
|
||||
report_errors: bool = Field(
|
||||
True, description="Automatically send crash reports to the GNS3 team")
|
||||
description='Default symbol theme, e.g. "Classic" or "Affinity-square-blue"',
|
||||
)
|
||||
allow_raw_images: bool = Field(True, description="Allow raw images to be uploaded to the server")
|
||||
auto_discover_images: bool = Field(True, description="Automatically discover images in the images directory")
|
||||
report_errors: bool = Field(True, description="Automatically send crash reports to the GNS3 team")
|
||||
additional_images_paths: List[str] = Field(
|
||||
default_factory=list,
|
||||
description="Additional paths to look for images (semicolon-separated in the configuration file)")
|
||||
description="Additional paths to look for images (semicolon-separated in the configuration file)",
|
||||
)
|
||||
console_start_port_range: int = Field(
|
||||
5000, gt=0, le=65535, description="First console port of the range allocated to devices")
|
||||
5000, gt=0, le=65535, description="First console port of the range allocated to devices"
|
||||
)
|
||||
console_end_port_range: int = Field(
|
||||
10000, gt=0, le=65535, description="Last console port of the range allocated to devices")
|
||||
10000, gt=0, le=65535, description="Last console port of the range allocated to devices"
|
||||
)
|
||||
vnc_console_start_port_range: int = Field(
|
||||
5900, ge=5900, le=65535, description="First VNC console port of the range allocated to devices")
|
||||
5900, ge=5900, le=65535, description="First VNC console port of the range allocated to devices"
|
||||
)
|
||||
vnc_console_end_port_range: int = Field(
|
||||
10000, ge=5900, le=65535, description="Last VNC console port of the range allocated to devices")
|
||||
10000, ge=5900, le=65535, description="Last VNC console port of the range allocated to devices"
|
||||
)
|
||||
udp_start_port_range: int = Field(
|
||||
10000, gt=0, le=65535,
|
||||
description="First UDP port of the range allocated for inter-device communication (two ports per link)")
|
||||
10000,
|
||||
gt=0,
|
||||
le=65535,
|
||||
description="First UDP port of the range allocated for inter-device communication (two ports per link)",
|
||||
)
|
||||
udp_end_port_range: int = Field(
|
||||
30000, gt=0, le=65535,
|
||||
description="Last UDP port of the range allocated for inter-device communication (two ports per link)")
|
||||
30000,
|
||||
gt=0,
|
||||
le=65535,
|
||||
description="Last UDP port of the range allocated for inter-device communication (two ports per link)",
|
||||
)
|
||||
ubridge_path: str = Field("ubridge", description="uBridge executable location, default: search in PATH")
|
||||
ubridge_control_transport: UbridgeControlTransport = Field(
|
||||
UbridgeControlTransport.unix,
|
||||
description='uBridge control channel transport: "unix" (AF_UNIX + SO_PEERCRED, recommended '
|
||||
'on Linux) or "tcp" (loopback, kept for backward compatibility)')
|
||||
'on Linux) or "tcp" (loopback, kept for backward compatibility)',
|
||||
)
|
||||
marker_listen_host: str = Field(
|
||||
"127.0.0.1",
|
||||
description="Marker (traffic-insight) UDP sink listen host: one listener per compute process "
|
||||
"receives uBridge MARK signals from every uBridge on this host")
|
||||
"receives uBridge MARK signals from every uBridge on this host",
|
||||
)
|
||||
marker_listen_port: int = Field(
|
||||
3070, ge=0, le=65535,
|
||||
description="Marker UDP sink listen port (0 lets the operating system choose a free port)")
|
||||
compute_username: str = Field(
|
||||
"gns3", description='Username for compute HTTP authentication, "gns3" is the default')
|
||||
3070, ge=0, le=65535, description="Marker UDP sink listen port (0 lets the operating system choose a free port)"
|
||||
)
|
||||
compute_username: str = Field("gns3", description='Username for compute HTTP authentication, "gns3" is the default')
|
||||
compute_password: SecretStr = Field(
|
||||
SecretStr(""),
|
||||
description="Password for compute HTTP authentication, a randomly generated password is used if not set")
|
||||
description="Password for compute HTTP authentication, a randomly generated password is used if not set",
|
||||
)
|
||||
allowed_interfaces: List[str] = Field(
|
||||
default_factory=list,
|
||||
description="Only allow these interfaces to be used by GNS3, for the Cloud node for example "
|
||||
"(comma-separated; do not forget virbr0 for the NAT node to work)")
|
||||
"(comma-separated; do not forget virbr0 for the NAT node to work)",
|
||||
)
|
||||
default_nat_interface: Optional[str] = Field(
|
||||
None, description="Interface used by the NAT node, default is virbr0 on Linux (requires libvirt)")
|
||||
None, description="Interface used by the NAT node, default is virbr0 on Linux (requires libvirt)"
|
||||
)
|
||||
allow_remote_console: bool = Field(
|
||||
False,
|
||||
description="Allow console connections from remote machines "
|
||||
"(console ports only accept local connections by default)")
|
||||
"(console ports only accept local connections by default)",
|
||||
)
|
||||
enable_builtin_templates: bool = Field(True, description="Enable the built-in templates")
|
||||
install_builtin_appliances: bool = Field(True, description="Install the built-in appliances")
|
||||
skills_repo_url: str = Field(
|
||||
"https://github.com/gns3/gns3-skills.git",
|
||||
description="Git repository URL for the external GNS3 Copilot skills "
|
||||
"(injection skills, prompts and device skills)")
|
||||
"(injection skills, prompts and device skills)",
|
||||
)
|
||||
skills_repo_branch: str = Field("main", description="Git branch of the skills repository")
|
||||
skills_auto_update: bool = Field(
|
||||
True, description="Automatically pull updates from the skills repository when reloading")
|
||||
True, description="Automatically pull updates from the skills repository when reloading"
|
||||
)
|
||||
mcp_enable_dns_rebinding_protection: bool = Field(
|
||||
False,
|
||||
description="Enable MCP transport DNS rebinding protection "
|
||||
"(allowed hosts and origins must be configured)")
|
||||
description="Enable MCP transport DNS rebinding protection (allowed hosts and origins must be configured)",
|
||||
)
|
||||
mcp_allowed_hosts: list[str] = Field(
|
||||
default_factory=list,
|
||||
description='Allowed hosts for MCP connections, only "host:*" port wildcards are supported '
|
||||
'(e.g. "127.0.0.1:*")')
|
||||
'(e.g. "127.0.0.1:*")',
|
||||
)
|
||||
mcp_allowed_origins: list[str] = Field(
|
||||
default_factory=list,
|
||||
description='Allowed origins for MCP connections (e.g. "http://localhost:*")')
|
||||
default_factory=list, description='Allowed origins for MCP connections (e.g. "http://localhost:*")'
|
||||
)
|
||||
|
||||
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True)
|
||||
|
||||
@@ -325,7 +330,6 @@ class ServerSettings(BaseModel):
|
||||
|
||||
|
||||
class ServerConfig(BaseModel):
|
||||
|
||||
Server: ServerSettings = ServerSettings()
|
||||
Controller: ControllerSettings = ControllerSettings()
|
||||
VPCS: VPCSSettings = VPCSSettings()
|
||||
|
||||
Reference in new issue
Block a user