From 0dbd92db1156049e18ce4ec352146cc4b36da81e Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 13 Feb 2017 19:11:29 +0100 Subject: [PATCH] Fix disk lost when save as a project using linked clone VirtualBox Fix https://github.com/GNS3/gns3-gui/issues/1824 --- .../compute/virtualbox/virtualbox_vm.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gns3server/compute/virtualbox/virtualbox_vm.py b/gns3server/compute/virtualbox/virtualbox_vm.py index 801988e25..e1d520dc4 100644 --- a/gns3server/compute/virtualbox/virtualbox_vm.py +++ b/gns3server/compute/virtualbox/virtualbox_vm.py @@ -19,14 +19,16 @@ VirtualBox VM instance. """ -import sys -import shlex import re import os -import tempfile +import sys import json +import uuid +import shlex +import shutil import socket import asyncio +import tempfile import xml.etree.ElementTree as ET from gns3server.utils import parse_version @@ -209,7 +211,16 @@ class VirtualBoxVM(BaseNode): if os.path.exists(self._linked_vbox_file()): tree = ET.parse(self._linked_vbox_file()) machine = tree.getroot().find("{http://www.virtualbox.org/}Machine") - if machine is not None: + if machine is not None and machine.get("uuid") != "{" + self.id + "}": + + for image in tree.getroot().findall("{http://www.virtualbox.org/}Image"): + currentSnapshot = machine.get("currentSnapshot") + if currentSnapshot: + newSnapshot = re.sub("\{.*\}", "{" + str(uuid.uuid4()) + "}", currentSnapshot) + shutil.move(os.path.join(self.working_dir, self._vmname, "Snapshots", currentSnapshot) + ".vdi", + os.path.join(self.working_dir, self._vmname, "Snapshots", newSnapshot) + ".vdi") + image.set("uuid", newSnapshot) + machine.set("uuid", "{" + self.id + "}") tree.write(self._linked_vbox_file())