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

Bridge support in cloud is more robust

Fix #761
This commit is contained in:
Julien Duponchelle 2016-11-04 17:40:44 +01:00
parent cf723962af
commit 7255754fef
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 10 additions and 5 deletions

View File

@ -41,13 +41,10 @@ class Cloud(BaseNode):
:param project: Project instance
:param manager: Parent VM Manager
"""
_cloud_id = 0
def __init__(self, name, node_id, project, manager, ports=[]):
super().__init__(name, node_id, project, manager)
Cloud._cloud_id += 1
self._nios = {}
# If the cloud is not configured we fill it with host interfaces
if not ports or len(ports) == 0:
@ -240,7 +237,15 @@ class Cloud(BaseNode):
"""
interface = port_info["interface"]
if gns3server.utils.interfaces.is_interface_bridge(interface):
tap = "gns3tap{}-{}".format(Cloud._cloud_id, port_info["port_number"])
network_interfaces = [interface["name"] for interface in self._interfaces()]
i = 0
while True:
tap = "gns3tap{}-{}".format(i, port_info["port_number"])
if tap not in network_interfaces:
break
i += 1
yield from self._ubridge_send('bridge add_nio_tap "{name}" "{interface}"'.format(name=bridge_name, interface=tap))
yield from self._ubridge_send('brctl addif "{interface}" "{tap}"'.format(tap=tap, interface=interface))
else:

View File

@ -173,7 +173,7 @@ def test_linux_ethernet_raw_add_nio_bridge(linux_platform, project, async_run, n
with patch("gns3server.utils.interfaces.is_interface_bridge", return_value=True):
async_run(cloud.add_nio(nio, 0))
tap = "gns3tap{}-0".format(cloud._cloud_id)
tap = "gns3tap0-0"
ubridge_mock.assert_has_calls([
call("bridge create {}-0".format(cloud._id)),
call("bridge add_nio_udp {}-0 4242 127.0.0.1 4343".format(cloud._id)),