Fix trouble with builtin devices when we free ports

Fix #825
This commit is contained in:
Julien Duponchelle
2016-12-12 19:17:06 +01:00
parent 9872fc09b7
commit d2f0cddbd7
12 changed files with 125 additions and 221 deletions

View File

@ -120,24 +120,30 @@ class ATMSwitch(Device):
self._mappings = mappings
@asyncio.coroutine
def delete(self):
"""
Deletes this ATM switch.
"""
def close(self):
for nio in self._nios.values():
if nio and isinstance(nio, NIOUDP):
self.manager.port_manager.release_udp_port(nio.lport, self._project)
try:
yield from self._hypervisor.send('atmsw delete "{}"'.format(self._name))
log.info('ATM switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id))
except DynamipsError:
log.debug("Could not properly delete ATM switch {}".format(self._name))
if self._hypervisor:
try:
yield from self._hypervisor.send('atmsw delete "{}"'.format(self._name))
log.info('ATM switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id))
except DynamipsError:
log.debug("Could not properly delete ATM switch {}".format(self._name))
if self._hypervisor and self in self._hypervisor.devices:
self._hypervisor.devices.remove(self)
if self._hypervisor and not self._hypervisor.devices:
yield from self.hypervisor.stop()
self._hypervisor = None
return True
@asyncio.coroutine
def delete(self):
"""
Deletes this ATM switch.
"""
yield from self.close()
def has_port(self, port):
"""