1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-11 09:38:08 +00:00
gns3-server/gns3server/schemas/controller/templates/__init__.py

91 lines
2.1 KiB
Python
Raw Normal View History

2020-10-02 06:37:50 +00:00
#
# Copyright (C) 2021 GNS3 Technologies Inc.
2020-10-02 06:37:50 +00:00
#
# 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
2020-10-02 06:37:50 +00:00
from ..nodes import NodeType
from ..base import DateTimeModelMixin
2020-10-02 06:37:50 +00:00
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
2020-10-02 06:37:50 +00:00
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] = ""
2020-10-02 06:37:50 +00:00
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):
2020-10-02 06:37:50 +00:00
template_id: UUID
2020-10-02 06:37:50 +00:00
name: str
category: Category
symbol: str
builtin: bool
template_type: NodeType
compute_id: Union[str, None]
class Config:
orm_mode = True
2020-10-02 06:37:50 +00:00
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")