Skip to content

Commit 3f7f5a3

Browse files
committed
Fix to access resources_path and install_builtin_appliances settings
1 parent 59ad5c5 commit 3f7f5a3

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

gns3server/compute/docker/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,12 @@ def resources_path():
9696
Get the Docker resources storage directory
9797
"""
9898

99-
server_config = Config.instance().get_section_config("Server")
100-
appname = vendor = "GNS3"
101-
resources_path = os.path.expanduser(server_config.get("resources_path", platformdirs.user_data_dir(appname, vendor, roaming=True)))
99+
resources_path = Config.instance().settings.Server.resources_path
100+
if not resources_path:
101+
appname = vendor = "GNS3"
102+
resources_path = platformdirs.user_data_dir(appname, vendor, roaming=True)
103+
else:
104+
resources_path = os.path.expanduser(resources_path)
102105
docker_resources_dir = os.path.join(resources_path, "docker")
103106
os.makedirs(docker_resources_dir, exist_ok=True)
104107
return docker_resources_dir

gns3server/config_samples/gns3_server.conf

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ symbols_path = /home/gns3/GNS3/symbols
5252
; Path where custom configs are stored
5353
configs_path = /home/gns3/GNS3/configs
5454

55+
; Path where files like built-in appliances and Docker resources are stored
56+
; The default path is the local user data directory
57+
; (Linux: "~/.local/share/GNS3", macOS: "~/Library/Application Support/GNS3", Windows: "%APPDATA%\GNS3")
58+
; resources_path = /home/gns3/GNS3/resources
59+
5560
; Default symbol theme
5661
; Currently available themes are "Classic", Affinity-square-blue", "Affinity-square-red"
5762
; "Affinity-square-gray", "Affinity-circle-blue", "Affinity-circle-red" and "Affinity-circle-gray"
@@ -63,11 +68,6 @@ allow_raw_images = True
6368
; Option to automatically discover images in the images directory
6469
auto_discover_images = True
6570

66-
; Path where files like built-in appliances and Docker resources are stored
67-
; The default path is the local user data directory
68-
; (Linux: "~/.local/share/GNS3", macOS: "~/Library/Application Support/GNS3", Windows: "%APPDATA%\GNS3")
69-
; resources_path = /home/gns3/GNS3/resources
70-
7171
; Option to automatically send crash reports to the GNS3 team
7272
report_errors = True
7373

gns3server/controller/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ def _load_controller_vars(self):
271271
self._iou_license_settings["license_check"] = iou_config.license_check
272272

273273
# install the built-in appliances if needed
274-
# FIXME
275-
server_config = Config.instance().get_section_config("Server")
276-
if server_config.getboolean("install_builtin_appliances", True):
274+
if Config.instance().settings.Server.install_builtin_appliances:
277275
previous_version = controller_vars.get("version")
278276
log.info("Comparing controller version {} with config version {}".format(__version__, previous_version))
279277
builtin_appliances_path = self._appliance_manager.builtin_appliances_path()

gns3server/controller/appliance_manager.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ def builtin_appliances_path(self, delete_first=False):
100100
Get the built-in appliance storage directory
101101
"""
102102

103-
server_config = Config.instance().get_section_config("Server")
104-
appname = vendor = "GNS3"
105-
resources_path = os.path.expanduser(server_config.get("resources_path", platformdirs.user_data_dir(appname, vendor, roaming=True)))
103+
resources_path = Config.instance().settings.Server.resources_path
104+
if not resources_path:
105+
appname = vendor = "GNS3"
106+
resources_path = platformdirs.user_data_dir(appname, vendor, roaming=True)
107+
else:
108+
resources_path = os.path.expanduser(resources_path)
106109
appliances_dir = os.path.join(resources_path, "appliances")
107110
if delete_first:
108111
shutil.rmtree(appliances_dir, ignore_errors=True)

gns3server/schemas/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class ServerSettings(BaseModel):
127127
appliances_path: str = "~/GNS3/appliances"
128128
symbols_path: str = "~/GNS3/symbols"
129129
configs_path: str = "~/GNS3/configs"
130+
resources_path: str = None
130131
default_symbol_theme: BuiltinSymbolTheme = BuiltinSymbolTheme.affinity_square_blue
131132
allow_raw_images: bool = True
132133
auto_discover_images: bool = True
@@ -145,6 +146,7 @@ class ServerSettings(BaseModel):
145146
default_nat_interface: str = None
146147
allow_remote_console: bool = False
147148
enable_builtin_templates: bool = True
149+
install_builtin_appliances: bool = True
148150
model_config = ConfigDict(validate_assignment=True, str_strip_whitespace=True, use_enum_values=True)
149151

150152
@field_validator("additional_images_paths", mode="before")

0 commit comments

Comments
 (0)