mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-26 00:38:10 +00:00
parent
9d94c47fc8
commit
6be5b6ffad
@ -27,6 +27,7 @@ import tempfile
|
|||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from gns3server.utils import parse_version
|
from gns3server.utils import parse_version
|
||||||
from gns3server.utils.telnet_server import TelnetServer
|
from gns3server.utils.telnet_server import TelnetServer
|
||||||
@ -162,8 +163,8 @@ class VirtualBoxVM(BaseNode):
|
|||||||
|
|
||||||
if self.linked_clone:
|
if self.linked_clone:
|
||||||
if self.id and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
|
if self.id and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
|
||||||
vbox_file = os.path.join(self.working_dir, self._vmname, self._vmname + ".vbox")
|
self._patch_vm_uuid()
|
||||||
yield from self.manager.execute("registervm", [vbox_file])
|
yield from self.manager.execute("registervm", [self._linked_vbox_file()])
|
||||||
yield from self._reattach_linked_hdds()
|
yield from self._reattach_linked_hdds()
|
||||||
else:
|
else:
|
||||||
yield from self._create_linked_clone()
|
yield from self._create_linked_clone()
|
||||||
@ -175,6 +176,18 @@ class VirtualBoxVM(BaseNode):
|
|||||||
if "memory" in vm_info:
|
if "memory" in vm_info:
|
||||||
self._ram = int(vm_info["memory"])
|
self._ram = int(vm_info["memory"])
|
||||||
|
|
||||||
|
def _linked_vbox_file(self):
|
||||||
|
return os.path.join(self.working_dir, self._vmname, self._vmname + ".vbox")
|
||||||
|
|
||||||
|
def _patch_vm_uuid(self):
|
||||||
|
"""
|
||||||
|
Fix the VM uuid in the case of linked clone
|
||||||
|
"""
|
||||||
|
tree = ET.parse(self._linked_vbox_file())
|
||||||
|
machine = tree.getroot().find("{http://www.virtualbox.org/}Machine")
|
||||||
|
machine.set("uuid", "{" + self.id + "}")
|
||||||
|
tree.write(self._linked_vbox_file())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def check_hw_virtualization(self):
|
def check_hw_virtualization(self):
|
||||||
"""
|
"""
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
import asyncio
|
import asyncio
|
||||||
from tests.utils import asyncio_patch
|
from tests.utils import asyncio_patch
|
||||||
@ -67,3 +68,20 @@ def test_json(vm, tmpdir, project):
|
|||||||
project._path = str(tmpdir)
|
project._path = str(tmpdir)
|
||||||
vm._linked_clone = True
|
vm._linked_clone = True
|
||||||
assert vm.__json__()["node_directory"] is not None
|
assert vm.__json__()["node_directory"] is not None
|
||||||
|
|
||||||
|
|
||||||
|
def test_patch_vm_uuid(vm):
|
||||||
|
xml = """<?xml version="1.0"?>
|
||||||
|
<VirtualBox xmlns="http://www.virtualbox.org/" version="1.16-macosx">
|
||||||
|
<Machine uuid="{f8138a63-e361-49ee-a5a4-ba0559bc00e2}" name="Debian-1" OSType="Debian_64" currentSnapshot="{8bd00b14-4c14-4992-a165-cb09e80fe8e4 }" snapshotFolder="Snapshots" lastStateChange="2016-10-28T12:54:26Z">
|
||||||
|
</Machine>
|
||||||
|
</VirtualBox>
|
||||||
|
"""
|
||||||
|
os.makedirs(os.path.join(vm.working_dir, vm._vmname), exist_ok=True)
|
||||||
|
with open(vm._linked_vbox_file(), "w+") as f:
|
||||||
|
f.write(xml)
|
||||||
|
vm._linked_clone = True
|
||||||
|
vm._patch_vm_uuid()
|
||||||
|
with open(vm._linked_vbox_file()) as f:
|
||||||
|
c = f.read()
|
||||||
|
assert "{" + vm.id + "}" in c
|
||||||
|
Loading…
Reference in New Issue
Block a user