2017-04-12 12:35:49 +00:00
|
|
|
# -*- 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/>.
|
|
|
|
|
2018-11-11 12:13:58 +00:00
|
|
|
import copy
|
2018-11-15 10:28:17 +00:00
|
|
|
|
2018-11-28 09:12:57 +00:00
|
|
|
BASE_TEMPLATE_PROPERTIES = {
|
|
|
|
"template_id": {
|
|
|
|
"description": "Template UUID",
|
2018-11-17 11:12:46 +00:00
|
|
|
"type": "string",
|
2018-11-15 10:28:17 +00:00
|
|
|
"minLength": 36,
|
|
|
|
"maxLength": 36,
|
|
|
|
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
|
|
|
},
|
2018-11-28 09:12:57 +00:00
|
|
|
"template_type": {
|
2018-11-17 11:12:46 +00:00
|
|
|
"description": "Type of node",
|
|
|
|
"enum": ["cloud", "ethernet_hub", "ethernet_switch", "docker", "dynamips", "vpcs", "traceng",
|
|
|
|
"virtualbox", "vmware", "iou", "qemu"]
|
|
|
|
},
|
2018-11-15 10:28:17 +00:00
|
|
|
"name": {
|
2018-11-28 09:12:57 +00:00
|
|
|
"description": "Template name",
|
2018-11-15 10:28:17 +00:00
|
|
|
"type": "string",
|
|
|
|
"minLength": 1,
|
|
|
|
},
|
2018-11-16 16:02:10 +00:00
|
|
|
"compute_id": {
|
|
|
|
"description": "Compute identifier",
|
2019-08-26 09:48:03 +00:00
|
|
|
"type": ["null", "string"]
|
2018-11-16 16:02:10 +00:00
|
|
|
},
|
2018-11-15 10:28:17 +00:00
|
|
|
"default_name_format": {
|
|
|
|
"description": "Default name format",
|
|
|
|
"type": "string",
|
2018-11-16 16:02:10 +00:00
|
|
|
"minLength": 1
|
2018-11-15 10:28:17 +00:00
|
|
|
},
|
|
|
|
"symbol": {
|
2018-11-28 09:12:57 +00:00
|
|
|
"description": "Symbol of the template",
|
2018-11-15 10:28:17 +00:00
|
|
|
"type": "string",
|
|
|
|
"minLength": 1
|
|
|
|
},
|
2018-11-16 16:02:10 +00:00
|
|
|
"category": {
|
2018-11-28 09:12:57 +00:00
|
|
|
"description": "Template category",
|
2018-11-16 16:02:10 +00:00
|
|
|
"anyOf": [
|
|
|
|
{"type": "integer"}, # old category support
|
|
|
|
{"enum": ["router", "switch", "guest", "firewall"]}
|
|
|
|
]
|
|
|
|
},
|
2018-11-15 10:28:17 +00:00
|
|
|
"builtin": {
|
2018-11-28 09:12:57 +00:00
|
|
|
"description": "Template is builtin",
|
2018-11-15 10:28:17 +00:00
|
|
|
"type": "boolean"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-11-28 09:12:57 +00:00
|
|
|
TEMPLATE_OBJECT_SCHEMA = {
|
2018-11-11 12:13:58 +00:00
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
|
|
"description": "A template object",
|
|
|
|
"type": "object",
|
2018-11-28 09:12:57 +00:00
|
|
|
"properties": BASE_TEMPLATE_PROPERTIES,
|
|
|
|
"required": ["name", "template_type", "template_id", "category", "compute_id", "default_name_format", "symbol", "builtin"]
|
2018-11-11 12:13:58 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 09:12:57 +00:00
|
|
|
TEMPLATE_CREATE_SCHEMA = copy.deepcopy(TEMPLATE_OBJECT_SCHEMA)
|
2018-11-14 08:24:30 +00:00
|
|
|
|
|
|
|
# create schema
|
2018-11-28 09:12:57 +00:00
|
|
|
# these properties are not required to create a template
|
|
|
|
TEMPLATE_CREATE_SCHEMA["required"].remove("template_id")
|
|
|
|
TEMPLATE_CREATE_SCHEMA["required"].remove("category")
|
|
|
|
TEMPLATE_CREATE_SCHEMA["required"].remove("default_name_format")
|
|
|
|
TEMPLATE_CREATE_SCHEMA["required"].remove("symbol")
|
|
|
|
TEMPLATE_CREATE_SCHEMA["required"].remove("builtin")
|
2018-11-14 08:24:30 +00:00
|
|
|
|
|
|
|
# update schema
|
2018-11-28 09:12:57 +00:00
|
|
|
TEMPLATE_UPDATE_SCHEMA = copy.deepcopy(TEMPLATE_OBJECT_SCHEMA)
|
|
|
|
del TEMPLATE_UPDATE_SCHEMA["required"]
|
2017-04-12 12:35:49 +00:00
|
|
|
|
2018-11-28 09:12:57 +00:00
|
|
|
TEMPLATE_USAGE_SCHEMA = {
|
2017-04-12 12:35:49 +00:00
|
|
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
2018-11-28 09:12:57 +00:00
|
|
|
"description": "Request validation to use a Template instance",
|
2017-04-12 12:35:49 +00:00
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"x": {
|
|
|
|
"description": "X position",
|
|
|
|
"type": "integer"
|
|
|
|
},
|
|
|
|
"y": {
|
|
|
|
"description": "Y position",
|
|
|
|
"type": "integer"
|
|
|
|
},
|
2020-01-08 00:19:33 +00:00
|
|
|
"name": {
|
|
|
|
"description": "Use this name to create a new node",
|
|
|
|
"type": ["null", "string"]
|
|
|
|
},
|
2017-04-12 12:35:49 +00:00
|
|
|
"compute_id": {
|
2018-11-28 09:12:57 +00:00
|
|
|
"description": "If the template don't have a default compute use this compute",
|
2017-04-12 12:35:49 +00:00
|
|
|
"type": ["null", "string"]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"additionalProperties": False,
|
|
|
|
"required": ["x", "y"]
|
|
|
|
}
|