Migration to FastAPI

This commit is contained in:
grossmj committed 2020-10-02 16:07:50 +09:30
1 parent c12b675691
commit eb3cb8a41f
224 files changed
+11254 -13517

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
#
# 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 .version import Version
from .iou_license import IOULicense
from .links import Link
from .common import ErrorMessage
from .computes import ComputeCreate, ComputeUpdate, Compute, AutoIdlePC
from .nodes import NodeUpdate, NodeDuplicate, NodeCapture, Node
from .projects import ProjectCreate, ProjectUpdate, ProjectDuplicate, Project, ProjectFile
from .snapshots import SnapshotCreate, Snapshot
from .templates import TemplateCreate, TemplateUpdate, TemplateUsage, Template
from .capabilities import Capabilities
from .nios import UDPNIO, TAPNIO, EthernetNIO
from .atm_switch_nodes import ATMSwitchCreate, ATMSwitchUpdate, ATMSwitch
from .cloud_nodes import CloudCreate, CloudUpdate, Cloud
from .docker_nodes import DockerCreate, DockerUpdate, Docker
from .dynamips_nodes import DynamipsCreate, DynamipsUpdate, Dynamips
from .ethernet_hub_nodes import EthernetHubCreate, EthernetHubUpdate, EthernetHub
from .ethernet_switch_nodes import EthernetSwitchCreate, EthernetSwitchUpdate, EthernetSwitch
from .frame_relay_switch_nodes import FrameRelaySwitchCreate, FrameRelaySwitchUpdate, FrameRelaySwitch
from .iou_nodes import IOUCreate, IOUUpdate, IOUStart, IOU
from .nat_nodes import NATCreate, NATUpdate, NAT
from .qemu_nodes import QemuCreate, QemuUpdate, Qemu, QemuDiskResize, QemuImageCreate, QemuImageUpdate
from .virtualbox_nodes import VirtualBoxCreate, VirtualBoxUpdate, VirtualBox
from .vmware_nodes import VMwareCreate, VMwareUpdate, VMware
from .vpcs_nodes import VPCSCreate, VPCSUpdate, VPCS
from .vpcs_templates import VPCSTemplateCreate, VPCSTemplateUpdate, VPCSTemplate
from .cloud_templates import CloudTemplateCreate, CloudTemplateUpdate, CloudTemplate
from .iou_templates import IOUTemplateCreate, IOUTemplateUpdate, IOUTemplate
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
#
# 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
from typing import Optional
from uuid import UUID
from .nodes import NodeStatus
class ATMSwitchBase(BaseModel):
"""
Common ATM switch properties.
"""
name: str = None
node_id: UUID = None
usage: Optional[str] = None
mappings: Optional[dict] = None
class ATMSwitchCreate(ATMSwitchBase):
"""
Properties to create an ATM switch node.
"""
node_id: Optional[UUID] = None
class ATMSwitchUpdate(ATMSwitchBase):
"""
Properties to update an ATM switch node.
"""
name: Optional[str] = None
node_id: Optional[UUID] = None
class ATMSwitch(ATMSwitchBase):
project_id: UUID
status: Optional[NodeStatus] = None
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
#
# 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")
+136
View File
@@ -0,0 +1,136 @@
# -*- coding: utf-8 -*-
#
# 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, Union, List
from enum import Enum
from uuid import UUID
from .nodes import NodeStatus
class HostInterfaceType(Enum):
ethernet = "ethernet"
tap = "tap"
class HostInterface(BaseModel):
"""
Interface on this host.
"""
name: str = Field(..., description="Interface name")
type: HostInterfaceType = Field(..., description="Interface type")
special: bool = Field(..., description="Whether the interface is non standard")
class EthernetType(Enum):
ethernet = "ethernet"
class EthernetPort(BaseModel):
"""
Ethernet port properties.
"""
name: str
port_number: int
type: EthernetType
interface: str
class TAPType(Enum):
tap = "tap"
class TAPPort(BaseModel):
"""
TAP port properties.
"""
name: str
port_number: int
type: TAPType
interface: str
class UDPType(Enum):
udp = "udp"
class UDPPort(BaseModel):
"""
UDP tunnel port properties.
"""
name: str
port_number: int
type: UDPType
lport: int = Field(..., gt=0, le=65535, description="Local port")
rhost: str = Field(..., description="Remote host")
rport: int = Field(..., gt=0, le=65535, description="Remote port")
class CloudConsoleType(Enum):
telnet = "telnet"
vnc = "vnc"
spice = "spice"
http = "http"
https = "https"
none = "none"
class CloudBase(BaseModel):
"""
Common cloud node properties.
"""
name: str
node_id: Optional[UUID] = None
usage: Optional[str] = None
remote_console_host: Optional[str] = Field(None, description="Remote console host or IP")
remote_console_port: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
remote_console_type: Optional[CloudConsoleType] = Field(None, description="Console type")
remote_console_http_path: Optional[str] = Field(None, description="Path of the remote web interface")
ports_mapping: Optional[List[Union[EthernetPort, TAPPort, UDPPort]]] = Field(None, description="List of port mappings")
interfaces: Optional[List[HostInterface]] = Field(None, description="List of interfaces")
class CloudCreate(CloudBase):
"""
Properties to create a cloud node.
"""
pass
class CloudUpdate(CloudBase):
"""
Properties to update a cloud node.
"""
name: Optional[str] = None
class Cloud(CloudBase):
project_id: UUID
node_id: UUID
ports_mapping: List[Union[EthernetPort, TAPPort, UDPPort]]
status: NodeStatus = Field(..., description="Cloud node status (read only)")
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
#
# 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 .templates import Category, TemplateBase
from .cloud_nodes import EthernetPort, TAPPort, UDPPort
from pydantic import Field
from typing import Optional, Union, List
from enum import Enum
from .nodes import NodeType
class RemoteConsoleType(str, Enum):
"""
Supported remote console types for cloud nodes.
"""
none = "none"
telnet = "telnet"
vnc = "vnc"
spice = "spice"
http = "http"
https = "https"
class CloudTemplateBase(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]] = []
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[RemoteConsoleType] = Field("none", description="Remote console type")
remote_console_path: Optional[str] = Field("/", description="Path of the remote web interface")
class CloudTemplateCreate(CloudTemplateBase):
name: str
template_type: NodeType
compute_id: str
class CloudTemplateUpdate(CloudTemplateBase):
pass
class CloudTemplate(CloudTemplateBase):
template_id: str
name: str
category: Category
symbol: str
builtin: bool
template_type: NodeType
compute_id: Union[str, None]
+40
View File
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# 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, Union
class ErrorMessage(BaseModel):
"""
Error message.
"""
message: str
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")
+130
View File
@@ -0,0 +1,130 @@
# -*- coding: utf-8 -*-
#
# 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, Union
from uuid import UUID
from enum import Enum
from .nodes import NodeType
class Protocol(str, Enum):
"""
Protocol supported to communicate with a compute.
"""
http = "http"
https = "https"
class ComputeBase(BaseModel):
"""
Data to create a compute.
"""
compute_id: Optional[Union[str, UUID]] = None
name: Optional[str] = None
protocol: Protocol
host: str
port: int = Field(..., gt=0, le=65535)
user: Optional[str] = None
class ComputeCreate(ComputeBase):
"""
Data to create a compute.
"""
password: Optional[str] = None
class Config:
schema_extra = {
"example": {
"name": "My compute",
"host": "127.0.0.1",
"port": 3080,
"user": "user",
"password": "password"
}
}
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[str] = 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(ComputeBase):
"""
Data returned for a compute.
"""
compute_id: Union[str, UUID]
name: str
connected: bool = Field(..., description="Whether the controller is connected to the compute or not")
cpu_usage_percent: float = Field(..., description="CPU usage of the compute", ge=0, le=100)
memory_usage_percent: float = Field(..., description="Memory usage of the compute", ge=0, le=100)
disk_usage_percent: float = Field(..., description="Disk usage of the compute", ge=0, le=100)
last_error: Optional[str] = Field(None, description="Last error found on the compute")
capabilities: Capabilities
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,73 @@
# -*- coding: utf-8 -*-
#
# 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, List
from uuid import UUID
from .nodes import CustomAdapter, ConsoleType, AuxType, NodeStatus
class DockerBase(BaseModel):
"""
Common Docker node properties.
"""
name: str
image: str = Field(..., description="Docker image name")
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_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")
aux_type: Optional[AuxType] = Field(None, description="Auxiliary console type")
usage: Optional[str] = Field(None, description="How to use the Docker container")
start_command: Optional[str] = Field(None, description="Docker CMD entry")
adapters: Optional[int] = Field(None, ge=0, le=99, description="Number of adapters")
environment: Optional[str] = Field(None, description="Docker environment variables")
extra_hosts: Optional[str] = Field(None, description="Docker extra hosts (added to /etc/hosts)")
extra_volumes: Optional[List[str]] = Field(None, description="Additional directories to make persistent")
memory: Optional[int] = Field(None, description="Maximum amount of memory the container can use in MB")
cpus: Optional[int] = Field(None, description="Maximum amount of CPU resources the container can use")
custom_adapters: Optional[List[CustomAdapter]] = Field(None, description="Custom adapters")
class DockerCreate(DockerBase):
"""
Properties to create a Docker node.
"""
pass
class DockerUpdate(DockerBase):
"""
Properties to update a Docker node.
"""
name: Optional[str] = None
image: Optional[str] = Field(None, description="Docker image name")
class Docker(DockerBase):
container_id: str = Field(..., min_length=12, max_length=64, regex="^[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)")
status: NodeStatus = Field(..., description="Container status (read only)")
+35
View File
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
#
# 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,180 @@
# -*- coding: utf-8 -*-
#
# 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, List
from pathlib import Path
from enum import Enum
from uuid import UUID
from .nodes import NodeStatus
class DynamipsAdapters(str, Enum):
"""
Supported Dynamips Network Modules.
"""
c7200_io_2fe = "C7200-IO-2FE"
c7200_io_fe = "C7200-IO-FE"
c7200_io_ge_e = "C7200-IO-GE-E"
nm_16esw = "NM-16ESW"
nm_1e = "NM-1E"
nm_1fe_tx = "NM-1FE-TX"
nm_4e = "NM-4E"
nm_4t = "NM-4T"
pa_2fe_tx = "PA-2FE-TX"
pa_4e = "PA-4E"
pa_4t_plus = "PA-4T+"
pa_8e = "PA-8E"
pa_8t = "PA-8T"
pa_a1 = "PA-A1"
pa_fe_tx = "PA-FE-TX"
pa_ge = "PA-GE"
pa_pos_oc3 = "PA-POS-OC3"
c2600_mb_2fe = "C2600-MB-2FE"
c2600_mb_1e = "C2600-MB-1E"
c1700_mb_1fe = "C1700-MB-1FE"
c2600_mb_2e = "C2600-MB-2E"
c2600_mb_1fe = "C2600-MB-1FE"
c1700_mb_wic1 = "C1700-MB-WIC1"
gt96100_fe = "GT96100-FE"
leopard_2fe = "Leopard-2FE"
class DynamipsWics(str, Enum):
"""
Supported Dynamips WICs.
"""
wic_1enet = "WIC-1ENET"
wic_1t = "WIC-1T"
wic_2t = "WIC-2T"
class DynamipsConsoleType(str, Enum):
"""
Supported Dynamips console types.
"""
telnet = "telnet"
none = "none"
class DynamipsNPE(str, Enum):
"""
Supported Dynamips NPE models.
"""
npe_100 = "npe-100"
npe_150 = "npe-150"
npe_175 = "npe-175"
npe_200 = "npe-200"
npe_225 = "npe-225"
npe_300 = "npe-300"
npe_400 = "npe-400"
npe_g2 = "npe-g2"
class DynamipsMidplane(str, Enum):
"""
Supported Dynamips Midplane models.
"""
std = "std"
vxr = "vxr"
#TODO: improve schema for Dynamips (match platform specific options, e.g. NPE allowd only for c7200)
class DynamipsBase(BaseModel):
"""
Common Dynamips node properties.
"""
node_id: Optional[UUID] = None
name: Optional[str] = None
dynamips_id: Optional[int] = Field(None, description="Dynamips internal ID")
platform: Optional[str] = Field(None, description="Cisco router platform", regex="^c[0-9]{4}$")
ram: Optional[int] = Field(None, description="Amount of RAM in MB")
nvram: Optional[int] = Field(None, description="Amount of NVRAM in KB")
image: Optional[Path] = 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)?$")
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]+)?$")
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")
disk0: Optional[int] = Field(None, description="Disk0 size in MB")
disk1: Optional[int] = Field(None, description="Disk1 size in MB")
auto_delete_disks: Optional[bool] = Field(None, description="Automatically delete nvram and disk files")
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
console_type: Optional[DynamipsConsoleType] = Field(None, description="Console type")
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}$")
system_id: Optional[str] = Field(None, description="System ID")
slot0: Optional[str] = Field(None, description="Network module slot 0")
slot1: Optional[str] = Field(None, description="Network module slot 1")
slot2: Optional[str] = Field(None, description="Network module slot 2")
slot3: Optional[str] = Field(None, description="Network module slot 3")
slot4: Optional[str] = Field(None, description="Network module slot 4")
slot5: Optional[str] = Field(None, description="Network module slot 5")
slot6: Optional[str] = Field(None, description="Network module slot 6")
wic0: Optional[str] = Field(None, description="Network module WIC slot 0")
wic1: Optional[str] = Field(None, description="Network module WIC slot 1")
wic2: Optional[str] = Field(None, description="Network module WIC slot 2")
npe: Optional[DynamipsNPE] = Field(None, description="NPE model")
midplane: Optional[DynamipsMidplane] = Field(None, description="Midplane model")
sensors: Optional[List] = Field(None, description="Temperature sensors")
power_supplies: Optional[List] = Field(None, description="Power supplies status")
# I/O memory property for all platforms but C7200
iomem: Optional[int] = Field(None, ge=0, le=100, description="I/O memory percentage")
class DynamipsCreate(DynamipsBase):
"""
Properties to create a Dynamips node.
"""
name: str
platform: str = Field(..., description="Cisco router platform", regex="^c[0-9]{4}$")
image: Path = Field(..., description="Path to the IOS image")
ram: int = Field(..., description="Amount of RAM in MB")
class DynamipsUpdate(DynamipsBase):
"""
Properties to update a Dynamips node.
"""
pass
class Dynamips(DynamipsBase):
name: str
node_id: UUID
project_id: UUID
dynamips_id: int
status: NodeStatus
node_directory: Optional[Path] = Field(None, description="Path to the vm working directory")
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
#
# 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
from typing import Optional, List
from uuid import UUID
from .nodes import NodeStatus
class EthernetHubPort(BaseModel):
name: str
port_number: int
class EthernetHubBase(BaseModel):
"""
Common Ethernet hub properties.
"""
name: Optional[str] = None
node_id: Optional[UUID] = None
usage: Optional[str] = None
ports_mapping: Optional[List[EthernetHubPort]] = None
class EthernetHubCreate(EthernetHubBase):
"""
Properties to create an Ethernet hub node.
"""
name: str
class EthernetHubUpdate(EthernetHubBase):
"""
Properties to update an Ethernet hub node.
"""
pass
class EthernetHub(EthernetHubBase):
name: str
node_id: UUID
project_id: UUID
ports_mapping: List[EthernetHubPort]
status: NodeStatus
@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*-
#
# 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, List
from uuid import UUID
from enum import Enum
from .nodes import NodeStatus
class EthernetSwitchPortType(Enum):
access = "access"
dot1q = "dot1q"
qinq = "qinq"
class EthernetSwitchEtherType(Enum):
ethertype_8021q = "0x8100"
ethertype_qinq = "0x88A8"
ethertype_8021q9100 = "0x9100"
ethertype_8021q9200 = "0x9200"
class EthernetSwitchPort(BaseModel):
name: str
port_number: int
type: EthernetSwitchPortType = Field(..., description="Port type")
vlan: Optional[int] = Field(None, ge=1, description="VLAN number")
ethertype: Optional[EthernetSwitchEtherType] = Field(None, description="QinQ Ethertype")
class TelnetConsoleType(str, Enum):
"""
Supported console types.
"""
telnet = "telnet"
none = "none"
class EthernetSwitchBase(BaseModel):
"""
Common Ethernet switch properties.
"""
name: Optional[str] = None
node_id: Optional[UUID] = None
usage: Optional[str] = None
ports_mapping: Optional[List[EthernetSwitchPort]] = None
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
console_type: Optional[TelnetConsoleType] = Field(None, description="Console type")
class EthernetSwitchCreate(EthernetSwitchBase):
"""
Properties to create an Ethernet switch node.
"""
name: str
class EthernetSwitchUpdate(EthernetSwitchBase):
"""
Properties to update an Ethernet hub node.
"""
pass
class EthernetSwitch(EthernetSwitchBase):
name: str
node_id: UUID
project_id: UUID
ports_mapping: List[EthernetSwitchPort]
status: NodeStatus
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env python
#
# 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/>.
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
#
# 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
from typing import Optional
from uuid import UUID
from .nodes import NodeStatus
class FrameRelaySwitchBase(BaseModel):
"""
Common Frame Relay switch properties.
"""
name: str = None
node_id: UUID = None
usage: Optional[str] = None
mappings: Optional[dict] = None
class FrameRelaySwitchCreate(FrameRelaySwitchBase):
"""
Properties to create an Frame Relay node.
"""
node_id: Optional[UUID] = None
class FrameRelaySwitchUpdate(FrameRelaySwitchBase):
"""
Properties to update an Frame Relay node.
"""
name: Optional[str] = None
node_id: Optional[UUID] = None
class FrameRelaySwitch(FrameRelaySwitchBase):
project_id: UUID
status: Optional[NodeStatus] = None
+56
View File
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
#
# 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")
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,24 @@
# -*- coding: utf-8 -*-
#
# 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")
+78
View File
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
#
# 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 pathlib import Path
from typing import Optional
from uuid import UUID
from .nodes import ConsoleType, NodeStatus
class IOUBase(BaseModel):
"""
Common IOU node properties.
"""
name: str
path: Path = Field(..., description="IOU executable path")
application_id: int = Field(..., description="Application ID for running IOU executable")
node_id: Optional[UUID]
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")
md5sum: Optional[str] = Field(None, description="IOU executable checksum")
serial_adapters: Optional[int] = Field(None, description="How many serial adapters are connected to IOU")
ethernet_adapters: Optional[int] = Field(None, description="How many Ethernet adapters are connected to IOU")
ram: Optional[int] = Field(None, description="Amount of RAM in MB")
nvram: Optional[int] = Field(None, description="Amount of NVRAM in KB")
l1_keepalives: Optional[bool] = Field(None, description="Use default IOU values")
use_default_iou_values: Optional[bool] = Field(None, description="Always up Ethernet interfaces")
startup_config_content: Optional[str] = Field(None, description="Content of IOU startup configuration file")
private_config_content: Optional[str] = Field(None, description="Content of IOU private configuration file")
class IOUCreate(IOUBase):
"""
Properties to create an IOU node.
"""
pass
class IOUUpdate(IOUBase):
"""
Properties to update an IOU node.
"""
name: Optional[str]
path: Optional[Path] = Field(None, description="IOU executable path")
application_id: Optional[int] = Field(None, description="Application ID for running IOU executable")
class IOU(IOUBase):
project_id: UUID = Field(..., description="Project ID")
node_directory: str = Field(..., description="Path to the node working directory (read only)")
command_line: str = Field(..., description="Last command line used to start IOU (read only)")
status: NodeStatus = Field(..., description="Container status (read only)")
class IOUStart(BaseModel):
iourc_content: Optional[str] = Field(None, description="Content of the iourc file")
license_check: Optional[bool] = Field(None, description="Whether the IOU license should be checked")
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
#
# 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 .templates import Category, TemplateBase
from pydantic import Field
from pathlib import Path
from typing import Optional, Union
from enum import Enum
from .nodes import NodeType
class ConsoleType(str, Enum):
"""
Supported console types for IOU nodes
"""
none = "none"
telnet = "telnet"
class IOUTemplateBase(TemplateBase):
category: Optional[Category] = "router"
default_name_format: Optional[str] = "IOU{0}"
symbol: Optional[str] = ":/symbols/multilayer_switch.svg"
path: Path = 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")
class IOUTemplateCreate(IOUTemplateBase):
name: str
template_type: NodeType
compute_id: str
class IOUTemplateUpdate(IOUTemplateBase):
pass
class IOUTemplate(IOUTemplateBase):
template_id: str
name: str
category: Category
symbol: str
builtin: bool
template_type: NodeType
compute_id: Union[str, None]
+60
View File
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
#
# 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 .common 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
+121
View File
@@ -0,0 +1,121 @@
# -*- coding: utf-8 -*-
#
# 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, Union, List
from enum import Enum
from uuid import UUID
from .nodes import NodeStatus
class HostInterfaceType(Enum):
ethernet = "ethernet"
tap = "tap"
class HostInterface(BaseModel):
"""
Interface on this host.
"""
name: str = Field(..., description="Interface name")
type: HostInterfaceType = Field(..., description="Interface type")
special: bool = Field(..., description="Whether the interface is non standard")
class EthernetType(Enum):
ethernet = "ethernet"
class EthernetPort(BaseModel):
"""
Ethernet port properties.
"""
name: str
port_number: int
type: EthernetType
interface: str
class TAPType(Enum):
tap = "tap"
class TAPPort(BaseModel):
"""
TAP port properties.
"""
name: str
port_number: int
type: TAPType
interface: str
class UDPType(Enum):
udp = "udp"
class UDPPort(BaseModel):
"""
UDP tunnel port properties.
"""
name: str
port_number: int
type: UDPType
lport: int = Field(..., gt=0, le=65535, description="Local port")
rhost: str = Field(..., description="Remote host")
rport: int = Field(..., gt=0, le=65535, description="Remote port")
class NATBase(BaseModel):
"""
Common NAT node properties.
"""
name: str
node_id: Optional[UUID] = None
usage: Optional[str] = None
ports_mapping: Optional[List[Union[EthernetPort, TAPPort, UDPPort]]] = Field(None, description="List of port mappings")
class NATCreate(NATBase):
"""
Properties to create a NAT node.
"""
pass
class NATUpdate(NATBase):
"""
Properties to update a NAT node.
"""
name: Optional[str] = None
class NAT(NATBase):
project_id: UUID
node_id: UUID
ports_mapping: List[Union[EthernetPort, TAPPort, UDPPort]]
status: NodeStatus = Field(..., description="NAT node status (read only)")
+69
View File
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
#
# 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, Union, Generic
from enum import Enum
from uuid import UUID
class UDPNIOType(Enum):
udp = "nio_udp"
class UDPNIO(BaseModel):
"""
UDP Network Input/Output properties.
"""
type: UDPNIOType
lport: int = Field(..., gt=0, le=65535, description="Local port")
rhost: str = Field(..., description="Remote host")
rport: int = Field(..., gt=0, le=65535, description="Remote port")
suspend: Optional[int] = Field(None, description="Suspend the NIO")
filters: Optional[dict] = Field(None, description="Packet filters")
class EthernetNIOType(Enum):
ethernet = "nio_ethernet"
class EthernetNIO(BaseModel):
"""
Generic Ethernet Network Input/Output properties.
"""
type: EthernetNIOType
ethernet_device: str = Field(..., description="Ethernet device name e.g. eth0")
class TAPNIOType(Enum):
tap = "nio_tap"
class TAPNIO(BaseModel):
"""
TAP Network Input/Output properties.
"""
type: TAPNIOType
tap_device: str = Field(..., description="TAP device name e.g. tap0")
+201
View File
@@ -0,0 +1,201 @@
# -*- coding: utf-8 -*-
#
# 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 pathlib import Path
from pydantic import BaseModel, Field
from typing import List, Optional, Union
from enum import Enum
from uuid import UUID
from .common import Label
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"
traceng = "traceng"
virtualbox = "virtualbox"
vmware = "vmware"
iou = "iou"
qemu = "qemu"
class Image(BaseModel):
"""
Image data.
"""
filename: str
path: Path
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 ConsoleType(str, Enum):
"""
Supported console types.
"""
vnc = "vnc"
telnet = "telnet"
http = "http"
https = "https"
spice = "spice"
spice_agent = "spice+agent"
none = "none"
class AuxType(str, Enum):
"""
Supported auxiliary console types.
"""
telnet = "telnet"
none = "none"
class NodeStatus(str, Enum):
"""
Supported node statuses.
"""
stopped = "stopped"
started = "started"
suspended = "suspended"
class NodeCapture(BaseModel):
"""
Node capture data.
"""
capture_file_name: str
data_link_type: Optional[DataLinkType] = None
class CustomAdapter(BaseModel):
"""
Custom adapter data.
"""
adapter_number: int
port_name: Optional[str] = None
adapter_type: Optional[str] = None
mac_address: Optional[str] = Field(None, regex="^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$")
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 Node(BaseModel):
"""
Node data.
"""
compute_id: Union[UUID, str]
name: str
node_type: NodeType
project_id: Optional[UUID] = None
node_id: Optional[UUID] = None
template_id: Optional[UUID] = Field(None, description="Template UUID from which the node has been created. Read only")
node_directory: Optional[str] = Field(None, description="Working directory of the node. Read only")
command_line: Optional[str] = Field(None, description="Command line use to start the node")
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
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")
console_type: Optional[ConsoleType] = None
console_auto_start: Optional[bool] = Field(None, 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(None, description="Properties specific to an emulator")
status: Optional[NodeStatus] = None
label: Optional[Label] = None
symbol: Optional[str] = None
width: Optional[int] = Field(None, description="Width of the node (Read only)")
height: Optional[int] = Field(None, description="Height of the node (Read only)")
x: Optional[int] = None
y: Optional[int] = None
z: Optional[int] = None
locked: Optional[bool] = Field(None, description="Whether the element locked or not")
port_name_format: Optional[str] = Field(None, description="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
ports: Optional[List[NodePort]] = Field(None, description="List of node ports (read only)")
class NodeUpdate(Node):
"""
Data to update a node.
"""
compute_id: Optional[Union[UUID, str]] = None
name: Optional[str] = None
node_type: Optional[NodeType] = None
class NodeDuplicate(BaseModel):
"""
Data to duplicate a node.
"""
x: int
y: int
z: Optional[int] = 0
+105
View File
@@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-
#
# 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 pathlib import Path
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: HttpUrl = Field(..., 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[Path] = 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):
name: Optional[str] = None
project_id = UUID
status: Optional[ProjectStatus] = None
class ProjectFile(BaseModel):
path: Path = Field(..., description="File path")
md5sum: str = Field(..., description="File checksum")
+293
View File
@@ -0,0 +1,293 @@
# -*- coding: utf-8 -*-
#
# 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 pathlib import Path
from typing import Optional, List
from enum import Enum
from uuid import UUID
from .nodes import CustomAdapter, NodeStatus
class QemuPlatform(str, Enum):
aarch64 = "aarch64"
alpha = "alpha"
arm = "arm"
cris = "cris"
i386 = "i386"
lm32 = "lm32"
m68k = "m68k"
microblaze = "microblaze"
microblazeel = "microblazeel"
mips = "mips"
mips64 = "mips64"
mips64el = "mips64el"
mipsel = "mipsel"
moxie = "moxie"
or32 = "or32"
ppc = "ppc"
ppc64 = "ppc64"
ppcemb = "ppcemb"
s390x = "s390x"
sh4 = "sh4"
sh4eb = "sh4eb"
sparc = "sparc"
sparc64 = "sparc64"
tricore = "tricore"
unicore32 = "unicore32"
x86_64 = "x86_64"
xtensa = "xtensa"
xtensaeb = "xtensaeb"
class QemuConsoleType(str, Enum):
"""
Supported console types.
"""
vnc = "vnc"
telnet = "telnet"
spice = "spice"
spice_agent = "spice+agent"
none = "none"
class QemuBootPriority(str, Enum):
"""
Supported boot priority types.
"""
c = "c"
d = "d"
n = "n"
cn = "cn"
cd = "cd"
dn = "dn"
dc = "dc"
nc = "nc"
nd = "nd"
class QemuOnCloseAction(str, Enum):
"""
Supported actions when closing Qemu VM.
"""
power_off = "power_off"
shutdown_signal = "shutdown_signal"
save_vm_state = "save_vm_state"
class QemuProcessPriority(str, Enum):
realtime = "realtime"
very_high = "very high"
high = "high"
normal = "normal"
low = "low"
very_low = "very low"
class QemuBase(BaseModel):
"""
Common Qemu node properties.
"""
name: str
node_id: Optional[UUID]
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[Path] = Field(None, description="Qemu executable path")
platform: Optional[QemuPlatform] = Field(None, description="Platform to emulate")
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
console_type: Optional[QemuConsoleType] = Field(None, description="Console type")
aux: Optional[int] = Field(None, gt=0, le=65535, description="Auxiliary console TCP port")
aux_type: Optional[QemuConsoleType] = Field(None, description="Auxiliary console type")
hda_disk_image: Optional[Path] = Field(None, description="QEMU hda disk image path")
hda_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hda disk image checksum")
hda_disk_image_interface: Optional[str] = Field(None, description="QEMU hda interface")
hdb_disk_image: Optional[Path] = Field(None, description="QEMU hdb disk image path")
hdb_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdb disk image checksum")
hdb_disk_image_interface: Optional[str] = Field(None, description="QEMU hdb interface")
hdc_disk_image: Optional[Path] = Field(None, description="QEMU hdc disk image path")
hdc_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdc disk image checksum")
hdc_disk_image_interface: Optional[str] = Field(None, description="QEMU hdc interface")
hdd_disk_image: Optional[Path] = Field(None, description="QEMU hdd disk image path")
hdd_disk_image_md5sum: Optional[str] = Field(None, description="QEMU hdd disk image checksum")
hdd_disk_image_interface: Optional[str] = Field(None, description="QEMU hdd interface")
cdrom_image: Optional[Path] = Field(None, description="QEMU cdrom image path")
cdrom_image_md5sum: Optional[str] = Field(None, description="QEMU cdrom image checksum")
bios_image: Optional[Path] = Field(None, description="QEMU bios image path")
bios_image_md5sum: Optional[str] = Field(None, description="QEMU bios image checksum")
initrd: Optional[Path] = Field(None, description="QEMU initrd path")
initrd_md5sum: Optional[str] = Field(None, description="QEMU initrd checksum")
kernel_image: Optional[Path] = Field(None, description="QEMU kernel image path")
kernel_image_md5sum: Optional[str] = Field(None, description="QEMU kernel image checksum")
kernel_command_line: Optional[str] = Field(None, description="QEMU kernel command line")
boot_priotiry: Optional[QemuBootPriority] = Field(None, description="QEMU boot priority")
ram: Optional[int] = Field(None, description="Amount of RAM in MB")
cpus: Optional[int] = Field(None, ge=1, le=255, description="Number of vCPUs")
maxcpus: Optional[int] = Field(None, ge=1, le=255, description="Maximum number of hotpluggable vCPUs")
adapters: Optional[int] = Field(None, ge=0, le=275, description="Number of adapters")
adapter_type: Optional[str] = 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})$")
legacy_networking: Optional[bool] = Field(None, description="Use QEMU legagy networking commands (-net syntax)")
replicate_network_connection_state: Optional[bool] = Field(None, description="Replicate the network connection state for links in Qemu")
create_config_disk: Optional[bool] = Field(None, description="Automatically create a config disk on HDD disk interface (secondary slave)")
on_close: Optional[QemuOnCloseAction] = Field(None, description="Action to execute on the VM is closed")
cpu_throttling: Optional[int] = Field(None, ge=0, le=800, description="Percentage of CPU allowed for QEMU")
process_priority: Optional[QemuProcessPriority] = Field(None, description="Process priority for QEMU")
options: Optional[str] = Field(None, description="Additional QEMU options")
custom_adapters: Optional[List[CustomAdapter]] = Field(None, description="Custom adapters")
class QemuCreate(QemuBase):
"""
Properties to create a Qemu node.
"""
pass
class QemuUpdate(QemuBase):
"""
Properties to update a Qemu node.
"""
name: Optional[str]
class Qemu(QemuBase):
project_id: UUID = Field(..., description="Project ID")
node_directory: str = Field(..., description="Path to the node working directory (read only)")
command_line: str = Field(..., description="Last command line used to start IOU (read only)")
status: NodeStatus = Field(..., description="Container status (read only)")
class QemuDriveName(str, Enum):
"""
Supported Qemu drive names.
"""
hda = "hda"
hdb = "hdb"
hdc = "hdc"
hdd = "hdd"
class QemuDiskResize(BaseModel):
"""
Properties to resize a Qemu disk.
"""
drive_name: QemuDriveName = Field(..., description="Qemu drive name")
extend: int = Field(..., description="Number of Megabytes to extend the image")
class QemuBinaryPath(BaseModel):
path: Path
version: str
class QemuImageFormat(str, Enum):
"""
Supported Qemu image formats.
"""
qcow2 = "qcow2"
qcow = "qcow"
vpc = "vpc"
vdi = "vdi"
vdmk = "vdmk"
raw = "raw"
class QemuImagePreallocation(str, Enum):
"""
Supported Qemu image preallocation options.
"""
off = "off"
metadata = "metadata"
falloc = "falloc"
full = "full"
class QemuImageOnOff(str, Enum):
"""
Supported Qemu image on/off options.
"""
on = "off"
off = "off"
class QemuImageSubformat(str, Enum):
"""
Supported Qemu image preallocation options.
"""
dynamic = "dynamic"
fixed = "fixed"
stream_optimized = "streamOptimized"
two_gb_max_extent_sparse = "twoGbMaxExtentSparse"
two_gb_max_extent_flat = "twoGbMaxExtentFlat"
monolithic_sparse = "monolithicSparse"
monolithic_flat = "monolithicFlat"
class QemuImageAdapterType(str, Enum):
"""
Supported Qemu image on/off options.
"""
ide = "ide"
lsilogic = "lsilogic"
buslogic = "buslogic"
legacy_esx = "legacyESX"
class QemuImageBase(BaseModel):
qemu_img: Path = Field(..., description="Path to the qemu-img binary")
path: Path = Field(..., description="Absolute or relative path of the image")
format: QemuImageFormat = Field(..., description="Image format type")
size: int = Field(..., description="Image size in Megabytes")
preallocation: Optional[QemuImagePreallocation]
cluster_size: Optional[int]
refcount_bits: Optional[int]
lazy_refcounts: Optional[QemuImageOnOff]
subformat: Optional[QemuImageSubformat]
static: Optional[QemuImageOnOff]
zeroed_grain: Optional[QemuImageOnOff]
adapter_type: Optional[QemuImageAdapterType]
class QemuImageCreate(QemuImageBase):
pass
class QemuImageUpdate(QemuImageBase):
format: Optional[QemuImageFormat] = Field(None, description="Image format type")
size: Optional[int] = Field(None, description="Image size in Megabytes")
extend: Optional[int] = Field(None, description="Number of Megabytes to extend the image")
+43
View File
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
#
# 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)")
+86
View File
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
#
# 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, Union
from enum import Enum
from .nodes import NodeType
class Category(str, Enum):
"""
Supported categories
"""
router = "router"
switch = "switch"
guest = "guest"
firewall = "firewall"
class TemplateBase(BaseModel):
"""
Common template properties.
"""
template_id: Optional[str] = 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
usage: Optional[str] = None
compute_id: Optional[str] = None
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(TemplateBase):
template_id: str
name: str
category: Category
symbol: str
builtin: bool
template_type: NodeType
compute_id: Union[str, None]
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")
+25
View File
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
#
# 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/>.
from pydantic import BaseModel, Field
from typing import Optional
class Version(BaseModel):
version: str = Field(..., description="Version number")
local: Optional[bool] = Field(None, description="Whether this is a local server or not")
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
#
# 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, List
from enum import Enum
from uuid import UUID
from .nodes import NodeStatus, CustomAdapter
class VirtualBoxConsoleType(str, Enum):
"""
Supported console types.
"""
telnet = "telnet"
none = "none"
class VirtualBoxOnCloseAction(str, Enum):
"""
Supported actions when closing VirtualBox VM.
"""
power_off = "power_off"
shutdown_signal = "shutdown_signal"
save_vm_state = "save_vm_state"
class VirtualBoxBase(BaseModel):
"""
Common VirtualBox node properties.
"""
name: str
vmname: str = Field(..., description="VirtualBox VM name (in VirtualBox itself)")
node_id: Optional[UUID]
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
adapters: Optional[int] = Field(None, ge=0, le=36, description="Number of adapters")
adapter_type: Optional[str] = Field(None, description="VirtualBox adapter type")
use_any_adapter: Optional[bool] = Field(None, description="Allow GNS3 to use any VirtualBox adapter")
console: Optional[int] = Field(None, gt=0, le=65535, description="Console TCP port")
console_type: Optional[VirtualBoxConsoleType] = Field(None, description="Console type")
ram: Optional[int] = Field(None, ge=0, le=65535, description="Amount of RAM in MB")
headless: Optional[bool] = Field(None, description="Headless mode")
on_close: Optional[VirtualBoxOnCloseAction] = Field(None, description="Action to execute on the VM is closed")
custom_adapters: Optional[List[CustomAdapter]] = Field(None, description="Custom adpaters")
class VirtualBoxCreate(VirtualBoxBase):
"""
Properties to create a VirtualBox node.
"""
pass
class VirtualBoxUpdate(VirtualBoxBase):
"""
Properties to update a VirtualBox node.
"""
name: Optional[str]
vmname: Optional[str]
class VirtualBox(VirtualBoxBase):
project_id: UUID = Field(..., description="Project ID")
node_directory: Optional[str] = Field(None, description="Path to the node working directory (read only)")
status: NodeStatus = Field(..., description="Container status (read only)")
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
#
# 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, List
from pathlib import Path
from enum import Enum
from uuid import UUID
from .nodes import NodeStatus, CustomAdapter
class VMwareConsoleType(str, Enum):
"""
Supported console types.
"""
telnet = "telnet"
none = "none"
class VMwareOnCloseAction(str, Enum):
"""
Supported actions when closing VMware VM.
"""
power_off = "power_off"
shutdown_signal = "shutdown_signal"
save_vm_state = "save_vm_state"
class VMwareBase(BaseModel):
"""
Common VMware node properties.
"""
name: str
vmx_path: Path = 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]
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")
headless: Optional[bool] = Field(None, description="Headless mode")
on_close: Optional[VMwareOnCloseAction] = Field(None, description="Action to execute on the VM is closed")
# 10 adapters is the maximum supported by VMware VMs.
adapters: Optional[int] = Field(None, ge=0, le=10, description="Number of adapters")
adapter_type: Optional[str] = Field(None, description="VMware adapter type")
use_any_adapter: Optional[bool] = Field(None, description="Allow GNS3 to use any VMware adapter")
custom_adapters: Optional[List[CustomAdapter]] = Field(None, description="Custom adpaters")
class VMwareCreate(VMwareBase):
"""
Properties to create a VMware node.
"""
pass
class VMwareUpdate(VMwareBase):
"""
Properties to update a VMware node.
"""
name: Optional[str]
vmx_path: Optional[Path]
linked_clone: Optional[bool]
class VMware(VMwareBase):
project_id: UUID = Field(..., description="Project ID")
node_directory: Optional[str] = Field(None, description="Path to the node working directory (read only)")
status: NodeStatus = Field(..., description="Container status (read only)")
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
#
# 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
from uuid import UUID
from .nodes import NodeStatus, CustomAdapter
class VPCSConsoleType(str, Enum):
"""
Supported console types.
"""
telnet = "telnet"
none = "none"
class VPCSBase(BaseModel):
"""
Common VPCS node properties.
"""
name: str
node_id: Optional[UUID]
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[VPCSConsoleType] = Field(None, description="Console type")
startup_script: Optional[str] = Field(None, description="Content of the VPCS startup script")
class VPCSCreate(VPCSBase):
"""
Properties to create a VPCS node.
"""
pass
class VPCSUpdate(VPCSBase):
"""
Properties to update a VPCS node.
"""
name: Optional[str]
class VPCS(VPCSBase):
project_id: UUID = Field(..., description="Project ID")
node_directory: str = Field(..., description="Path to the node working directory (read only)")
status: NodeStatus = Field(..., description="Container status (read only)")
command_line: str = Field(..., description="Last command line used to start VPCS")
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
#
# 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 .templates import Category, TemplateBase
from pydantic import Field
from typing import Optional, Union
from enum import Enum
from .nodes import NodeType
class ConsoleType(str, Enum):
"""
Supported console types for VPCS nodes
"""
none = "none"
telnet = "telnet"
class VPCSTemplateBase(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")
class VPCSTemplateCreate(VPCSTemplateBase):
name: str
template_type: NodeType
compute_id: str
class VPCSTemplateUpdate(VPCSTemplateBase):
pass
class VPCSTemplate(VPCSTemplateBase):
template_id: str
name: str
category: Category
symbol: str
builtin: bool
template_type: NodeType
compute_id: Union[str, None]