mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Drop netifaces (replaced by psutil). Fixes #344.
This commit is contained in:
1 parent
6fbc84c0dc
commit
c3e99bfc1d
7 files changed
+18
-30
No files matched your search
@@ -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))
|
||||
|
||||
@@ -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})
|
||||
|
||||
Reference in new issue
Block a user