diff --git a/gns3server/modules/vmware/vmware_vm.py b/gns3server/modules/vmware/vmware_vm.py index 79cc2bf7..be1f352f 100644 --- a/gns3server/modules/vmware/vmware_vm.py +++ b/gns3server/modules/vmware/vmware_vm.py @@ -28,6 +28,7 @@ import tempfile from pkg_resources import parse_version from gns3server.ubridge.hypervisor import Hypervisor +from gns3server.ubridge.ubridge_error import UbridgeError from gns3server.utils.telnet_server import TelnetServer from gns3server.utils.interfaces import get_windows_interfaces from collections import OrderedDict @@ -357,6 +358,8 @@ class VMwareVM(BaseVM): if not ubridge_path or not os.path.isfile(ubridge_path): raise VMwareError("ubridge is necessary to start a VMware VM") + yield from self._start_ubridge() + try: self._vmx_pairs = self.manager.parse_vmware_file(self._vmx_path) except OSError as e: @@ -375,7 +378,6 @@ class VMwareVM(BaseVM): else: yield from self._control_vm("start") - yield from self._start_ubridge() for adapter_number in range(0, self._adapters): nio = self._ethernet_adapters[adapter_number].get_nio(0) if nio: diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/modules/vpcs/vpcs_vm.py index 6b8a878c..11074783 100644 --- a/gns3server/modules/vpcs/vpcs_vm.py +++ b/gns3server/modules/vpcs/vpcs_vm.py @@ -27,16 +27,16 @@ import signal import re import asyncio import shutil -import gns3server.utils.asyncio +from gns3server.utils.asyncio import wait_for_process_termination +from gns3server.utils.asyncio import monitor_process +from gns3server.utils.asyncio import subprocess_check_output from pkg_resources import parse_version from .vpcs_error import VPCSError from ..adapters.ethernet_adapter import EthernetAdapter from ..nios.nio_udp import NIOUDP from ..nios.nio_tap import NIOTAP from ..base_vm import BaseVM -from ...utils.asyncio import subprocess_check_output, monitor_process - import logging log = logging.getLogger(__name__) @@ -268,7 +268,7 @@ class VPCSVM(BaseVM): self._terminate_process() if self._process.returncode is None: try: - yield from gns3server.utils.asyncio.wait_for_process_termination(self._process, timeout=3) + yield from wait_for_process_termination(self._process, timeout=3) except asyncio.TimeoutError: if self._process.returncode is None: log.warn("VPCS process {} is still running... killing it".format(self._process.pid)) diff --git a/gns3server/ubridge/hypervisor.py b/gns3server/ubridge/hypervisor.py index fd765ac2..ed1b4e0e 100644 --- a/gns3server/ubridge/hypervisor.py +++ b/gns3server/ubridge/hypervisor.py @@ -23,9 +23,12 @@ import os import subprocess import asyncio import socket +import re +from pkg_resources import parse_version from gns3server.utils.asyncio import wait_for_process_termination from gns3server.utils.asyncio import monitor_process +from gns3server.utils.asyncio import subprocess_check_output from .ubridge_hypervisor import UBridgeHypervisor from .ubridge_error import UbridgeError @@ -114,14 +117,31 @@ class Hypervisor(UBridgeHypervisor): self._path = path + @asyncio.coroutine + def _check_ubridge_version(self): + """ + Checks if the ubridge executable version is >= 0.9.1 + """ + try: + output = yield from subprocess_check_output(self._path, "-v", cwd=self._working_dir) + match = re.search("ubridge version ([0-9a-z\.]+)", output) + if match: + version = match.group(1) + if parse_version(version) < parse_version("0.9.1"): + raise UbridgeError("uBridge executable version must be >= 0.9.1") + else: + raise UbridgeError("Could not determine uBridge version for {}".format(self._path)) + except (OSError, subprocess.SubprocessError) as e: + raise UbridgeError("Error while looking for uBridge version: {}".format(e)) + @asyncio.coroutine def start(self): """ Starts the uBridge hypervisor process. """ + yield from self._check_ubridge_version() try: - # self._update_ubridge_config() command = self._build_command() log.info("starting ubridge: {}".format(command)) self._stdout_file = os.path.join(self._working_dir, "ubridge.log") diff --git a/gns3server/web/route.py b/gns3server/web/route.py index 017e0fd0..bd78a120 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -26,6 +26,7 @@ import traceback log = logging.getLogger(__name__) from ..modules.vm_error import VMError +from ..ubridge.ubridge_error import UbridgeError from .response import Response from ..crash_report import CrashReport from ..config import Config @@ -179,7 +180,7 @@ class Route(object): response = Response(request=request, route=route) response.set_status(e.status) response.json({"message": e.text, "status": e.status}) - except VMError as e: + except (VMError, UbridgeError) as e: log.error("VM error detected: {type}".format(type=type(e)), exc_info=1) response = Response(request=request, route=route) response.set_status(409)