mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
Pydantic v2 migration
This commit is contained in:
1 parent
11f51b3809
commit
9c456532d0
46 files changed
+221
-277
No files matched your search
@@ -31,7 +31,7 @@ class DockerBase(BaseModel):
|
||||
node_id: Optional[UUID] = None
|
||||
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
|
||||
console_type: Optional[ConsoleType] = Field(None, description="Console type")
|
||||
console_resolution: Optional[str] = Field(None, regex="^[0-9]+x[0-9]+$", description="Console resolution for VNC")
|
||||
console_resolution: Optional[str] = Field(None, pattern="^[0-9]+x[0-9]+$", description="Console resolution for VNC")
|
||||
console_http_port: Optional[int] = Field(None, description="Internal port in the container for the HTTP server")
|
||||
console_http_path: Optional[str] = Field(None, description="Path of the web interface")
|
||||
aux: Optional[int] = Field(None, gt=0, le=65535, description="Auxiliary TCP port")
|
||||
@@ -67,7 +67,7 @@ class DockerUpdate(DockerBase):
|
||||
class Docker(DockerBase):
|
||||
|
||||
container_id: str = Field(
|
||||
..., min_length=12, max_length=64, regex="^[a-f0-9]+$", description="Docker container ID (read only)"
|
||||
..., min_length=12, max_length=64, pattern="^[a-f0-9]+$", description="Docker container ID (read only)"
|
||||
)
|
||||
project_id: UUID = Field(..., description="Project ID")
|
||||
node_directory: str = Field(..., description="Path to the node working directory (read only)")
|
||||
|
||||
@@ -129,13 +129,13 @@ class DynamipsBase(BaseModel):
|
||||
image: Optional[str] = Field(None, description="Path to the IOS image")
|
||||
image_md5sum: Optional[str] = Field(None, description="Checksum of the IOS image")
|
||||
usage: Optional[str] = Field(None, description="How to use the Dynamips VM")
|
||||
chassis: Optional[str] = Field(None, description="Cisco router chassis model", regex="^[0-9]{4}(XM)?$")
|
||||
chassis: Optional[str] = Field(None, description="Cisco router chassis model", pattern="^[0-9]{4}(XM)?$")
|
||||
startup_config_content: Optional[str] = Field(None, description="Content of IOS startup configuration file")
|
||||
private_config_content: Optional[str] = Field(None, description="Content of IOS private configuration file")
|
||||
mmap: Optional[bool] = Field(None, description="MMAP feature")
|
||||
sparsemem: Optional[bool] = Field(None, description="Sparse memory feature")
|
||||
clock_divisor: Optional[int] = Field(None, description="Clock divisor")
|
||||
idlepc: Optional[str] = Field(None, description="Idle-PC value", regex="^(0x[0-9a-fA-F]+)?$")
|
||||
idlepc: Optional[str] = Field(None, description="Idle-PC value", pattern="^(0x[0-9a-fA-F]+)?$")
|
||||
idlemax: Optional[int] = Field(None, description="Idlemax value")
|
||||
idlesleep: Optional[int] = Field(None, description="Idlesleep value")
|
||||
exec_area: Optional[int] = Field(None, description="Exec area value")
|
||||
@@ -147,7 +147,7 @@ class DynamipsBase(BaseModel):
|
||||
aux: Optional[int] = Field(None, gt=0, le=65535, description="Auxiliary console TCP port")
|
||||
aux_type: Optional[DynamipsConsoleType] = Field(None, description="Auxiliary console type")
|
||||
mac_addr: Optional[str] = Field(
|
||||
None, description="Base MAC address", regex="^([0-9a-fA-F]{4}\\.){2}[0-9a-fA-F]{4}$"
|
||||
None, description="Base MAC address", pattern="^([0-9a-fA-F]{4}\\.){2}[0-9a-fA-F]{4}$"
|
||||
)
|
||||
system_id: Optional[str] = Field(None, description="System ID")
|
||||
slot0: Optional[DynamipsAdapters] = Field(None, description="Network module slot 0")
|
||||
@@ -174,7 +174,7 @@ class DynamipsCreate(DynamipsBase):
|
||||
"""
|
||||
|
||||
name: str
|
||||
platform: str = Field(..., description="Cisco router platform", regex="^c[0-9]{4}$")
|
||||
platform: str = Field(..., description="Cisco router platform", pattern="^c[0-9]{4}$")
|
||||
image: str = Field(..., description="Path to the IOS image")
|
||||
ram: int = Field(..., description="Amount of RAM in MB")
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
from typing import Optional, List
|
||||
from uuid import UUID
|
||||
from enum import Enum
|
||||
@@ -43,15 +43,14 @@ class EthernetSwitchPort(BaseModel):
|
||||
port_number: int
|
||||
type: EthernetSwitchPortType = Field(..., description="Port type")
|
||||
vlan: int = Field(..., ge=1, le=4094, description="VLAN number")
|
||||
ethertype: Optional[EthernetSwitchEtherType] = Field(None, description="QinQ Ethertype")
|
||||
ethertype: Optional[EthernetSwitchEtherType] = Field("0x8100", description="QinQ Ethertype")
|
||||
|
||||
@validator("ethertype")
|
||||
def validate_ethertype(cls, v, values):
|
||||
@model_validator(mode="after")
|
||||
def check_ethertype(self) -> "EthernetSwitchPort":
|
||||
|
||||
if v is not None:
|
||||
if "type" not in values or values["type"] != EthernetSwitchPortType.qinq:
|
||||
raise ValueError("Ethertype is only for QinQ port type")
|
||||
return v
|
||||
if self.ethertype != EthernetSwitchEtherType.ethertype_8021q and self.type != EthernetSwitchPortType.qinq:
|
||||
raise ValueError("Ethertype is only for QinQ port type")
|
||||
return self
|
||||
|
||||
|
||||
class TelnetConsoleType(str, Enum):
|
||||
|
||||
@@ -29,7 +29,7 @@ class IOUBase(BaseModel):
|
||||
name: str
|
||||
path: str = Field(..., description="IOU executable path")
|
||||
application_id: int = Field(..., description="Application ID for running IOU executable")
|
||||
node_id: Optional[UUID]
|
||||
node_id: Optional[UUID] = None
|
||||
usage: Optional[str] = Field(None, description="How to use the node")
|
||||
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
|
||||
console_type: Optional[ConsoleType] = Field(None, description="Console type")
|
||||
@@ -57,7 +57,7 @@ class IOUUpdate(IOUBase):
|
||||
Properties to update an IOU node.
|
||||
"""
|
||||
|
||||
name: Optional[str]
|
||||
name: Optional[str] = None
|
||||
path: Optional[str] = Field(None, description="IOU executable path")
|
||||
application_id: Optional[int] = Field(None, description="Application ID for running IOU executable")
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ class QemuBase(BaseModel):
|
||||
"""
|
||||
|
||||
name: str
|
||||
node_id: Optional[UUID]
|
||||
node_id: Optional[UUID] = None
|
||||
usage: Optional[str] = Field(None, description="How to use the node")
|
||||
linked_clone: Optional[bool] = Field(None, description="Whether the VM is a linked clone or not")
|
||||
qemu_path: Optional[str] = Field(None, description="Qemu executable path")
|
||||
@@ -197,7 +197,7 @@ class QemuBase(BaseModel):
|
||||
adapters: Optional[int] = Field(None, ge=0, le=275, description="Number of adapters")
|
||||
adapter_type: Optional[QemuAdapterType] = Field(None, description="QEMU adapter type")
|
||||
mac_address: Optional[str] = Field(
|
||||
None, description="QEMU MAC address", regex="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$"
|
||||
None, description="QEMU MAC address", pattern="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$"
|
||||
)
|
||||
replicate_network_connection_state: Optional[bool] = Field(
|
||||
None, description="Replicate the network connection state for links in Qemu"
|
||||
@@ -227,7 +227,7 @@ class QemuUpdate(QemuBase):
|
||||
Properties to update a Qemu node.
|
||||
"""
|
||||
|
||||
name: Optional[str]
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class Qemu(QemuBase):
|
||||
|
||||
@@ -58,7 +58,7 @@ class VirtualBoxBase(BaseModel):
|
||||
|
||||
name: str
|
||||
vmname: str = Field(..., description="VirtualBox VM name (in VirtualBox itself)")
|
||||
node_id: Optional[UUID]
|
||||
node_id: Optional[UUID] = None
|
||||
linked_clone: Optional[bool] = Field(None, description="Whether the VM is a linked clone or not")
|
||||
usage: Optional[str] = Field(None, description="How to use the node")
|
||||
# 36 adapters is the maximum given by the ICH9 chipset in VirtualBox
|
||||
@@ -86,8 +86,8 @@ class VirtualBoxUpdate(VirtualBoxBase):
|
||||
Properties to update a VirtualBox node.
|
||||
"""
|
||||
|
||||
name: Optional[str]
|
||||
vmname: Optional[str]
|
||||
name: Optional[str] = None
|
||||
vmname: Optional[str] = None
|
||||
|
||||
|
||||
class VirtualBox(VirtualBoxBase):
|
||||
|
||||
@@ -64,7 +64,7 @@ class VMwareBase(BaseModel):
|
||||
name: str
|
||||
vmx_path: str = Field(..., description="Path to the vmx file")
|
||||
linked_clone: bool = Field(..., description="Whether the VM is a linked clone or not")
|
||||
node_id: Optional[UUID]
|
||||
node_id: Optional[UUID] = None
|
||||
usage: Optional[str] = Field(None, description="How to use the node")
|
||||
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
|
||||
console_type: Optional[VMwareConsoleType] = Field(None, description="Console type")
|
||||
@@ -90,9 +90,9 @@ class VMwareUpdate(VMwareBase):
|
||||
Properties to update a VMware node.
|
||||
"""
|
||||
|
||||
name: Optional[str]
|
||||
vmx_path: Optional[str]
|
||||
linked_clone: Optional[bool]
|
||||
name: Optional[str] = None
|
||||
vmx_path: Optional[str] = None
|
||||
linked_clone: Optional[bool] = None
|
||||
|
||||
|
||||
class VMware(VMwareBase):
|
||||
|
||||
@@ -37,7 +37,7 @@ class VPCSBase(BaseModel):
|
||||
"""
|
||||
|
||||
name: str
|
||||
node_id: Optional[UUID]
|
||||
node_id: Optional[UUID] = None
|
||||
usage: Optional[str] = Field(None, description="How to use the node")
|
||||
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
|
||||
console_type: Optional[ConsoleType] = Field(None, description="Console type")
|
||||
@@ -57,7 +57,7 @@ class VPCSUpdate(VPCSBase):
|
||||
Properties to update a VPCS node.
|
||||
"""
|
||||
|
||||
name: Optional[str]
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class VPCS(VPCSBase):
|
||||
|
||||
Reference in new issue
Block a user