mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-22 17:33:49 +02:00
Add more information when patching .vbox file. Ref https://github.com/GNS3/gns3-gui/issues/3542
This commit is contained in:
parent
ccc8974d92
commit
bd58196817
@ -218,14 +218,18 @@ class VirtualBoxVM(BaseNode):
|
||||
"""
|
||||
Fix the VM uuid in the case of linked clone
|
||||
"""
|
||||
if os.path.exists(self._linked_vbox_file()):
|
||||
|
||||
linked_vbox_file = self._linked_vbox_file()
|
||||
if not os.path.exists(linked_vbox_file):
|
||||
raise VirtualBoxError("Cannot find VirtualBox linked node file: {}".format(linked_vbox_file))
|
||||
|
||||
try:
|
||||
tree = ET.parse(self._linked_vbox_file())
|
||||
tree = ET.parse(linked_vbox_file)
|
||||
except ET.ParseError:
|
||||
raise VirtualBoxError("Cannot modify VirtualBox linked nodes file. "
|
||||
"File {} is corrupted.".format(self._linked_vbox_file()))
|
||||
raise VirtualBoxError("Cannot modify VirtualBox linked node file. "
|
||||
"File {} is corrupted.".format(linked_vbox_file))
|
||||
except OSError as e:
|
||||
raise VirtualBoxError("Cannot modify VirtualBox linked nodes file '{}': {}".format(self._linked_vbox_file(), e))
|
||||
raise VirtualBoxError("Cannot modify VirtualBox linked node file '{}': {}".format(linked_vbox_file, e))
|
||||
|
||||
machine = tree.getroot().find("{http://www.virtualbox.org/}Machine")
|
||||
if machine is not None and machine.get("uuid") != "{" + self.id + "}":
|
||||
@ -234,12 +238,25 @@ class VirtualBoxVM(BaseNode):
|
||||
currentSnapshot = machine.get("currentSnapshot")
|
||||
if currentSnapshot:
|
||||
newSnapshot = re.sub(r"\{.*\}", "{" + 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")
|
||||
shutil.move(
|
||||
os.path.join(self.working_dir, self._vmname, "Snapshots", currentSnapshot) + ".vdi",
|
||||
os.path.join(self.working_dir, self._vmname, "Snapshots", newSnapshot) + ".vdi"
|
||||
)
|
||||
log.info("VirtualBox VM '{name}' [{id}] snapshot file moved from '{current}' to '{new}'".format(
|
||||
name=self.name,
|
||||
id=self.id,
|
||||
current=currentSnapshot,
|
||||
new=newSnapshot,
|
||||
))
|
||||
image.set("uuid", newSnapshot)
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{id}] '{vbox_file}' has been patched".format(
|
||||
name=self.name,
|
||||
id=self.id,
|
||||
vbox_file=linked_vbox_file,
|
||||
))
|
||||
machine.set("uuid", "{" + self.id + "}")
|
||||
tree.write(self._linked_vbox_file())
|
||||
tree.write(linked_vbox_file)
|
||||
|
||||
async def check_hw_virtualization(self):
|
||||
"""
|
||||
@ -458,7 +475,7 @@ class VirtualBoxVM(BaseNode):
|
||||
|
||||
async def save_linked_hdds_info(self):
|
||||
"""
|
||||
Save linked cloned hard disks information.
|
||||
Save linked cloned hard disk information.
|
||||
|
||||
:returns: disk table information
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user