1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +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
- aiohttp
- setuptools
- netifaces
- psutil
- jsonschema
The following commands will install some of these dependencies:

View File

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

View File

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

View File

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

View File

@ -44,18 +44,10 @@ dependencies = [
"Jinja2>=2.7.3",
"raven>=5.2.0",
"docker-py>=1.4.0",
"psutil>=2.2.1"
"psutil>=3.0.0"
]
if not 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:
if sys.platform.startswith("win"):
dependencies.append("pywin32>=219")
setup(

View File

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

View File

@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import netifaces
from gns3server.utils.interfaces import interfaces, is_interface_up
@ -28,7 +27,8 @@ def test_interfaces():
def test_is_interface_up():
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"):
assert is_interface_up("lo0") is True
else: