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

Allow to configure the interface to be used by the NAT node. Fixes #1175.

This commit is contained in:
grossmj 2018-03-15 17:20:40 +07:00
parent 08493871a5
commit aaf59e6050
2 changed files with 19 additions and 8 deletions

View File

@ -40,7 +40,12 @@ user = gns3
password = gns3
; Only allow these interfaces to be used by GNS3, for the Cloud node for example (Linux/OSX only)
allowed_interfaces = eth0,eth1
; Do not forget to allow virbr0 in order for the NAT node to work
allowed_interfaces = eth0,eth1,virbr0
; Specify the NAT interface to be used by the NAT node
; Default is virbr0 on Linux (requires libvirt) and vmnet8 for other platforms (requires VMware)
nat_interface = vmnet10
[VPCS]
; VPCS executable location, default: search in PATH

View File

@ -22,6 +22,9 @@ from ...error import NodeError
import gns3server.utils.interfaces
import logging
log = logging.getLogger(__name__)
class Nat(Cloud):
"""
@ -29,19 +32,22 @@ class Nat(Cloud):
NAT access.
"""
def __init__(self, *args, **kwargs):
def __init__(self, name, node_id, project, manager, ports=None):
if sys.platform.startswith("linux"):
if "virbr0" not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
raise NodeError("virbr0 is missing, please install libvirt")
interface = "virbr0"
nat_interface = manager.config.get_section_config("Server").get("nat_interface", "virbr0")
if nat_interface not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
raise NodeError("NAT interface {} is missing, please install libvirt".format(nat_interface))
interface = nat_interface
else:
interfaces = list(filter(lambda x: 'vmnet8' in x.lower(),
nat_interface = manager.config.get_section_config("Server").get("nat_interface", "vmnet8")
interfaces = list(filter(lambda x: nat_interface in x.lower(),
[interface["name"] for interface in gns3server.utils.interfaces.interfaces()]))
if not len(interfaces):
raise NodeError("vmnet8 is missing. You need to install VMware or use the NAT node on GNS3 VM")
raise NodeError("NAT interface {} is missing. You need to install VMware or use the NAT node on GNS3 VM".format(nat_interface))
interface = interfaces[0] # take the first available interface containing the vmnet8 name
log.info("NAT node '{}' configured to use NAT interface '{}'".format(name, interface))
ports = [
{
"name": "nat0",
@ -50,7 +56,7 @@ class Nat(Cloud):
"port_number": 0
}
]
super().__init__(*args, ports=ports)
super().__init__(name, node_id, project, manager, ports=ports)
@property
def ports_mapping(self):