diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index cb0d9947..242a6699 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -409,7 +409,11 @@ class Compute: self._controller.notification.emit("compute.updated", self.__json__()) def _getUrl(self, path): - return "{}://{}:{}/v2/compute{}".format(self._protocol, self._host, self._port, path) + host = self._host + # IPV6 + if host and ":" in host: + host = "[{}]".format(host) + return "{}://{}:{}/v2/compute{}".format(self._protocol, host, self._port, path) @asyncio.coroutine def _run_http_query(self, method, path, data=None, timeout=10, raw=False): diff --git a/tests/controller/test_compute.py b/tests/controller/test_compute.py index 7f3fe791..14826050 100644 --- a/tests/controller/test_compute.py +++ b/tests/controller/test_compute.py @@ -40,6 +40,13 @@ def test_init(compute): assert compute.id == "my_compute_id" +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" + compute = Compute("my_compute_id", protocol="https", host="::1", 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) assert compute.host_ip == "127.0.0.1" @@ -92,7 +99,6 @@ def test_compute_httpQueryNotConnected(compute, controller, async_run): controller.notification.emit.assert_called_with("compute.updated", compute.__json__()) - def test_compute_httpQueryNotConnectedGNS3vmNotRunning(compute, controller, async_run): """ We are not connected to the remote and it's a GNS3 VM. So we need to start it @@ -117,8 +123,6 @@ def test_compute_httpQueryNotConnectedGNS3vmNotRunning(compute, controller, asyn controller.notification.emit.assert_called_with("compute.updated", compute.__json__()) - - def test_compute_httpQueryNotConnectedInvalidVersion(compute, async_run): compute._connected = False response = AsyncioMagicMock()