From 4cd164fc2451ec05254a7409f7ef383680a37974 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 21 Sep 2016 17:01:50 +0200 Subject: [PATCH] Better management of the GNS3 VM with VirtualBox --- gns3server/controller/gns3vm/__init__.py | 11 ++++++---- .../controller/gns3vm/virtualbox_gns3_vm.py | 22 ++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/gns3server/controller/gns3vm/__init__.py b/gns3server/controller/gns3vm/__init__.py index b9dbd8ee..c4677cae 100644 --- a/gns3server/controller/gns3vm/__init__.py +++ b/gns3server/controller/gns3vm/__init__.py @@ -60,7 +60,8 @@ class GNS3VM: "engine_id": "vmware", "description": 'VMware is the recommended choice for best performances.
The GNS3 VM can be downloaded here.'.format(download_url), "support_when_exit": True, - "support_headless": True + "support_headless": True, + "support_ram": True } if sys.platform.startswith("darwin"): vmware_informations["name"] = "VMware Fusion" @@ -73,7 +74,8 @@ class GNS3VM: "name": "VirtualBox", "description": 'VirtualBox doesn\'t support nested virtualization, this means running Qemu based VM could be very slow.
The GNS3 VM can be downloaded here'.format(download_url), "support_when_exit": True, - "support_headless": True + "support_headless": True, + "support_ram": True } remote_informations = { @@ -81,7 +83,8 @@ class GNS3VM: "name": "Remote", "description": "Use a remote GNS3 server as the GNS3 VM.", "support_when_exit": False, - "support_headless": False + "support_headless": False, + "support_ram": False } return [ @@ -185,7 +188,7 @@ class GNS3VM: else: # When user fix something on his system and try again if not self._current_engine().running and self.enable: - yield from self.auto_start_vm() + yield from self.start() def _get_engine(self, engine): """ diff --git a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py index d0b081ea..41be00b8 100644 --- a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py +++ b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py @@ -243,7 +243,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM): if json_data: for interface in json_data: if "name" in interface and interface["name"] == "eth{}".format(hostonly_interface_number - 1): - if "ip_address" in interface: + if "ip_address" in interface and len(interface["ip_address"]) > 0: return interface["ip_address"] remaining_try -= 1 yield from asyncio.sleep(1) @@ -265,7 +265,27 @@ class VirtualBoxGNS3VM(BaseGNS3VM): Stops the GNS3 VM. """ + vm_state = yield from self._get_state() + if vm_state == "poweroff": + self.running = False + return + yield from self._execute("controlvm", [self._vmname, "acpipowerbutton"], timeout=3) + trial = 120 + while True: + try: + vm_state = yield from self._get_state() + # During a small amount of time the command will fail + except GNS3VMError: + vm_state = "running" + if vm_state == "poweroff": + break + trial -= 1 + if trial == 0: + yield from self._execute("controlvm", [self._vmname, "poweroff"], timeout=3) + break + yield from asyncio.sleep(1) + log.info("GNS3 VM has been stopped") self.running = False