mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 16:28:11 +00:00
Detect Wifi adapters on OSX. Fixes #549.
This commit is contained in:
parent
182a979e71
commit
c3c5eb533f
@ -17,12 +17,14 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from ...error import NodeError
|
from ...error import NodeError
|
||||||
from ...base_node import BaseNode
|
from ...base_node import BaseNode
|
||||||
from ...nios.nio_udp import NIOUDP
|
from ...nios.nio_udp import NIOUDP
|
||||||
|
|
||||||
from gns3server.utils.interfaces import interfaces
|
from gns3server.utils.interfaces import interfaces
|
||||||
|
import gns3server.utils.asyncio
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -111,6 +113,26 @@ class Cloud(BaseNode):
|
|||||||
yield from self._stop_ubridge()
|
yield from self._stop_ubridge()
|
||||||
log.info('Cloud "{name}" [{id}] has been closed'.format(name=self._name, id=self._id))
|
log.info('Cloud "{name}" [{id}] has been closed'.format(name=self._name, id=self._id))
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def _is_wifi_adapter_osx(self, adapter_name):
|
||||||
|
|
||||||
|
try:
|
||||||
|
output = yield from gns3server.utils.asyncio.subprocess_check_output("networksetup", "-listallhardwareports")
|
||||||
|
except (FileNotFoundError, subprocess.SubprocessError) as e:
|
||||||
|
log.warn("Could not execute networksetup: {}".format(e))
|
||||||
|
return False
|
||||||
|
|
||||||
|
is_wifi = False
|
||||||
|
for line in output.splitlines():
|
||||||
|
if is_wifi:
|
||||||
|
if adapter_name == line.replace("Device: ", ""):
|
||||||
|
return True
|
||||||
|
is_wifi = False
|
||||||
|
else:
|
||||||
|
if 'Wi-Fi' in line:
|
||||||
|
is_wifi = True
|
||||||
|
return False
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _add_ubridge_connection(self, nio, port_number):
|
def _add_ubridge_connection(self, nio, port_number):
|
||||||
"""
|
"""
|
||||||
@ -164,9 +186,10 @@ class Cloud(BaseNode):
|
|||||||
yield from self._ubridge_send('bridge add_nio_linux_raw {name} "{interface}"'.format(name=bridge_name,
|
yield from self._ubridge_send('bridge add_nio_linux_raw {name} "{interface}"'.format(name=bridge_name,
|
||||||
interface=port_info["interface"]))
|
interface=port_info["interface"]))
|
||||||
else:
|
else:
|
||||||
if sys.platform.startswith("darwin") and port_info["interface"].startswith("en"):
|
if sys.platform.startswith("darwin"):
|
||||||
# Wireless adapters are not well supported by the libpcap on OSX
|
# Wireless adapters are not well supported by the libpcap on OSX
|
||||||
raise NodeError("Connecting to a Wireless adapter is not supported.")
|
if (yield from self._is_wifi_adapter_osx(port_info["interface"])):
|
||||||
|
raise NodeError("Connecting to a Wireless adapter is not supported on Mac OS")
|
||||||
if sys.platform.startswith("darwin") and port_info["interface"].startswith("vmnet"):
|
if sys.platform.startswith("darwin") and port_info["interface"].startswith("vmnet"):
|
||||||
# Use a special NIO to connect to VMware vmnet interfaces on OSX (libpcap doesn't support them)
|
# Use a special NIO to connect to VMware vmnet interfaces on OSX (libpcap doesn't support them)
|
||||||
yield from self._ubridge_send('bridge add_nio_fusion_vmnet {name} "{interface}"'.format(name=bridge_name,
|
yield from self._ubridge_send('bridge add_nio_fusion_vmnet {name} "{interface}"'.format(name=bridge_name,
|
||||||
|
@ -56,7 +56,7 @@ def subprocess_check_output(*args, cwd=None, env=None):
|
|||||||
if output is None:
|
if output is None:
|
||||||
return ""
|
return ""
|
||||||
# If we received garbage we ignore invalid characters
|
# If we received garbage we ignore invalid characters
|
||||||
# it should happend only when user try to use another binary
|
# it should happens only when user try to use another binary
|
||||||
# and the code of VPCS, dynamips... Will detect it's not the correct binary
|
# and the code of VPCS, dynamips... Will detect it's not the correct binary
|
||||||
return output.decode("utf-8", errors="ignore")
|
return output.decode("utf-8", errors="ignore")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user