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

Drop netifaces (replaced by psutil). Fixes #344.

This commit is contained in:
grossmj 2015-11-08 13:34:27 -07:00
parent 6fbc84c0dc
commit c3e99bfc1d
7 changed files with 18 additions and 30 deletions

View File

@ -45,7 +45,7 @@ Dependencies:
- Python 3.4 or above - Python 3.4 or above
- aiohttp - aiohttp
- setuptools - setuptools
- netifaces - psutil
- jsonschema - jsonschema
The following commands will install some of these dependencies: The following commands will install some of these dependencies:

View File

@ -21,8 +21,7 @@ Docker container instance.
import asyncio import asyncio
import shutil import shutil
import docker import psutil
import netifaces
from docker.utils import create_host_config from docker.utils import create_host_config
from gns3server.ubridge.hypervisor import Hypervisor from gns3server.ubridge.hypervisor import Hypervisor
@ -271,10 +270,8 @@ class Container(BaseVM):
name=self.name, adapter_number=adapter_number)) name=self.name, adapter_number=adapter_number))
if nio and isinstance(nio, NIOUDP): if nio and isinstance(nio, NIOUDP):
ifcs = netifaces.interfaces()
for index in range(128): for index in range(128):
ifcs = netifaces.interfaces() if "gns3-veth{}ext".format(index) not in psutil.net_if_addrs():
if "gns3-veth{}ext".format(index) not in ifcs:
adapter.ifc = "eth{}".format(str(index)) adapter.ifc = "eth{}".format(str(index))
adapter.host_ifc = "gns3-veth{}ext".format(str(index)) adapter.host_ifc = "gns3-veth{}ext".format(str(index))
adapter.guest_ifc = "gns3-veth{}int".format(str(index)) adapter.guest_ifc = "gns3-veth{}int".format(str(index))

View File

@ -20,6 +20,7 @@ import sys
import aiohttp import aiohttp
import socket import socket
import struct import struct
import psutil
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -114,8 +115,7 @@ def is_interface_up(interface):
if sys.platform.startswith("linux"): if sys.platform.startswith("linux"):
import netifaces if interface not in psutil.net_if_addrs():
if interface not in netifaces.interfaces():
return False return False
import fcntl import fcntl
@ -143,13 +143,13 @@ def interfaces():
results = [] results = []
if not sys.platform.startswith("win"): if not sys.platform.startswith("win"):
import netifaces for interface in sorted(psutil.net_if_addrs().keys()):
for interface in netifaces.interfaces():
ip_address = "" ip_address = ""
ip_addresses = netifaces.ifaddresses(interface) for addr in psutil.net_if_addrs()[interface]:
if netifaces.AF_INET in ip_addresses and ip_addresses[netifaces.AF_INET]: # get the first available IPv4 address only
# get the first IPv4 address only if addr.family == socket.AF_INET:
ip_address = ip_addresses[netifaces.AF_INET][0]["addr"] ip_address = addr.address
break
results.append({"id": interface, results.append({"id": interface,
"name": interface, "name": interface,
"ip_address": ip_address}) "ip_address": ip_address})

View File

@ -2,6 +2,5 @@ jsonschema>=2.4.0
aiohttp==0.17.4 aiohttp==0.17.4
Jinja2>=2.7.3 Jinja2>=2.7.3
raven>=5.2.0 raven>=5.2.0
gns3-netifaces==0.10.4.1
docker-py==1.4.0 docker-py==1.4.0
psutil>=2.2.1 psutil>=3.0.0

View File

@ -44,18 +44,10 @@ dependencies = [
"Jinja2>=2.7.3", "Jinja2>=2.7.3",
"raven>=5.2.0", "raven>=5.2.0",
"docker-py>=1.4.0", "docker-py>=1.4.0",
"psutil>=2.2.1" "psutil>=3.0.0"
] ]
if not sys.platform.startswith("win"): if sys.platform.startswith("win"):
# netifaces if not used on Windows
try:
import netifaces
except ImportError:
# add gns3-netifaces only if netifaces isn't already installed
# for instance via a Debian package.
dependencies.append("gns3-netifaces>=0.10.4.1")
else:
dependencies.append("pywin32>=219") dependencies.append("pywin32>=219")
setup( setup(

View File

@ -132,8 +132,8 @@ def free_console_port(request, port_manager, project):
@pytest.fixture @pytest.fixture
def ethernet_device(): def ethernet_device():
import netifaces import psutil
return netifaces.interfaces()[0] return sorted(psutil.net_if_addrs().keys())[0]
@pytest.yield_fixture(autouse=True) @pytest.yield_fixture(autouse=True)

View File

@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys import sys
import netifaces
from gns3server.utils.interfaces import interfaces, is_interface_up from gns3server.utils.interfaces import interfaces, is_interface_up
@ -28,7 +27,8 @@ def test_interfaces():
def test_is_interface_up(): def test_is_interface_up():
if sys.platform.startswith("win"): if sys.platform.startswith("win"):
assert is_interface_up(netifaces.interfaces[0]) is True # is_interface_up() always returns True on Windows
pass
elif sys.platform.startswith("darwin"): elif sys.platform.startswith("darwin"):
assert is_interface_up("lo0") is True assert is_interface_up("lo0") is True
else: else: