From 84a2f8b4a33e24be0cbb06d670f5c23f6fcd05a5 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 14 Sep 2016 17:15:06 +0200 Subject: [PATCH] Return flag for special interface that you can use in the cloud Fix https://github.com/GNS3/gns3-gui/issues/1509 --- gns3server/compute/builtin/nodes/cloud.py | 3 ++- gns3server/schemas/cloud.py | 7 ++++++- gns3server/utils/interfaces.py | 7 +++++++ tests/utils/test_interfaces.py | 6 +++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gns3server/compute/builtin/nodes/cloud.py b/gns3server/compute/builtin/nodes/cloud.py index b3349999..949d6aeb 100644 --- a/gns3server/compute/builtin/nodes/cloud.py +++ b/gns3server/compute/builtin/nodes/cloud.py @@ -55,7 +55,8 @@ class Cloud(BaseNode): network_interfaces = interfaces() for interface in network_interfaces: host_interfaces.append({"name": interface["name"], - "type": interface["type"]}) + "type": interface["type"], + "special": interface["special"]}) return {"name": self.name, "node_id": self.id, diff --git a/gns3server/schemas/cloud.py b/gns3server/schemas/cloud.py index 16978cb3..f5c23508 100644 --- a/gns3server/schemas/cloud.py +++ b/gns3server/schemas/cloud.py @@ -26,10 +26,15 @@ HOST_INTERFACE_SCHEMA = { "minLength": 1, }, "type": { + "description": "Interface type", "enum": ["ethernet", "tap"] }, + "special": { + "description": "If true the interface is non standard (firewire for example)", + "type": "boolean" + } }, - "required": ["name", "type"], + "required": ["name", "type", "special"], "additionalProperties": False } diff --git a/gns3server/utils/interfaces.py b/gns3server/utils/interfaces.py index 16f29c38..877670c9 100644 --- a/gns3server/utils/interfaces.py +++ b/gns3server/utils/interfaces.py @@ -205,4 +205,11 @@ def interfaces(): if service_installed is False: raise aiohttp.web.HTTPInternalServerError(text="The Winpcap or Npcap is not installed or running") + # This interface have special behavior + for result in results: + result["special"] = False + for special_interface in ("lo", "vmnet", "vboxnet", "docker", "lxcbr", "virbr", "ovs-system", "veth", "fw", "p2p"): + if result["name"].lower().startswith(special_interface): + result["special"] = True + return results diff --git a/tests/utils/test_interfaces.py b/tests/utils/test_interfaces.py index 153639dc..f9d75963 100644 --- a/tests/utils/test_interfaces.py +++ b/tests/utils/test_interfaces.py @@ -22,7 +22,11 @@ from gns3server.utils.interfaces import interfaces, is_interface_up def test_interfaces(): # This test should pass on all platforms without crash - assert isinstance(interfaces(), list) + interface_list = interfaces() + assert isinstance(interface_list, list) + for interface in interface_list: + if interface["name"].startswith("vmnet"): + assert interface["special"] def test_is_interface_up():