diff --git a/gns3server/compute/docker/docker_vm.py b/gns3server/compute/docker/docker_vm.py index bd94e86e..dc04c1d6 100644 --- a/gns3server/compute/docker/docker_vm.py +++ b/gns3server/compute/docker/docker_vm.py @@ -488,8 +488,8 @@ class DockerVM(BaseNode): params["Env"].append(f"DISPLAY=:{self._display}") params["HostConfig"]["Mounts"].append({ "Type": "bind", - "Source": "/tmp/.X11-unix/", - "Target": "/tmp/.X11-unix/" + "Source": f"/tmp/.X11-unix/X{self._display}", + "Target": f"/tmp/.X11-unix/X{self._display}" }) if self._extra_hosts: diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 7568b569..2d06ca8d 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -270,9 +270,12 @@ class Controller: log.error(f"Cannot read IOU license file '{iourc_path}': {e}") self._iou_license_settings["license_check"] = iou_config.license_check - current_version = __version__.split("+")[0] - previous_version = controller_vars.get("version", "").split("+")[0] - if not previous_version or parse_version(current_version) > parse_version(previous_version): + previous_version = controller_settings.get("version") + log.info("Comparing controller version {} with config version {}".format(__version__, previous_version)) + if not previous_version or \ + parse_version(__version__.split("+")[0]) > parse_version(previous_version.split("+")[0]): + self._appliance_manager.install_builtin_appliances() + elif not os.listdir(self._appliance_manager.builtin_appliances_path()): self._appliance_manager.install_builtin_appliances() self._appliance_manager.appliances_etag = controller_vars.get("appliances_etag") diff --git a/gns3server/controller/appliance_manager.py b/gns3server/controller/appliance_manager.py index ac8bd7fd..99a3377b 100644 --- a/gns3server/controller/appliance_manager.py +++ b/gns3server/controller/appliance_manager.py @@ -21,6 +21,7 @@ import json import asyncio import aiofiles import shutil +import platformdirs from typing import Tuple, List @@ -94,13 +95,13 @@ class ApplianceManager: os.makedirs(appliances_path, exist_ok=True) return appliances_path - def _builtin_appliances_path(self, delete_first=False): + def builtin_appliances_path(self, delete_first=False): """ Get the built-in appliance storage directory """ - config = Config.instance() - appliances_dir = os.path.join(config.config_dir, "appliances") + appname = vendor = "GNS3" + appliances_dir = os.path.join(platformdirs.user_data_dir(appname, vendor, roaming=True), "appliances") if delete_first: shutil.rmtree(appliances_dir, ignore_errors=True) os.makedirs(appliances_dir, exist_ok=True) @@ -111,7 +112,7 @@ class ApplianceManager: At startup we copy the built-in appliances files. """ - dst_path = self._builtin_appliances_path(delete_first=True) + dst_path = self.builtin_appliances_path(delete_first=True) log.info(f"Installing built-in appliances in '{dst_path}'") from . import Controller try: @@ -316,7 +317,7 @@ class ApplianceManager: self._appliances = {} for directory, builtin in ( ( - self._builtin_appliances_path(), + self.builtin_appliances_path(), True, ), ( @@ -434,7 +435,7 @@ class ApplianceManager: Controller.instance().save() json_data = await response.json() - appliances_dir = self._builtin_appliances_path() + appliances_dir = self.builtin_appliances_path() downloaded_appliance_files = [] for appliance in json_data: if appliance["type"] == "file": diff --git a/requirements.txt b/requirements.txt index 1c5b44b2..2f8880f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,4 +18,5 @@ python-jose==3.3.0 email-validator==2.0.0.post2 watchfiles==0.20.0 zstandard==0.21.0 +platformdirs==2.4.0 importlib_resources>=1.3 diff --git a/tests/compute/docker/test_docker_vm.py b/tests/compute/docker/test_docker_vm.py index 273b119b..58ce7e0e 100644 --- a/tests/compute/docker/test_docker_vm.py +++ b/tests/compute/docker/test_docker_vm.py @@ -222,8 +222,9 @@ async def test_create_vnc(compute_project, manager): }, { "Type": "bind", - "Source": "/tmp/.X11-unix/", - "Target": "/tmp/.X11-unix/" + "Source": f"/tmp/.X11-unix/X{vm._display}", + "Target": f"/tmp/.X11-unix/X{vm._display}", + "ReadOnly": True } ], "Privileged": True,