diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 37da5200..b945c4ba 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -373,7 +373,7 @@ class IOU(IModule): return try: - iou_instance.delete() + iou_instance.clean_delete() del self._iou_instances[request["id"]] except IOUError as e: self.send_custom_error(str(e)) diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index 66e33f3d..bb126535 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -27,6 +27,8 @@ import subprocess import argparse import threading import configparser +import shutil + from .ioucon import start_ioucon from .iou_error import IOUError from .adapters.ethernet_adapter import EthernetAdapter @@ -332,6 +334,28 @@ class IOUDevice(object): log.info("IOU device {name} [id={id}] has been deleted".format(name=self._name, id=self._id)) + def clean_delete(self): + """ + Deletes this IOU device & all files (nvram, startup-config etc.) + """ + + self.stop() + self._instances.remove(self._id) + + if self.console: + self._allocated_console_ports.remove(self.console) + + try: + shutil.rmtree(self._working_dir) + except OSError as e: + log.error("could not delete IOU device {name} [id={id}]: {error}".format(name=self._name, + id=self._id, + error=e)) + return + + log.info("IOU device {name} [id={id}] has been deleted (including associated files)".format(name=self._name, + id=self._id)) + @property def started(self): """ diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index 22487821..294fe2ec 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -284,7 +284,7 @@ class VPCS(IModule): return try: - vpcs_instance.delete() + vpcs_instance.clean_delete() del self._vpcs_instances[request["id"]] except VPCSError as e: self.send_custom_error(str(e)) diff --git a/gns3server/modules/vpcs/vpcs_device.py b/gns3server/modules/vpcs/vpcs_device.py index ad9eafbf..f95cb9d0 100644 --- a/gns3server/modules/vpcs/vpcs_device.py +++ b/gns3server/modules/vpcs/vpcs_device.py @@ -23,6 +23,8 @@ order to run an VPCS instance. import os import subprocess import signal +import shutil + from .vpcs_error import VPCSError from .adapters.ethernet_adapter import EthernetAdapter from .nios.nio_udp import NIO_UDP @@ -267,6 +269,28 @@ class VPCSDevice(object): log.info("VPCS device {name} [id={id}] has been deleted".format(name=self._name, id=self._id)) + def clean_delete(self): + """ + Deletes this VPCS device & all files (configs, logs etc.) + """ + + self.stop() + self._instances.remove(self._id) + + if self.console: + self._allocated_console_ports.remove(self.console) + + try: + shutil.rmtree(self._working_dir) + except OSError as e: + log.error("could not delete VPCS device {name} [id={id}]: {error}".format(name=self._name, + id=self._id, + error=e)) + return + + log.info("VPCS device {name} [id={id}] has been deleted".format(name=self._name, + id=self._id)) + @property def started(self): """