Cleanup port when cloud failed to create

This commit is contained in:
Julien Duponchelle 2016-09-23 10:52:08 +02:00
parent 87e2326363
commit 4c900ce639
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

View File

@ -22,6 +22,7 @@ import subprocess
from ...error import NodeError from ...error import NodeError
from ...base_node import BaseNode from ...base_node import BaseNode
from ...nios.nio_udp import NIOUDP from ...nios.nio_udp import NIOUDP
from ....ubridge.ubridge_error import UbridgeError
import gns3server.utils.interfaces import gns3server.utils.interfaces
import gns3server.utils.asyncio import gns3server.utils.asyncio
@ -96,6 +97,9 @@ class Cloud(BaseNode):
:param ports: ports info :param ports: ports info
""" """
if len(self._nios) > 0:
raise NodeError("Can't modify a cloud already connected.")
self._ports_mapping = ports self._ports_mapping = ports
@asyncio.coroutine @asyncio.coroutine
@ -242,7 +246,16 @@ class Cloud(BaseNode):
nio=nio, nio=nio,
port=port_number)) port=port_number))
self._nios[port_number] = nio self._nios[port_number] = nio
try:
yield from self._add_ubridge_connection(nio, port_number) 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 @asyncio.coroutine
def _delete_ubridge_connection(self, port_number): def _delete_ubridge_connection(self, port_number):