From 4c900ce639e15ba9045206e31ff7dc7504d497e0 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 23 Sep 2016 10:52:08 +0200 Subject: [PATCH] Cleanup port when cloud failed to create --- gns3server/compute/builtin/nodes/cloud.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gns3server/compute/builtin/nodes/cloud.py b/gns3server/compute/builtin/nodes/cloud.py index ebfa47bc..6d28ba5d 100644 --- a/gns3server/compute/builtin/nodes/cloud.py +++ b/gns3server/compute/builtin/nodes/cloud.py @@ -22,6 +22,7 @@ import subprocess from ...error import NodeError from ...base_node import BaseNode from ...nios.nio_udp import NIOUDP +from ....ubridge.ubridge_error import UbridgeError import gns3server.utils.interfaces import gns3server.utils.asyncio @@ -96,6 +97,9 @@ class Cloud(BaseNode): :param ports: ports info """ + if len(self._nios) > 0: + raise NodeError("Can't modify a cloud already connected.") + self._ports_mapping = ports @asyncio.coroutine @@ -242,7 +246,16 @@ class Cloud(BaseNode): nio=nio, port=port_number)) self._nios[port_number] = nio - yield from self._add_ubridge_connection(nio, port_number) + try: + yield from self._add_ubridge_connection(nio, port_number) + # Cleanup stuff + except UbridgeError as e: + try: + self._delete_ubridge_connection(port_number) + except UbridgeError: + pass + del self._nios[port_number] + raise e @asyncio.coroutine def _delete_ubridge_connection(self, port_number):