From 7255754fef7830818cc02a4c6d8db9be19ff1ff5 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 4 Nov 2016 17:40:44 +0100 Subject: [PATCH] Bridge support in cloud is more robust Fix #761 --- gns3server/compute/builtin/nodes/cloud.py | 13 +++++++++---- tests/compute/builtin/nodes/test_cloud.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gns3server/compute/builtin/nodes/cloud.py b/gns3server/compute/builtin/nodes/cloud.py index 1a391644..1634948d 100644 --- a/gns3server/compute/builtin/nodes/cloud.py +++ b/gns3server/compute/builtin/nodes/cloud.py @@ -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: diff --git a/tests/compute/builtin/nodes/test_cloud.py b/tests/compute/builtin/nodes/test_cloud.py index 93c54105..462677f8 100644 --- a/tests/compute/builtin/nodes/test_cloud.py +++ b/tests/compute/builtin/nodes/test_cloud.py @@ -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)),