From 67bf14776f719ec08d2d0b49a5eb218e31b6af41 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 15 Jun 2022 14:48:52 +0200 Subject: [PATCH] Config option to disable built-in templates --- conf/gns3_server.conf | 3 +++ gns3server/controller/template_manager.py | 16 +++++++++------- tests/controller/test_controller.py | 10 ++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/conf/gns3_server.conf b/conf/gns3_server.conf index af7b1edd..9f9e02dc 100644 --- a/conf/gns3_server.conf +++ b/conf/gns3_server.conf @@ -59,6 +59,9 @@ allowed_interfaces = eth0,eth1,virbr0 ; Default is virbr0 on Linux (requires libvirt) and vmnet8 for other platforms (requires VMware) default_nat_interface = vmnet10 +; Enable the built-in templates +enable_builtin_templates = True + [VPCS] ; VPCS executable location, default: search in PATH ;vpcs_path = vpcs diff --git a/gns3server/controller/template_manager.py b/gns3server/controller/template_manager.py index b7c14bcb..b3224188 100644 --- a/gns3server/controller/template_manager.py +++ b/gns3server/controller/template_manager.py @@ -21,6 +21,7 @@ import aiohttp import jsonschema from .template import Template +from gns3server.config import Config import logging log = logging.getLogger(__name__) @@ -60,13 +61,14 @@ class TemplateManager: # Add builtins builtins = [] - builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "cloud"), {"template_type": "cloud", "name": "Cloud", "default_name_format": "Cloud{0}", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True)) - builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "nat"), {"template_type": "nat", "name": "NAT", "default_name_format": "NAT{0}", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True)) - builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "vpcs"), {"template_type": "vpcs", "name": "VPCS", "default_name_format": "PC{0}", "category": 2, "symbol": ":/symbols/vpcs_guest.svg", "properties": {"base_script_file": "vpcs_base_config.txt"}}, builtin=True)) - builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_switch"), {"template_type": "ethernet_switch", "console_type": "none", "name": "Ethernet switch", "default_name_format": "Switch{0}", "category": 1, "symbol": ":/symbols/ethernet_switch.svg"}, builtin=True)) - builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_hub"), {"template_type": "ethernet_hub", "name": "Ethernet hub", "default_name_format": "Hub{0}", "category": 1, "symbol": ":/symbols/hub.svg"}, builtin=True)) - builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "frame_relay_switch"), {"template_type": "frame_relay_switch", "name": "Frame Relay switch", "default_name_format": "FRSW{0}", "category": 1, "symbol": ":/symbols/frame_relay_switch.svg"}, builtin=True)) - builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "atm_switch"), {"template_type": "atm_switch", "name": "ATM switch", "default_name_format": "ATMSW{0}", "category": 1, "symbol": ":/symbols/atm_switch.svg"}, builtin=True)) + if Config.instance().get_section_config("Server").getboolean("enable_builtin_templates", True): + builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "cloud"), {"template_type": "cloud", "name": "Cloud", "default_name_format": "Cloud{0}", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True)) + builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "nat"), {"template_type": "nat", "name": "NAT", "default_name_format": "NAT{0}", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True)) + builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "vpcs"), {"template_type": "vpcs", "name": "VPCS", "default_name_format": "PC{0}", "category": 2, "symbol": ":/symbols/vpcs_guest.svg", "properties": {"base_script_file": "vpcs_base_config.txt"}}, builtin=True)) + builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_switch"), {"template_type": "ethernet_switch", "console_type": "none", "name": "Ethernet switch", "default_name_format": "Switch{0}", "category": 1, "symbol": ":/symbols/ethernet_switch.svg"}, builtin=True)) + builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_hub"), {"template_type": "ethernet_hub", "name": "Ethernet hub", "default_name_format": "Hub{0}", "category": 1, "symbol": ":/symbols/hub.svg"}, builtin=True)) + builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "frame_relay_switch"), {"template_type": "frame_relay_switch", "name": "Frame Relay switch", "default_name_format": "FRSW{0}", "category": 1, "symbol": ":/symbols/frame_relay_switch.svg"}, builtin=True)) + builtins.append(Template(uuid.uuid3(uuid.NAMESPACE_DNS, "atm_switch"), {"template_type": "atm_switch", "name": "ATM switch", "default_name_format": "ATMSW{0}", "category": 1, "symbol": ":/symbols/atm_switch.svg"}, builtin=True)) #FIXME: disable TraceNG #if sys.platform.startswith("win"): diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py index a9490170..48b8d98d 100644 --- a/tests/controller/test_controller.py +++ b/tests/controller/test_controller.py @@ -24,6 +24,7 @@ import aiohttp from unittest.mock import MagicMock, patch from tests.utils import AsyncioMagicMock, asyncio_patch +from gns3server.config import Config from gns3server.controller.compute import Compute from gns3server.version import __version__ @@ -451,6 +452,15 @@ def test_load_templates(controller): assert cloud_uuid == template.id +def test_load_templates_without_builtins(controller): + + config = Config.instance() + config.set("Server", "enable_builtin_templates", False) + controller.template_manager.load_templates() + + assert not controller.template_manager.templates.values() + + async def test_autoidlepc(controller): controller._computes["local"] = AsyncioMagicMock()