1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Check for uBridge version and catch uBridge errors.

This commit is contained in:
Jeremy 2015-07-21 17:58:53 -06:00
parent f0649b4ac3
commit fc0409286b
4 changed files with 30 additions and 7 deletions

View File

@ -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:

View File

@ -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))

View File

@ -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")

View File

@ -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)