From 36d2e80d0af86c045e887661cdb8e1bb3cb568da Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 29 Aug 2016 18:31:33 +0200 Subject: [PATCH] Nat node is only on the GNS3 VM for the moment Fix https://github.com/GNS3/gns3-gui/issues/1448 --- gns3server/compute/builtin/__init__.py | 7 +++++-- gns3server/compute/builtin/nodes/nat.py | 4 ++++ tests/handlers/api/compute/test_capabilities.py | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gns3server/compute/builtin/__init__.py b/gns3server/compute/builtin/__init__.py index af1019a8..2bef75c6 100644 --- a/gns3server/compute/builtin/__init__.py +++ b/gns3server/compute/builtin/__init__.py @@ -21,7 +21,7 @@ Builtin nodes server module. from ..base_manager import BaseManager -from .builtin_node_factory import BuiltinNodeFactory +from .builtin_node_factory import BuiltinNodeFactory, BUILTIN_NODES import logging log = logging.getLogger(__name__) @@ -40,4 +40,7 @@ class Builtin(BaseManager): """ :returns: List of node type supported by this class and computer """ - return ['cloud', 'nat', 'ethernet_hub', 'ethernet_switch'] + types = ['cloud', 'ethernet_hub', 'ethernet_switch'] + if BUILTIN_NODES['nat'].is_supported(): + types.append('nat') + return types diff --git a/gns3server/compute/builtin/nodes/nat.py b/gns3server/compute/builtin/nodes/nat.py index 742eeddd..b54e78d6 100644 --- a/gns3server/compute/builtin/nodes/nat.py +++ b/gns3server/compute/builtin/nodes/nat.py @@ -41,6 +41,10 @@ class Nat(Cloud): } ] + @classmethod + def is_supported(self): + return socket.gethostname() == "gns3vm" + def __json__(self): return { "name": self.name, diff --git a/tests/handlers/api/compute/test_capabilities.py b/tests/handlers/api/compute/test_capabilities.py index c76c0cc1..4852ae1a 100644 --- a/tests/handlers/api/compute/test_capabilities.py +++ b/tests/handlers/api/compute/test_capabilities.py @@ -26,6 +26,15 @@ from gns3server.version import __version__ def test_get(http_compute): + """ + Nat is not supported outside the GNS3VM + """ response = http_compute.get('/capabilities', example=True) assert response.status == 200 - assert response.json == {'node_types': ['cloud', 'nat', 'ethernet_hub', 'ethernet_switch', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou'], 'version': __version__} + assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou'], 'version': __version__} + + +def test_get_on_gns3vm(http_compute, on_gns3vm): + response = http_compute.get('/capabilities', example=True) + assert response.status == 200 + assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou'], 'version': __version__}