Skip to content

Commit

Permalink
Fix image uploading when image name differs with the image name recor…
Browse files Browse the repository at this point in the history
…ded in the appliance. Fixes #3682
  • Loading branch information
grossmj committed Dec 26, 2024
1 parent a5976a6 commit 141767e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gns3/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __fix_compute_id(self, compute_id):

def request(self, method, path, *args, **kwargs):
"""
Forward the query to the HTTP client or controller depending of the path
Forward the query to the HTTP client or controller depending on the path
"""

if self._http_client:
Expand Down
15 changes: 0 additions & 15 deletions gns3/dialogs/appliance_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,21 +551,6 @@ def _install(self, version):
TemplateManager.instance().createTemplate(Template(new_template), callback=self._templateCreatedCallback)
return False

#worker = WaitForLambdaWorker(lambda: self._create_template(appliance_configuration, self._compute_id), allowed_exceptions=[ConfigException, OSError])
#progress_dialog = ProgressDialog(worker, "Add template", "Installing a new template...", None, busy=True, parent=self)
#progress_dialog.show()
#if progress_dialog.exec_():
# QtWidgets.QMessageBox.information(self.parent(), "Add template", "{} template has been installed!".format(appliance_configuration["name"]))
# return True
#return False

# worker = WaitForLambdaWorker(lambda: config.save(), allowed_exceptions=[ConfigException, OSError])
# progress_dialog = ProgressDialog(worker, "Add appliance", "Install the appliance...", None, busy=True, parent=self)
# progress_dialog.show()
# if progress_dialog.exec_():
# QtWidgets.QMessageBox.information(self.parent(), "Add appliance", "{} installed!".format(appliance_configuration["name"]))
# return True

def _templateCreatedCallback(self, result, error=False, **kwargs):

if error is True:
Expand Down
2 changes: 1 addition & 1 deletion gns3/image_upload_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _fileUploadToController(self) -> bool:
except HttpClientError as e:
QtWidgets.QMessageBox.critical(
self._parent,
"Image upload",
"Image upload to controller",
f"Could not upload image {self._image.filename}: {e}"
)
return False
Expand Down
31 changes: 7 additions & 24 deletions gns3/registry/appliance_to_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _add_qemu_config(self, new_config, template_properties, appliance_config):

for image in appliance_config["images"]:
if image.get("path"):
new_config[image["type"]] = self._relative_image_path("QEMU", image["path"])
new_config[image["type"]] = image["filename"]

if "arch" in appliance_config:
new_config["platform"] = appliance_config["arch"]
Expand Down Expand Up @@ -188,38 +188,21 @@ def _add_dynamips_config(self, new_config, template_properties, appliance_config

new_config["template_type"] = "dynamips"
new_config.update(template_properties)

for image in appliance_config["images"]:
new_config[image["type"]] = self._relative_image_path("IOS", image["path"])
new_config[image["type"]] = image["filename"]
if self._registry_version < 8:
new_config["idlepc"] = image.get("idlepc", "")
if "image" not in new_config:
raise ConfigException("Disk image is missing")

def _add_iou_config(self, new_config, template_properties, appliance_config):

new_config["template_type"] = "iou"
new_config.update(template_properties)
for image in appliance_config["images"]:
if "path" not in image:
raise ConfigException("Disk image is missing")
new_config[image["type"]] = self._relative_image_path("IOU", image["path"])
new_config["path"] = new_config["image"]

def _relative_image_path(self, image_dir_type, path):
"""
:param image_dir_type: Type of image directory
:param filename: Filename at the end of the process
:param path: Full path to the file
:returns: Path relative to image directory.
Copy the image to the directory if not already in the directory
"""

images_dir = os.path.join(Config().images_dir, image_dir_type)
path = os.path.abspath(path)
if os.path.commonprefix([images_dir, path]) == images_dir:
return path.replace(images_dir, '').strip('/\\')

return os.path.basename(path)
new_config["path"] = image["filename"]
if "path" not in new_config:
raise ConfigException("Disk image is missing")

def _set_symbol(self, symbol_id, controller_symbols):
"""
Expand Down

0 comments on commit 141767e

Please sign in to comment.