mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
parent
4b891070d2
commit
d772b6fbd7
@ -15,7 +15,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# 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 socket
|
import sys
|
||||||
from .cloud import Cloud
|
from .cloud import Cloud
|
||||||
from ...error import NodeError
|
from ...error import NodeError
|
||||||
|
|
||||||
@ -31,24 +31,21 @@ class Nat(Cloud):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
if socket.gethostname() != "gns3vm":
|
if "virbr0" not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
|
||||||
raise NodeError("NAT node is supported only on GNS3 VM")
|
raise NodeError("virbr0 is missing. You need to install libvirt")
|
||||||
|
|
||||||
if "eth1" not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
|
|
||||||
raise NodeError("eth1 is missing on the GNS3 VM. You need to provide a nat interface as eth1")
|
|
||||||
|
|
||||||
self.ports = [
|
self.ports = [
|
||||||
{
|
{
|
||||||
"name": "nat0",
|
"name": "virbr0",
|
||||||
"type": "ethernet",
|
"type": "ethernet",
|
||||||
"interface": "eth1",
|
"interface": "virbr0",
|
||||||
"port_number": 0
|
"port_number": 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_supported(self):
|
def is_supported(self):
|
||||||
return socket.gethostname() == "gns3vm"
|
return sys.platform.startswith("linux")
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
return {
|
return {
|
||||||
|
@ -31,8 +31,8 @@ def test_json(on_gns3vm, project):
|
|||||||
"status": "started",
|
"status": "started",
|
||||||
"ports": [
|
"ports": [
|
||||||
{
|
{
|
||||||
"interface": "eth1",
|
"interface": "virbr0",
|
||||||
"name": "nat0",
|
"name": "virbr0",
|
||||||
"port_number": 0,
|
"port_number": 0,
|
||||||
"type": "ethernet"
|
"type": "ethernet"
|
||||||
}
|
}
|
||||||
|
@ -315,10 +315,10 @@ def async_run(loop):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def on_gns3vm():
|
def on_gns3vm(linux_platform):
|
||||||
"""
|
"""
|
||||||
Mock the hostname to emulate the GNS3 VM
|
Mock the hostname to emulate the GNS3 VM
|
||||||
"""
|
"""
|
||||||
with patch("gns3server.utils.interfaces.interfaces", return_value=[{"name": "eth0"}, {"name": "eth1"}]):
|
with patch("gns3server.utils.interfaces.interfaces", return_value=[{"name": "eth0"}, {"name": "eth1", "name": "virbr0"}]):
|
||||||
with patch("socket.gethostname", return_value="gns3vm"):
|
with patch("socket.gethostname", return_value="gns3vm"):
|
||||||
yield
|
yield
|
||||||
|
Loading…
Reference in New Issue
Block a user