# -*- 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 . 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)")