From a8ffaa9cb543675093cb5eb645e350a8411e84d6 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 17 Oct 2016 18:20:29 +0200 Subject: [PATCH] If listen on all interface do not return localhost as console Fix https://github.com/GNS3/gns3-gui/issues/1574 --- gns3server/controller/compute.py | 12 ++++++++++-- gns3server/schemas/node.py | 2 +- tests/controller/test_compute.py | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index 242a6699..7a2873dc 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -411,8 +411,16 @@ class Compute: def _getUrl(self, path): host = self._host # IPV6 - if host and ":" in host: - host = "[{}]".format(host) + if host: + # IPV6 + if ":" in host: + # Reduce IPV6 to his simple form + host = str(ipaddress.IPv6Address(host)) + if host == "::": + host = "::1" + host = "[{}]".format(host) + elif host == "0.0.0.0": + host = "127.0.0.1" return "{}://{}:{}/v2/compute{}".format(self._protocol, host, self._port, path) @asyncio.coroutine diff --git a/gns3server/schemas/node.py b/gns3server/schemas/node.py index cd57e413..d1eb2715 100644 --- a/gns3server/schemas/node.py +++ b/gns3server/schemas/node.py @@ -127,7 +127,7 @@ NODE_OBJECT_SCHEMA = { "type": ["integer", "null"] }, "console_host": { - "description": "Console host", + "description": "Console host. Warning if the host is 0.0.0.0 or :: (listen on all interfaces) you need to use the same address you use to connect to the controller.", "type": "string", "minLength": 1, }, diff --git a/tests/controller/test_compute.py b/tests/controller/test_compute.py index 14826050..bad0e6c4 100644 --- a/tests/controller/test_compute.py +++ b/tests/controller/test_compute.py @@ -43,9 +43,17 @@ def test_init(compute): def test_getUrl(controller): compute = Compute("my_compute_id", protocol="https", host="localhost", port=84, controller=controller) assert compute._getUrl("/test") == "https://localhost:84/v2/compute/test" + # IPV6 localhost compute = Compute("my_compute_id", protocol="https", host="::1", port=84, controller=controller) assert compute._getUrl("/test") == "https://[::1]:84/v2/compute/test" + # Listen on all interfaces aka 0.0.0.0 require us to connect via 127.0.0.1 + compute = Compute("my_compute_id", protocol="https", host="0.0.0.0", port=84, controller=controller) + assert compute._getUrl("/test") == "https://127.0.0.1:84/v2/compute/test" + # IPV6 + compute = Compute("my_compute_id", protocol="https", host="::", port=84, controller=controller) + assert compute._getUrl("/test") == "https://[::1]:84/v2/compute/test" + def test_host_ip(controller): compute = Compute("my_compute_id", protocol="https", host="localhost", port=84, controller=controller)