|
|
@ -22,6 +22,9 @@ from ...error import NodeError
|
|
|
|
|
|
|
|
|
|
|
|
import gns3server.utils.interfaces
|
|
|
|
import gns3server.utils.interfaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Nat(Cloud):
|
|
|
|
class Nat(Cloud):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -29,19 +32,22 @@ class Nat(Cloud):
|
|
|
|
NAT access.
|
|
|
|
NAT access.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
def __init__(self, name, node_id, project, manager, ports=None):
|
|
|
|
|
|
|
|
|
|
|
|
if sys.platform.startswith("linux"):
|
|
|
|
if sys.platform.startswith("linux"):
|
|
|
|
if "virbr0" not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
|
|
|
|
nat_interface = manager.config.get_section_config("Server").get("nat_interface", "virbr0")
|
|
|
|
raise NodeError("virbr0 is missing, please install libvirt")
|
|
|
|
if nat_interface not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
|
|
|
|
interface = "virbr0"
|
|
|
|
raise NodeError("NAT interface {} is missing, please install libvirt".format(nat_interface))
|
|
|
|
|
|
|
|
interface = nat_interface
|
|
|
|
else:
|
|
|
|
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()]))
|
|
|
|
[interface["name"] for interface in gns3server.utils.interfaces.interfaces()]))
|
|
|
|
if not len(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
|
|
|
|
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 = [
|
|
|
|
ports = [
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"name": "nat0",
|
|
|
|
"name": "nat0",
|
|
|
@ -50,7 +56,7 @@ class Nat(Cloud):
|
|
|
|
"port_number": 0
|
|
|
|
"port_number": 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
super().__init__(*args, ports=ports)
|
|
|
|
super().__init__(name, node_id, project, manager, ports=ports)
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def ports_mapping(self):
|
|
|
|
def ports_mapping(self):
|
|
|
|