From 7182e59892966e6b366e29ce8df5f3ac3d0632c9 Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 19 May 2014 12:05:30 -0600 Subject: [PATCH] Clean delete for IOU & VPCS devices. --- gns3server/modules/iou/__init__.py | 2 +- gns3server/modules/iou/iou_device.py | 24 ++++++++++++++++++++++++ gns3server/modules/vpcs/__init__.py | 2 +- gns3server/modules/vpcs/vpcs_device.py | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) 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): """