mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 22:41:12 +02:00
Move schemas between compute and controller subpackages
This commit is contained in:
1 parent
c59fc375f2
commit
9c850e0f2b
57 files changed
+332
-214
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 typing import Optional
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class DateTimeModelMixin(BaseModel):
|
||||
|
||||
created_at: Optional[datetime]
|
||||
updated_at: Optional[datetime]
|
||||
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
from typing import List
|
||||
|
||||
from .nodes import NodeType
|
||||
|
||||
|
||||
class Capabilities(BaseModel):
|
||||
"""
|
||||
Capabilities properties.
|
||||
"""
|
||||
|
||||
version: str = Field(..., description="Compute version number")
|
||||
node_types: List[NodeType] = Field(..., description="Node types supported by the compute")
|
||||
platform: str = Field(..., description="Platform where the compute is running")
|
||||
cpus: int = Field(..., description="Number of CPUs on this compute")
|
||||
memory: int = Field(..., description="Amount of memory on this compute")
|
||||
disk_size: int = Field(..., description="Disk size on this compute")
|
||||
@@ -0,0 +1,139 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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, SecretStr, validator
|
||||
from typing import List, Optional, Union
|
||||
from uuid import UUID, uuid4
|
||||
from enum import Enum
|
||||
|
||||
from .nodes import NodeType
|
||||
from .base import DateTimeModelMixin
|
||||
|
||||
|
||||
class Protocol(str, Enum):
|
||||
"""
|
||||
Protocol supported to communicate with a compute.
|
||||
"""
|
||||
|
||||
http = "http"
|
||||
https = "https"
|
||||
|
||||
|
||||
class ComputeBase(BaseModel):
|
||||
"""
|
||||
Data to create a compute.
|
||||
"""
|
||||
|
||||
protocol: Protocol
|
||||
host: str
|
||||
port: int = Field(..., gt=0, le=65535)
|
||||
user: Optional[str] = None
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class ComputeCreate(ComputeBase):
|
||||
"""
|
||||
Data to create a compute.
|
||||
"""
|
||||
|
||||
compute_id: Union[str, UUID] = Field(default_factory=uuid4)
|
||||
password: Optional[SecretStr] = None
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {"name": "My compute", "host": "127.0.0.1", "port": 3080, "user": "user", "password": "password"}
|
||||
}
|
||||
|
||||
@validator("name", always=True)
|
||||
def generate_name(cls, name, values):
|
||||
|
||||
if name is not None:
|
||||
return name
|
||||
else:
|
||||
protocol = values.get("protocol")
|
||||
host = values.get("host")
|
||||
port = values.get("port")
|
||||
user = values.get("user")
|
||||
if user:
|
||||
# due to random user generated by 1.4 it's common to have a very long user
|
||||
if len(user) > 14:
|
||||
user = user[:11] + "..."
|
||||
return f"{protocol}://{user}@{host}:{port}"
|
||||
else:
|
||||
return f"{protocol}://{host}:{port}"
|
||||
|
||||
|
||||
class ComputeUpdate(ComputeBase):
|
||||
"""
|
||||
Data to update a compute.
|
||||
"""
|
||||
|
||||
protocol: Optional[Protocol] = None
|
||||
host: Optional[str] = None
|
||||
port: Optional[int] = Field(None, gt=0, le=65535)
|
||||
password: Optional[SecretStr] = None
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"host": "10.0.0.1",
|
||||
"port": 8080,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Capabilities(BaseModel):
|
||||
"""
|
||||
Capabilities supported by a compute.
|
||||
"""
|
||||
|
||||
version: str = Field(..., description="Compute version number")
|
||||
node_types: List[NodeType] = Field(..., description="Node types supported by the compute")
|
||||
platform: str = Field(..., description="Platform where the compute is running (Linux, Windows or macOS)")
|
||||
cpus: int = Field(..., description="Number of CPUs on this compute")
|
||||
memory: int = Field(..., description="Amount of memory on this compute")
|
||||
disk_size: int = Field(..., description="Disk size on this compute")
|
||||
|
||||
|
||||
class Compute(DateTimeModelMixin, ComputeBase):
|
||||
"""
|
||||
Data returned for a compute.
|
||||
"""
|
||||
|
||||
compute_id: Union[str, UUID]
|
||||
name: str
|
||||
connected: Optional[bool] = Field(None, description="Whether the controller is connected to the compute or not")
|
||||
cpu_usage_percent: Optional[float] = Field(None, description="CPU usage of the compute", ge=0, le=100)
|
||||
memory_usage_percent: Optional[float] = Field(None, description="Memory usage of the compute", ge=0, le=100)
|
||||
disk_usage_percent: Optional[float] = Field(None, description="Disk usage of the compute", ge=0, le=100)
|
||||
last_error: Optional[str] = Field(None, description="Last error found on the compute")
|
||||
capabilities: Optional[Capabilities] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class AutoIdlePC(BaseModel):
|
||||
"""
|
||||
Data for auto Idle-PC request.
|
||||
"""
|
||||
|
||||
platform: str = Field(..., description="Cisco platform")
|
||||
image: str = Field(..., description="Image path")
|
||||
ram: int = Field(..., description="Amount of RAM in MB")
|
||||
|
||||
class Config:
|
||||
schema_extra = {"example": {"platform": "c7200", "image": "/path/to/c7200_image.bin", "ram": 256}}
|
||||
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
class Drawing(BaseModel):
|
||||
"""
|
||||
Drawing data.
|
||||
"""
|
||||
|
||||
drawing_id: Optional[UUID] = None
|
||||
project_id: Optional[UUID] = None
|
||||
x: Optional[int] = None
|
||||
y: Optional[int] = None
|
||||
z: Optional[int] = None
|
||||
locked: Optional[bool] = None
|
||||
rotation: Optional[int] = Field(None, ge=-359, le=360)
|
||||
svg: Optional[str] = None
|
||||
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
from typing import Optional
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class WhenExit(str, Enum):
|
||||
"""
|
||||
What to do with the VM when GNS3 VM exits.
|
||||
"""
|
||||
|
||||
stop = "stop"
|
||||
suspend = "suspend"
|
||||
keep = "keep"
|
||||
|
||||
|
||||
class Engine(str, Enum):
|
||||
"""
|
||||
"The engine to use for the GNS3 VM.
|
||||
"""
|
||||
|
||||
vmware = "vmware"
|
||||
virtualbox = "virtualbox"
|
||||
hyperv = "hyper-v"
|
||||
none = "none"
|
||||
|
||||
|
||||
class GNS3VM(BaseModel):
|
||||
"""
|
||||
GNS3 VM data.
|
||||
"""
|
||||
|
||||
enable: Optional[bool] = Field(None, description="Enable/disable the GNS3 VM")
|
||||
vmname: Optional[str] = Field(None, description="GNS3 VM name")
|
||||
when_exit: Optional[WhenExit] = Field(None, description="Action when the GNS3 VM exits")
|
||||
headless: Optional[bool] = Field(None, description="Start the GNS3 VM GUI or not")
|
||||
engine: Optional[Engine] = Field(None, description="The engine to use for the GNS3 VM")
|
||||
allocate_vcpus_ram: Optional[bool] = Field(None, description="Allocate vCPUS and RAM settings")
|
||||
vcpus: Optional[int] = Field(None, description="Number of CPUs to allocate for the GNS3 VM")
|
||||
ram: Optional[int] = Field(None, description="Amount of memory to allocate for the GNS3 VM")
|
||||
port: Optional[int] = Field(None, gt=0, le=65535)
|
||||
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# Copyright (C) 2018 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
class IOULicense(BaseModel):
|
||||
|
||||
iourc_content: str = Field(..., description="Content of iourc file")
|
||||
license_check: bool = Field(..., description="Whether the license must be checked or not")
|
||||
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# Copyright (C) 2021 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
from typing import Optional, Union
|
||||
|
||||
|
||||
class Label(BaseModel):
|
||||
"""
|
||||
Label data.
|
||||
"""
|
||||
|
||||
text: str
|
||||
style: Optional[Union[str, None]] = Field(None, description="SVG style attribute. Apply default style if null")
|
||||
x: Optional[Union[int, None]] = Field(None, description="Relative X position of the label. Center it if null")
|
||||
y: Optional[int] = Field(None, description="Relative Y position of the label")
|
||||
rotation: Optional[int] = Field(None, ge=-359, le=360, description="Rotation of the label")
|
||||
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
from typing import List, Optional
|
||||
from enum import Enum
|
||||
from uuid import UUID
|
||||
|
||||
from .labels import Label
|
||||
|
||||
|
||||
class LinkNode(BaseModel):
|
||||
"""
|
||||
Link node data.
|
||||
"""
|
||||
|
||||
node_id: UUID
|
||||
adapter_number: int
|
||||
port_number: int
|
||||
label: Optional[Label]
|
||||
|
||||
|
||||
class LinkType(str, Enum):
|
||||
"""
|
||||
Link type.
|
||||
"""
|
||||
|
||||
ethernet = "ethernet"
|
||||
serial = "serial"
|
||||
|
||||
|
||||
class Link(BaseModel):
|
||||
"""
|
||||
Link data.
|
||||
"""
|
||||
|
||||
link_id: Optional[UUID] = None
|
||||
project_id: Optional[UUID] = None
|
||||
nodes: Optional[List[LinkNode]] = None
|
||||
suspend: Optional[bool] = None
|
||||
filters: Optional[dict] = None
|
||||
capturing: Optional[bool] = Field(None, description="Read only property. True if a capture running on the link")
|
||||
capture_file_name: Optional[str] = Field(
|
||||
None, description="Read only property. The name of the capture file if a capture is running"
|
||||
)
|
||||
capture_file_path: Optional[str] = Field(
|
||||
None, description="Read only property. The full path of the capture file if a capture is running"
|
||||
)
|
||||
capture_compute_id: Optional[str] = Field(
|
||||
None, description="Read only property. The compute identifier where a capture is running"
|
||||
)
|
||||
link_type: Optional[LinkType] = None
|
||||
@@ -0,0 +1,193 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 typing import List, Optional, Union
|
||||
from enum import Enum
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from .labels import Label
|
||||
from ..common import ConsoleType, NodeStatus, CustomAdapter
|
||||
|
||||
|
||||
class NodeType(str, Enum):
|
||||
"""
|
||||
Supported node types.
|
||||
"""
|
||||
|
||||
cloud = "cloud"
|
||||
nat = "nat"
|
||||
ethernet_hub = "ethernet_hub"
|
||||
ethernet_switch = "ethernet_switch"
|
||||
frame_relay_switch = "frame_relay_switch"
|
||||
atm_switch = "atm_switch"
|
||||
docker = "docker"
|
||||
dynamips = "dynamips"
|
||||
vpcs = "vpcs"
|
||||
virtualbox = "virtualbox"
|
||||
vmware = "vmware"
|
||||
iou = "iou"
|
||||
qemu = "qemu"
|
||||
|
||||
|
||||
class Image(BaseModel):
|
||||
"""
|
||||
Image data.
|
||||
"""
|
||||
|
||||
filename: str
|
||||
path: str
|
||||
md5sum: Optional[str] = None
|
||||
filesize: Optional[int] = None
|
||||
|
||||
|
||||
class LinkType(str, Enum):
|
||||
"""
|
||||
Supported link types.
|
||||
"""
|
||||
|
||||
ethernet = "ethernet"
|
||||
serial = "serial"
|
||||
|
||||
|
||||
class DataLinkType(str, Enum):
|
||||
"""
|
||||
Supported data link types.
|
||||
"""
|
||||
|
||||
atm = "DLT_ATM_RFC1483"
|
||||
ethernet = "DLT_EN10MB"
|
||||
frame_relay = "DLT_FRELAY"
|
||||
cisco_hdlc = "DLT_C_HDLC"
|
||||
ppp = "DLT_PPP_SERIAL"
|
||||
|
||||
|
||||
class NodeCapture(BaseModel):
|
||||
"""
|
||||
Node capture data.
|
||||
"""
|
||||
|
||||
capture_file_name: str
|
||||
data_link_type: Optional[DataLinkType] = None
|
||||
|
||||
|
||||
class NodePort(BaseModel):
|
||||
"""
|
||||
Node port data.
|
||||
"""
|
||||
|
||||
name: str = Field(..., description="Port name")
|
||||
short_name: str = Field(..., description="Port name")
|
||||
adapter_number: int = Field(..., description="Adapter slot")
|
||||
adapter_type: Optional[str] = Field(None, description="Adapter type")
|
||||
port_number: int = Field(..., description="Port slot")
|
||||
link_type: LinkType = Field(..., description="Type of link")
|
||||
data_link_types: dict = Field(..., description="Available PCAP types for capture")
|
||||
mac_address: Union[str, None] = Field(None, regex="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$")
|
||||
|
||||
|
||||
class NodeBase(BaseModel):
|
||||
"""
|
||||
Node data.
|
||||
"""
|
||||
|
||||
compute_id: Union[UUID, str]
|
||||
name: str
|
||||
node_type: NodeType
|
||||
|
||||
node_id: Optional[UUID] = None
|
||||
|
||||
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
|
||||
|
||||
console_type: Optional[ConsoleType] = None
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
aux: Optional[int] = Field(None, gt=0, le=65535, description="Auxiliary console TCP port")
|
||||
aux_type: Optional[ConsoleType]
|
||||
properties: Optional[dict] = Field(default_factory=dict, description="Properties specific to an emulator")
|
||||
|
||||
label: Optional[Label] = None
|
||||
symbol: Optional[str] = None
|
||||
|
||||
x: Optional[int] = 0
|
||||
y: Optional[int] = 0
|
||||
z: Optional[int] = 1
|
||||
locked: Optional[bool] = Field(False, description="Whether the element locked or not")
|
||||
port_name_format: Optional[str] = Field(
|
||||
None, descript_port_name_formation="Formatting for port name {0} will be replace by port number"
|
||||
)
|
||||
port_segment_size: Optional[int] = Field(None, description="Size of the port segment")
|
||||
first_port_name: Optional[str] = Field(None, description="Name of the first port")
|
||||
custom_adapters: Optional[List[CustomAdapter]] = None
|
||||
|
||||
@validator("port_name_format", pre=True, always=True)
|
||||
def default_port_name_format(cls, v, values):
|
||||
if v is None:
|
||||
if "node_type" in values and values["node_type"] == NodeType.iou:
|
||||
return "Ethernet{segment0}/{port0}"
|
||||
return "Ethernet{0}"
|
||||
return v
|
||||
|
||||
@validator("port_segment_size", pre=True, always=True)
|
||||
def default_port_segment_size(cls, v, values):
|
||||
if v is None:
|
||||
if "node_type" in values and values["node_type"] == NodeType.iou:
|
||||
return 4
|
||||
return 0
|
||||
return v
|
||||
|
||||
|
||||
class NodeCreate(NodeBase):
|
||||
|
||||
node_id: UUID = Field(default_factory=uuid4)
|
||||
|
||||
|
||||
class NodeUpdate(NodeBase):
|
||||
"""
|
||||
Data to update a node.
|
||||
"""
|
||||
|
||||
compute_id: Optional[Union[UUID, str]] = None
|
||||
name: Optional[str] = None
|
||||
node_type: Optional[NodeType] = None
|
||||
|
||||
|
||||
class Node(NodeBase):
|
||||
|
||||
template_id: Optional[UUID] = Field(None,
|
||||
description="Template UUID from which the node has been created. Read only")
|
||||
project_id: Optional[UUID] = None
|
||||
node_directory: Optional[str] = Field(None, description="Working directory of the node. Read only")
|
||||
status: Optional[NodeStatus] = Field(None, description="Node status. Read only")
|
||||
command_line: Optional[str] = Field(None, description="Command line use to start the node. Read only")
|
||||
width: Optional[int] = Field(None, description="Width of the node. Read only")
|
||||
height: Optional[int] = Field(None, description="Height of the node. Read only")
|
||||
ports: Optional[List[NodePort]] = Field(None, description="List of node ports. Read only")
|
||||
console_host: Optional[str] = Field(
|
||||
None,
|
||||
description="Console host. Warning if the host is 0.0.0.0 or :: (listen on all interfaces) you need to use the same address you use to connect to the controller",
|
||||
)
|
||||
|
||||
|
||||
class NodeDuplicate(BaseModel):
|
||||
"""
|
||||
Data to duplicate a node.
|
||||
"""
|
||||
|
||||
x: int
|
||||
y: int
|
||||
z: Optional[int] = 0
|
||||
@@ -0,0 +1,104 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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, HttpUrl
|
||||
from typing import List, Optional
|
||||
from uuid import UUID
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ProjectStatus(str, Enum):
|
||||
"""
|
||||
Supported project statuses.
|
||||
"""
|
||||
|
||||
opened = "opened"
|
||||
closed = "closed"
|
||||
|
||||
|
||||
class Supplier(BaseModel):
|
||||
|
||||
logo: str = Field(..., description="Path to the project supplier logo")
|
||||
url: Optional[HttpUrl] = Field(None, description="URL to the project supplier site")
|
||||
|
||||
|
||||
class Variable(BaseModel):
|
||||
|
||||
name: str = Field(..., description="Variable name")
|
||||
value: Optional[str] = Field(None, description="Variable value")
|
||||
|
||||
|
||||
class ProjectBase(BaseModel):
|
||||
"""
|
||||
Common properties for projects.
|
||||
"""
|
||||
|
||||
name: str
|
||||
project_id: Optional[UUID] = None
|
||||
path: Optional[str] = Field(None, description="Project directory")
|
||||
auto_close: Optional[bool] = Field(None, description="Close project when last client leaves")
|
||||
auto_open: Optional[bool] = Field(None, description="Project opens when GNS3 starts")
|
||||
auto_start: Optional[bool] = Field(None, description="Project starts when opened")
|
||||
scene_height: Optional[int] = Field(None, description="Height of the drawing area")
|
||||
scene_width: Optional[int] = Field(None, description="Width of the drawing area")
|
||||
zoom: Optional[int] = Field(None, description="Zoom of the drawing area")
|
||||
show_layers: Optional[bool] = Field(None, description="Show layers on the drawing area")
|
||||
snap_to_grid: Optional[bool] = Field(None, description="Snap to grid on the drawing area")
|
||||
show_grid: Optional[bool] = Field(None, description="Show the grid on the drawing area")
|
||||
grid_size: Optional[int] = Field(None, description="Grid size for the drawing area for nodes")
|
||||
drawing_grid_size: Optional[int] = Field(None, description="Grid size for the drawing area for drawings")
|
||||
show_interface_labels: Optional[bool] = Field(None, description="Show interface labels on the drawing area")
|
||||
supplier: Optional[Supplier] = Field(None, description="Supplier of the project")
|
||||
variables: Optional[List[Variable]] = Field(None, description="Variables required to run the project")
|
||||
|
||||
|
||||
class ProjectCreate(ProjectBase):
|
||||
"""
|
||||
Properties for project creation.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ProjectDuplicate(ProjectBase):
|
||||
"""
|
||||
Properties for project duplication.
|
||||
"""
|
||||
|
||||
reset_mac_addresses: Optional[bool] = Field(False, description="Reset MAC addresses for this project")
|
||||
|
||||
|
||||
class ProjectUpdate(ProjectBase):
|
||||
"""
|
||||
Properties for project update.
|
||||
"""
|
||||
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class Project(ProjectBase):
|
||||
|
||||
project_id: UUID
|
||||
name: Optional[str] = None
|
||||
status: Optional[ProjectStatus] = None
|
||||
filename: Optional[str] = None
|
||||
|
||||
|
||||
class ProjectFile(BaseModel):
|
||||
|
||||
path: str = Field(..., description="File path")
|
||||
md5sum: str = Field(..., description="File checksum")
|
||||
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
class SnapshotBase(BaseModel):
|
||||
"""
|
||||
Common properties for snapshot.
|
||||
"""
|
||||
|
||||
name: str
|
||||
|
||||
|
||||
class SnapshotCreate(SnapshotBase):
|
||||
"""
|
||||
Properties for snapshot creation.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class Snapshot(SnapshotBase):
|
||||
|
||||
snapshot_id: UUID
|
||||
project_id: UUID
|
||||
created_at: int = Field(..., description="Date of the snapshot (UTC timestamp)")
|
||||
@@ -0,0 +1,90 @@
|
||||
#
|
||||
# Copyright (C) 2021 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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
|
||||
from typing import Optional, Union
|
||||
from enum import Enum
|
||||
from uuid import UUID
|
||||
|
||||
from ..nodes import NodeType
|
||||
from ..base import DateTimeModelMixin
|
||||
|
||||
|
||||
class Category(str, Enum):
|
||||
"""
|
||||
Supported categories
|
||||
"""
|
||||
|
||||
router = "router"
|
||||
switch = "switch"
|
||||
guest = "guest"
|
||||
firewall = "firewall"
|
||||
|
||||
|
||||
class TemplateBase(BaseModel):
|
||||
"""
|
||||
Common template properties.
|
||||
"""
|
||||
|
||||
template_id: Optional[UUID] = None
|
||||
name: Optional[str] = None
|
||||
category: Optional[Category] = None
|
||||
default_name_format: Optional[str] = None
|
||||
symbol: Optional[str] = None
|
||||
builtin: Optional[bool] = None
|
||||
template_type: Optional[NodeType] = None
|
||||
compute_id: Optional[str] = None
|
||||
usage: Optional[str] = ""
|
||||
|
||||
class Config:
|
||||
extra = "allow"
|
||||
|
||||
|
||||
class TemplateCreate(TemplateBase):
|
||||
"""
|
||||
Properties to create a template.
|
||||
"""
|
||||
|
||||
name: str
|
||||
template_type: NodeType
|
||||
compute_id: str
|
||||
|
||||
|
||||
class TemplateUpdate(TemplateBase):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class Template(DateTimeModelMixin, TemplateBase):
|
||||
|
||||
template_id: UUID
|
||||
name: str
|
||||
category: Category
|
||||
symbol: str
|
||||
builtin: bool
|
||||
template_type: NodeType
|
||||
compute_id: Union[str, None]
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class TemplateUsage(BaseModel):
|
||||
|
||||
x: int
|
||||
y: int
|
||||
name: Optional[str] = Field(None, description="Use this name to create a new node")
|
||||
compute_id: Optional[str] = Field(None, description="Used if the template doesn't have a default compute")
|
||||
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.cloud_nodes import (
|
||||
EthernetPort,
|
||||
TAPPort,
|
||||
UDPPort,
|
||||
CloudConsoleType
|
||||
)
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional, Union, List
|
||||
|
||||
|
||||
class CloudTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "guest"
|
||||
default_name_format: Optional[str] = "Cloud{0}"
|
||||
symbol: Optional[str] = ":/symbols/cloud.svg"
|
||||
ports_mapping: List[Union[EthernetPort, TAPPort, UDPPort]] = Field(default_factory=list)
|
||||
remote_console_host: Optional[str] = Field("127.0.0.1", description="Remote console host or IP")
|
||||
remote_console_port: Optional[int] = Field(23, gt=0, le=65535, description="Remote console TCP port")
|
||||
remote_console_type: Optional[CloudConsoleType] = Field("none", description="Remote console type")
|
||||
remote_console_http_path: Optional[str] = Field("/", description="Path of the remote web interface")
|
||||
@@ -0,0 +1,53 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from ...common import ConsoleType, AuxType, CustomAdapter
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class DockerTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "guest"
|
||||
default_name_format: Optional[str] = "{name}-{0}"
|
||||
symbol: Optional[str] = ":/symbols/docker_guest.svg"
|
||||
image: str = Field(..., description="Docker image name")
|
||||
adapters: Optional[int] = Field(1, ge=0, le=100, description="Number of adapters")
|
||||
start_command: Optional[str] = Field("", description="Docker CMD entry")
|
||||
environment: Optional[str] = Field("", description="Docker environment variables")
|
||||
console_type: Optional[ConsoleType] = Field("telnet", description="Console type")
|
||||
aux_type: Optional[AuxType] = Field("none", description="Auxiliary console type")
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
console_http_port: Optional[int] = Field(
|
||||
80, gt=0, le=65535, description="Internal port in the container for the HTTP server"
|
||||
)
|
||||
console_http_path: Optional[str] = Field(
|
||||
"/",
|
||||
description="Path of the web interface",
|
||||
)
|
||||
console_resolution: Optional[str] = Field(
|
||||
"1024x768", regex="^[0-9]+x[0-9]+$", description="Console resolution for VNC"
|
||||
)
|
||||
extra_hosts: Optional[str] = Field("", description="Docker extra hosts (added to /etc/hosts)")
|
||||
extra_volumes: Optional[List] = Field([], description="Additional directories to make persistent")
|
||||
memory: Optional[int] = Field(0, description="Maximum amount of memory the container can use in MB")
|
||||
cpus: Optional[int] = Field(0, description="Maximum amount of CPU resources the container can use")
|
||||
custom_adapters: Optional[List[CustomAdapter]] = Field(default_factory=list, description="Custom adapters")
|
||||
@@ -0,0 +1,157 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
|
||||
from gns3server.schemas.compute.dynamips_nodes import (
|
||||
DynamipsConsoleType,
|
||||
DynamipsPlatform,
|
||||
DynamipsAdapters,
|
||||
DynamipsWics,
|
||||
DynamipsNPE,
|
||||
DynamipsMidplane,
|
||||
)
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class DynamipsTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "router"
|
||||
default_name_format: Optional[str] = "R{0}"
|
||||
symbol: Optional[str] = ":/symbols/router.svg"
|
||||
platform: DynamipsPlatform = Field(..., description="Cisco router platform")
|
||||
image: str = Field(..., description="Path to the IOS image")
|
||||
exec_area: Optional[int] = Field(64, description="Exec area value")
|
||||
mmap: Optional[bool] = Field(True, description="MMAP feature")
|
||||
mac_addr: Optional[str] = Field(
|
||||
"", description="Base MAC address", regex="^([0-9a-fA-F]{4}\\.){2}[0-9a-fA-F]{4}$|^$"
|
||||
)
|
||||
system_id: Optional[str] = Field("FTX0945W0MY", description="System ID")
|
||||
startup_config: Optional[str] = Field("ios_base_startup-config.txt", description="IOS startup configuration file")
|
||||
private_config: Optional[str] = Field("", description="IOS private configuration file")
|
||||
idlepc: Optional[str] = Field("", description="Idle-PC value", regex="^(0x[0-9a-fA-F]+)?$|^$")
|
||||
idlemax: Optional[int] = Field(500, description="Idlemax value")
|
||||
idlesleep: Optional[int] = Field(30, description="Idlesleep value")
|
||||
disk0: Optional[int] = Field(0, description="Disk0 size in MB")
|
||||
disk1: Optional[int] = Field(0, description="Disk1 size in MB")
|
||||
auto_delete_disks: Optional[bool] = Field(False, description="Automatically delete nvram and disk files")
|
||||
console_type: Optional[DynamipsConsoleType] = Field("telnet", description="Console type")
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
aux_type: Optional[DynamipsConsoleType] = Field("none", description="Auxiliary console type")
|
||||
slot0: Optional[DynamipsAdapters] = Field(None, description="Network module slot 0")
|
||||
slot1: Optional[DynamipsAdapters] = Field(None, description="Network module slot 1")
|
||||
slot2: Optional[DynamipsAdapters] = Field(None, description="Network module slot 2")
|
||||
slot3: Optional[DynamipsAdapters] = Field(None, description="Network module slot 3")
|
||||
slot4: Optional[DynamipsAdapters] = Field(None, description="Network module slot 4")
|
||||
slot5: Optional[DynamipsAdapters] = Field(None, description="Network module slot 5")
|
||||
slot6: Optional[DynamipsAdapters] = Field(None, description="Network module slot 6")
|
||||
wic0: Optional[DynamipsWics] = Field(None, description="Network module WIC slot 0")
|
||||
wic1: Optional[DynamipsWics] = Field(None, description="Network module WIC slot 1")
|
||||
wic2: Optional[DynamipsWics] = Field(None, description="Network module WIC slot 2")
|
||||
|
||||
|
||||
class C7200DynamipsTemplate(DynamipsTemplate):
|
||||
|
||||
ram: Optional[int] = Field(512, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(512, description="Amount of NVRAM in KB")
|
||||
npe: Optional[DynamipsNPE] = Field("npe-400", description="NPE model")
|
||||
midplane: Optional[DynamipsMidplane] = Field("vxr", description="Midplane model")
|
||||
sparsemem: Optional[bool] = Field(True, description="Sparse memory feature")
|
||||
|
||||
|
||||
class C3725DynamipsTemplate(DynamipsTemplate):
|
||||
|
||||
ram: Optional[int] = Field(128, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(256, description="Amount of NVRAM in KB")
|
||||
iomem: Optional[int] = Field(5, ge=0, le=100, description="I/O memory percentage")
|
||||
sparsemem: Optional[bool] = Field(True, description="Sparse memory feature")
|
||||
|
||||
|
||||
class C3745DynamipsTemplate(DynamipsTemplate):
|
||||
|
||||
ram: Optional[int] = Field(256, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(256, description="Amount of NVRAM in KB")
|
||||
iomem: Optional[int] = Field(5, ge=0, le=100, description="I/O memory percentage")
|
||||
sparsemem: Optional[bool] = Field(True, description="Sparse memory feature")
|
||||
|
||||
|
||||
class C3600ChassisType(str, Enum):
|
||||
|
||||
chassis_3620 = "3620"
|
||||
chassis_3640 = "3640"
|
||||
chassis_3660 = "3660"
|
||||
|
||||
|
||||
class C3600DynamipsTemplate(DynamipsTemplate):
|
||||
|
||||
chassis: Optional[C3600ChassisType] = Field("c3660", description="Chassis type")
|
||||
ram: Optional[int] = Field(192, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(128, description="Amount of NVRAM in KB")
|
||||
iomem: Optional[int] = Field(5, ge=0, le=100, description="I/O memory percentage")
|
||||
sparsemem: Optional[bool] = Field(True, description="Sparse memory feature")
|
||||
|
||||
|
||||
class C2691DynamipsTemplate(DynamipsTemplate):
|
||||
|
||||
ram: Optional[int] = Field(192, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(256, description="Amount of NVRAM in KB")
|
||||
iomem: Optional[int] = Field(5, ge=0, le=100, description="I/O memory percentage")
|
||||
sparsemem: Optional[bool] = Field(True, description="Sparse memory feature")
|
||||
|
||||
|
||||
class C2600ChassisType(str, Enum):
|
||||
|
||||
chassis_2610 = "2610"
|
||||
chassis_2620 = "2620"
|
||||
chassis_2610xm = "2610XM"
|
||||
chassis_2620xm = "2620XM"
|
||||
chassis_2650xm = "2650XM"
|
||||
chassis_2621 = "2621"
|
||||
chassis_2611xm = "2611XM"
|
||||
chassis_2621xm = "2621XM"
|
||||
chassis_2651xm = "2651XM"
|
||||
|
||||
|
||||
class C2600DynamipsTemplate(DynamipsTemplate):
|
||||
|
||||
chassis: Optional[C2600ChassisType] = Field("2651XM", description="Chassis type")
|
||||
ram: Optional[int] = Field(160, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(128, description="Amount of NVRAM in KB")
|
||||
iomem: Optional[int] = Field(15, ge=0, le=100, description="I/O memory percentage")
|
||||
sparsemem: Optional[bool] = Field(True, description="Sparse memory feature")
|
||||
|
||||
|
||||
class C1700ChassisType(str, Enum):
|
||||
|
||||
chassis_1720 = "1720"
|
||||
chassis_1721 = "1721"
|
||||
chassis_1750 = "1750"
|
||||
chassis_1751 = "1751"
|
||||
chassis_1760 = "1760"
|
||||
|
||||
|
||||
class C1700DynamipsTemplate(DynamipsTemplate):
|
||||
|
||||
chassis: Optional[C1700ChassisType] = Field("1760", description="Chassis type")
|
||||
ram: Optional[int] = Field(160, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(128, description="Amount of NVRAM in KB")
|
||||
iomem: Optional[int] = Field(15, ge=0, le=100, description="I/O memory percentage")
|
||||
sparsemem: Optional[bool] = Field(False, description="Sparse memory feature")
|
||||
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.ethernet_hub_nodes import EthernetHubPort
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
DEFAULT_PORTS = [
|
||||
dict(port_number=0, name="Ethernet0"),
|
||||
dict(port_number=1, name="Ethernet1"),
|
||||
dict(port_number=2, name="Ethernet2"),
|
||||
dict(port_number=3, name="Ethernet3"),
|
||||
dict(port_number=4, name="Ethernet4"),
|
||||
dict(port_number=5, name="Ethernet5"),
|
||||
dict(port_number=6, name="Ethernet6"),
|
||||
dict(port_number=7, name="Ethernet7"),
|
||||
]
|
||||
|
||||
|
||||
class EthernetHubTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "switch"
|
||||
default_name_format: Optional[str] = "Hub{0}"
|
||||
symbol: Optional[str] = ":/symbols/hub.svg"
|
||||
ports_mapping: Optional[List[EthernetHubPort]] = Field(DEFAULT_PORTS, description="Ports")
|
||||
@@ -0,0 +1,52 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.ethernet_switch_nodes import EthernetSwitchPort
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional, List
|
||||
from enum import Enum
|
||||
|
||||
DEFAULT_PORTS = [
|
||||
dict(port_number=0, name="Ethernet0", vlan=1, type="access", ethertype="0x8100"),
|
||||
dict(port_number=1, name="Ethernet1", vlan=1, type="access", ethertype="0x8100"),
|
||||
dict(port_number=2, name="Ethernet2", vlan=1, type="access", ethertype="0x8100"),
|
||||
dict(port_number=3, name="Ethernet3", vlan=1, type="access", ethertype="0x8100"),
|
||||
dict(port_number=4, name="Ethernet4", vlan=1, type="access", ethertype="0x8100"),
|
||||
dict(port_number=5, name="Ethernet5", vlan=1, type="access", ethertype="0x8100"),
|
||||
dict(port_number=6, name="Ethernet6", vlan=1, type="access", ethertype="0x8100"),
|
||||
dict(port_number=7, name="Ethernet7", vlan=1, type="access", ethertype="0x8100"),
|
||||
]
|
||||
|
||||
|
||||
class ConsoleType(str, Enum):
|
||||
"""
|
||||
Supported console types for Ethernet switch nodes.
|
||||
"""
|
||||
|
||||
none = "none"
|
||||
telnet = "telnet"
|
||||
|
||||
|
||||
class EthernetSwitchTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "switch"
|
||||
default_name_format: Optional[str] = "Switch{0}"
|
||||
symbol: Optional[str] = ":/symbols/ethernet_switch.svg"
|
||||
ports_mapping: Optional[List[EthernetSwitchPort]] = Field(DEFAULT_PORTS, description="Ports")
|
||||
console_type: Optional[ConsoleType] = Field("none", description="Console type")
|
||||
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.iou_nodes import ConsoleType
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class IOUTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "router"
|
||||
default_name_format: Optional[str] = "IOU{0}"
|
||||
symbol: Optional[str] = ":/symbols/multilayer_switch.svg"
|
||||
path: str = Field(..., description="Path of IOU executable")
|
||||
ethernet_adapters: Optional[int] = Field(2, description="Number of ethernet adapters")
|
||||
serial_adapters: Optional[int] = Field(2, description="Number of serial adapters")
|
||||
ram: Optional[int] = Field(256, description="Amount of RAM in MB")
|
||||
nvram: Optional[int] = Field(128, description="Amount of NVRAM in KB")
|
||||
use_default_iou_values: Optional[bool] = Field(True, description="Use default IOU values")
|
||||
startup_config: Optional[str] = Field("iou_l3_base_startup-config.txt", description="Startup-config of IOU")
|
||||
private_config: Optional[str] = Field("", description="Private-config of IOU")
|
||||
l1_keepalives: Optional[bool] = Field(False, description="Always keep up Ethernet interface (does not always work)")
|
||||
console_type: Optional[ConsoleType] = Field("telnet", description="Console type")
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
@@ -0,0 +1,88 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.qemu_nodes import (
|
||||
QemuConsoleType,
|
||||
QemuPlatform,
|
||||
QemuAdapterType,
|
||||
QemuOnCloseAction,
|
||||
QemuBootPriority,
|
||||
QemuDiskInterfaceType,
|
||||
QemuProcessPriority,
|
||||
CustomAdapter,
|
||||
)
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class QemuTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "guest"
|
||||
default_name_format: Optional[str] = "{name}-{0}"
|
||||
symbol: Optional[str] = ":/symbols/qemu_guest.svg"
|
||||
qemu_path: Optional[str] = Field("", description="Qemu executable path")
|
||||
platform: Optional[QemuPlatform] = Field("i386", description="Platform to emulate")
|
||||
linked_clone: Optional[bool] = Field(True, description="Whether the VM is a linked clone or not")
|
||||
ram: Optional[int] = Field(256, description="Amount of RAM in MB")
|
||||
cpus: Optional[int] = Field(1, ge=1, le=255, description="Number of vCPUs")
|
||||
maxcpus: Optional[int] = Field(1, ge=1, le=255, description="Maximum number of hotpluggable vCPUs")
|
||||
adapters: Optional[int] = Field(1, ge=0, le=275, description="Number of adapters")
|
||||
adapter_type: Optional[QemuAdapterType] = Field("e1000", description="QEMU adapter type")
|
||||
mac_address: Optional[str] = Field(
|
||||
"", description="QEMU MAC address", regex="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$|^$"
|
||||
)
|
||||
first_port_name: Optional[str] = Field("", description="Optional name of the first networking port example: eth0")
|
||||
port_name_format: Optional[str] = Field(
|
||||
"Ethernet{0}", description="Optional formatting of the networking port example: eth{0}"
|
||||
)
|
||||
port_segment_size: Optional[int] = Field(
|
||||
0,
|
||||
description="Optional port segment size. A port segment is a block of port. For example Ethernet0/0 Ethernet0/1 is the module 0 with a port segment size of 2",
|
||||
)
|
||||
console_type: Optional[QemuConsoleType] = Field("telnet", description="Console type")
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
aux_type: Optional[QemuConsoleType] = Field("none", description="Auxiliary console type")
|
||||
boot_priority: Optional[QemuBootPriority] = Field("c", description="QEMU boot priority")
|
||||
hda_disk_image: Optional[str] = Field("", description="QEMU hda disk image path")
|
||||
hda_disk_interface: Optional[QemuDiskInterfaceType] = Field("none", description="QEMU hda interface")
|
||||
hdb_disk_image: Optional[str] = Field("", description="QEMU hdb disk image path")
|
||||
hdb_disk_interface: Optional[QemuDiskInterfaceType] = Field("none", description="QEMU hdb interface")
|
||||
hdc_disk_image: Optional[str] = Field("", description="QEMU hdc disk image path")
|
||||
hdc_disk_interface: Optional[QemuDiskInterfaceType] = Field("none", description="QEMU hdc interface")
|
||||
hdd_disk_image: Optional[str] = Field("", description="QEMU hdd disk image path")
|
||||
hdd_disk_interface: Optional[QemuDiskInterfaceType] = Field("none", description="QEMU hdd interface")
|
||||
cdrom_image: Optional[str] = Field("", description="QEMU cdrom image path")
|
||||
initrd: Optional[str] = Field("", description="QEMU initrd path")
|
||||
kernel_image: Optional[str] = Field("", description="QEMU kernel image path")
|
||||
bios_image: Optional[str] = Field("", description="QEMU bios image path")
|
||||
kernel_command_line: Optional[str] = Field("", description="QEMU kernel command line")
|
||||
legacy_networking: Optional[bool] = Field(False, description="Use QEMU legagy networking commands (-net syntax)")
|
||||
replicate_network_connection_state: Optional[bool] = Field(
|
||||
True, description="Replicate the network connection state for links in Qemu"
|
||||
)
|
||||
create_config_disk: Optional[bool] = Field(
|
||||
False, description="Automatically create a config disk on HDD disk interface (secondary slave)"
|
||||
)
|
||||
on_close: Optional[QemuOnCloseAction] = Field("power_off", description="Action to execute on the VM is closed")
|
||||
cpu_throttling: Optional[int] = Field(0, ge=0, le=800, description="Percentage of CPU allowed for QEMU")
|
||||
process_priority: Optional[QemuProcessPriority] = Field("normal", description="Process priority for QEMU")
|
||||
options: Optional[str] = Field("", description="Additional QEMU options")
|
||||
custom_adapters: Optional[List[CustomAdapter]] = Field(default_factory=list, description="Custom adapters")
|
||||
@@ -0,0 +1,60 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.virtualbox_nodes import (
|
||||
VirtualBoxConsoleType,
|
||||
VirtualBoxAdapterType,
|
||||
VirtualBoxOnCloseAction,
|
||||
CustomAdapter
|
||||
)
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class VirtualBoxTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "guest"
|
||||
default_name_format: Optional[str] = "{name}-{0}"
|
||||
symbol: Optional[str] = ":/symbols/vbox_guest.svg"
|
||||
vmname: str = Field(..., description="VirtualBox VM name (in VirtualBox itself)")
|
||||
ram: Optional[int] = Field(256, gt=0, description="Amount of RAM in MB")
|
||||
linked_clone: Optional[bool] = Field(False, description="Whether the VM is a linked clone or not")
|
||||
adapters: Optional[int] = Field(
|
||||
1, ge=0, le=36, description="Number of adapters"
|
||||
) # 36 is the maximum given by the ICH9 chipset in VirtualBox
|
||||
use_any_adapter: Optional[bool] = Field(False, description="Allow GNS3 to use any VirtualBox adapter")
|
||||
adapter_type: Optional[VirtualBoxAdapterType] = Field(
|
||||
"Intel PRO/1000 MT Desktop (82540EM)", description="VirtualBox adapter type"
|
||||
)
|
||||
first_port_name: Optional[str] = Field("", description="Optional name of the first networking port example: eth0")
|
||||
port_name_format: Optional[str] = Field(
|
||||
"Ethernet{0}", description="Optional formatting of the networking port example: eth{0}"
|
||||
)
|
||||
port_segment_size: Optional[int] = Field(
|
||||
0,
|
||||
description="Optional port segment size. A port segment is a block of port. For example Ethernet0/0 Ethernet0/1 is the module 0 with a port segment size of 2",
|
||||
)
|
||||
headless: Optional[bool] = Field(False, description="Headless mode")
|
||||
on_close: Optional[VirtualBoxOnCloseAction] = Field(
|
||||
"power_off", description="Action to execute on the VM is closed"
|
||||
)
|
||||
console_type: Optional[VirtualBoxConsoleType] = Field("none", description="Console type")
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
custom_adapters: Optional[List[CustomAdapter]] = Field(default_factory=list, description="Custom adapters")
|
||||
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.vmware_nodes import (
|
||||
VMwareConsoleType,
|
||||
VMwareAdapterType,
|
||||
VMwareOnCloseAction,
|
||||
CustomAdapter
|
||||
)
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class VMwareTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "guest"
|
||||
default_name_format: Optional[str] = "{name}-{0}"
|
||||
symbol: Optional[str] = ":/symbols/vmware_guest.svg"
|
||||
vmx_path: str = Field(..., description="Path to the vmx file")
|
||||
linked_clone: Optional[bool] = Field(False, description="Whether the VM is a linked clone or not")
|
||||
first_port_name: Optional[str] = Field("", description="Optional name of the first networking port example: eth0")
|
||||
port_name_format: Optional[str] = Field(
|
||||
"Ethernet{0}", description="Optional formatting of the networking port example: eth{0}"
|
||||
)
|
||||
port_segment_size: Optional[int] = Field(
|
||||
0,
|
||||
description="Optional port segment size. A port segment is a block of port. For example Ethernet0/0 Ethernet0/1 is the module 0 with a port segment size of 2",
|
||||
)
|
||||
adapters: Optional[int] = Field(
|
||||
1, ge=0, le=10, description="Number of adapters"
|
||||
) # 10 is the maximum adapters support by VMware VMs
|
||||
adapter_type: Optional[VMwareAdapterType] = Field("e1000", description="VMware adapter type")
|
||||
use_any_adapter: Optional[bool] = Field(False, description="Allow GNS3 to use any VMware adapter")
|
||||
headless: Optional[bool] = Field(False, description="Headless mode")
|
||||
on_close: Optional[VMwareOnCloseAction] = Field("power_off", description="Action to execute on the VM is closed")
|
||||
console_type: Optional[VMwareConsoleType] = Field("none", description="Console type")
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
custom_adapters: Optional[List[CustomAdapter]] = Field(default_factory=list, description="Custom adapters")
|
||||
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 . import Category, TemplateBase
|
||||
from gns3server.schemas.compute.vpcs_nodes import ConsoleType
|
||||
|
||||
from pydantic import Field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class VPCSTemplate(TemplateBase):
|
||||
|
||||
category: Optional[Category] = "guest"
|
||||
default_name_format: Optional[str] = "PC{0}"
|
||||
symbol: Optional[str] = ":/symbols/vpcs_guest.svg"
|
||||
base_script_file: Optional[str] = Field("vpcs_base_config.txt", description="Script file")
|
||||
console_type: Optional[ConsoleType] = Field("telnet", description="Console type")
|
||||
console_auto_start: Optional[bool] = Field(
|
||||
False, description="Automatically start the console when the node has started"
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Token(BaseModel):
|
||||
|
||||
access_token: str
|
||||
token_type: str
|
||||
|
||||
|
||||
class TokenData(BaseModel):
|
||||
|
||||
username: Optional[str] = None
|
||||
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#
|
||||
# This file contains the validation for checking a .gns3 file
|
||||
#
|
||||
|
||||
from .computes import Compute
|
||||
from .drawings import Drawing
|
||||
from .links import Link
|
||||
from .nodes import Node
|
||||
|
||||
from .projects import Supplier, Variable
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, List
|
||||
from enum import Enum
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
class TopologyType(str, Enum):
|
||||
|
||||
topology = "topology"
|
||||
|
||||
|
||||
class TopologyContent(BaseModel):
|
||||
|
||||
computes: List[Compute] = Field(..., description="List of computes")
|
||||
drawings: List[Drawing] = Field(..., description="List of drawings")
|
||||
links: List[Link] = Field(..., description="List of links")
|
||||
nodes: List[Node] = Field(..., description="List of nodes")
|
||||
|
||||
|
||||
class Topology(BaseModel):
|
||||
|
||||
project_id: UUID = Field(..., description="Project UUID")
|
||||
type: TopologyType = Field(..., description="Type of file. It's always topology")
|
||||
revision: int = Field(..., description="Version of the .gns3 specification")
|
||||
version: str = Field(..., description="Version of the GNS3 software which have update the file for the last time")
|
||||
name: str = Field(..., description="Name of the project")
|
||||
topology: TopologyContent = Field(..., description="Topology content")
|
||||
auto_start: Optional[bool] = Field(None, description="Start the topology when opened")
|
||||
auto_close: Optional[bool] = Field(None, description="Close the topology when no client is connected")
|
||||
scene_height: Optional[int] = Field(None, description="Height of the drawing area")
|
||||
scene_width: Optional[int] = Field(None, description="Width of the drawing area")
|
||||
zoom: Optional[int] = Field(None, description="Zoom of the drawing area")
|
||||
show_layers: Optional[bool] = Field(None, description="Show layers on the drawing area")
|
||||
snap_to_grid: Optional[bool] = Field(None, description="Snap to grid on the drawing area")
|
||||
show_grid: Optional[bool] = Field(None, description="Show the grid on the drawing area")
|
||||
grid_size: Optional[int] = Field(None, description="Grid size for the drawing area for nodes")
|
||||
drawing_grid_size: Optional[int] = Field(None, description="Grid size for the drawing area for drawings")
|
||||
show_interface_labels: Optional[bool] = Field(None, description="Show interface labels on the drawing area")
|
||||
supplier: Optional[Supplier] = Field(None, description="Supplier of the project")
|
||||
variables: Optional[List[Variable]] = Field(None, description="Variables required to run the project")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
with open(sys.argv[1]) as f:
|
||||
data = json.load(f)
|
||||
Topology.parse_obj(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,58 @@
|
||||
#
|
||||
# Copyright (C) 2020 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 typing import Optional
|
||||
from pydantic import EmailStr, BaseModel, Field
|
||||
from uuid import UUID
|
||||
|
||||
from .base import DateTimeModelMixin
|
||||
|
||||
|
||||
class UserBase(BaseModel):
|
||||
"""
|
||||
Common user properties.
|
||||
"""
|
||||
|
||||
username: Optional[str] = Field(None, min_length=3, regex="[a-zA-Z0-9_-]+$")
|
||||
email: Optional[EmailStr]
|
||||
full_name: Optional[str]
|
||||
|
||||
|
||||
class UserCreate(UserBase):
|
||||
"""
|
||||
Properties to create an user.
|
||||
"""
|
||||
|
||||
username: str = Field(..., min_length=3, regex="[a-zA-Z0-9_-]+$")
|
||||
password: str = Field(..., min_length=7, max_length=100)
|
||||
|
||||
|
||||
class UserUpdate(UserBase):
|
||||
"""
|
||||
Properties to update an user.
|
||||
"""
|
||||
|
||||
password: Optional[str] = Field(None, min_length=7, max_length=100)
|
||||
|
||||
|
||||
class User(DateTimeModelMixin, UserBase):
|
||||
|
||||
user_id: UUID
|
||||
is_active: bool = True
|
||||
is_superuser: bool = False
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
Reference in new issue
Block a user