1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-30 18:50:58 +00:00

Fixes bug with VMware VM connections + moves some uBridge code to BaseVM.

This commit is contained in:
grossmj 2015-09-13 14:52:25 -06:00
parent 0ee31361c0
commit 65fa4036c6
3 changed files with 63 additions and 34 deletions

View File

@ -22,9 +22,12 @@ import shutil
import asyncio
import tempfile
from pkg_resources import parse_version
from ..utils.asyncio import wait_run_in_executor
from ..ubridge.hypervisor import Hypervisor
from .vm_error import VMError
log = logging.getLogger(__name__)
@ -50,6 +53,7 @@ class BaseVM:
self._console_type = console_type
self._temporary_directory = None
self._hw_virtualization = False
self._ubridge_hypervisor = None
self._vm_status = "stopped"
if self._console is not None:
@ -264,6 +268,36 @@ class BaseVM:
id=self.id,
console_type=console_type))
@property
def ubridge_path(self):
"""
Returns the uBridge executable path.
:returns: path to uBridge
"""
path = self._manager.config.get_section_config("Server").get("ubridge_path", "ubridge")
if path == "ubridge":
path = shutil.which("ubridge")
return path
@asyncio.coroutine
def _start_ubridge(self):
"""
Starts uBridge (handles connections to and from this VMware VM).
"""
server_config = self._manager.config.get_section_config("Server")
server_host = server_config.get("host")
self._ubridge_hypervisor = Hypervisor(self._project, self.ubridge_path, self.working_dir, server_host)
log.info("Starting new uBridge hypervisor {}:{}".format(self._ubridge_hypervisor.host, self._ubridge_hypervisor.port))
yield from self._ubridge_hypervisor.start()
log.info("Hypervisor {}:{} has successfully started".format(self._ubridge_hypervisor.host, self._ubridge_hypervisor.port))
yield from self._ubridge_hypervisor.connect()
if parse_version(self._ubridge_hypervisor.version) < parse_version('0.9.2'):
raise VMError("uBridge version must be >= 0.9.2, detected version is {}".format(self._ubridge_hypervisor.version))
@property
def hw_virtualization(self):
"""

View File

@ -19,6 +19,8 @@
Base interface for NIOs.
"""
import uuid
class NIO(object):
@ -28,6 +30,8 @@ class NIO(object):
def __init__(self):
# create an unique name
self._name = 'nio-{}'.format(uuid.uuid4())
self._capturing = False
self._pcap_output_file = ""
self._pcap_data_link_type = ""
@ -74,3 +78,23 @@ class NIO(object):
"""
return self._pcap_data_link_type
def __str__(self):
"""
NIO string representation.
:returns: NIO name
"""
return self._name
@property
def name(self):
"""
Returns the NIO name.
:returns: NIO name
"""
return self._name

View File

@ -22,12 +22,9 @@ VMware VM instance.
import sys
import os
import socket
import shutil
import asyncio
import tempfile
from pkg_resources import parse_version
from gns3server.ubridge.hypervisor import Hypervisor
from gns3server.utils.telnet_server import TelnetServer
from gns3server.utils.interfaces import get_windows_interfaces
from collections import OrderedDict
@ -57,7 +54,6 @@ class VMwareVM(BaseVM):
self._linked_clone = linked_clone
self._vmx_pairs = OrderedDict()
self._ubridge_hypervisor = None
self._telnet_server_thread = None
self._serial_pipe = None
self._vmnets = []
@ -283,6 +279,11 @@ class VMwareVM(BaseVM):
if not vmnet in self._vmnets:
self._vmnets.append(vmnet)
self._vmx_pairs["ethernet{}.vnet".format(adapter_number)] = vmnet
else:
# not connected to anything...
vnet = "ethernet{}.vnet".format(adapter_number)
if vnet not in self._vmx_pairs:
self._vmx_pairs["ethernet{}.startconnected".format(adapter_number)] = "FALSE"
# disable remaining network adapters
for adapter_number in range(self._adapters, self._maximum_adapters):
@ -380,36 +381,6 @@ class VMwareVM(BaseVM):
raise VMwareError("vnet {} not in VMX file".format(vnet))
yield from self._ubridge_hypervisor.send("bridge stop_capture {name}".format(name=vnet))
@property
def ubridge_path(self):
"""
Returns the uBridge executable path.
:returns: path to uBridge
"""
path = self._manager.config.get_section_config("Server").get("ubridge_path", "ubridge")
if path == "ubridge":
path = shutil.which("ubridge")
return path
@asyncio.coroutine
def _start_ubridge(self):
"""
Starts uBridge (handles connections to and from this VMware VM).
"""
server_config = self._manager.config.get_section_config("Server")
server_host = server_config.get("host")
self._ubridge_hypervisor = Hypervisor(self._project, self.ubridge_path, self.working_dir, server_host)
log.info("Starting new uBridge hypervisor {}:{}".format(self._ubridge_hypervisor.host, self._ubridge_hypervisor.port))
yield from self._ubridge_hypervisor.start()
log.info("Hypervisor {}:{} has successfully started".format(self._ubridge_hypervisor.host, self._ubridge_hypervisor.port))
yield from self._ubridge_hypervisor.connect()
if parse_version(self._ubridge_hypervisor.version) < parse_version('0.9.1'):
raise VMwareError("uBridge version must be >= 0.9.1, detected version is {}".format(self._ubridge_hypervisor.version))
def check_hw_virtualization(self):
"""
Returns either hardware virtualization is activated or not.