diff --git a/gns3server/modules/base_vm.py b/gns3server/modules/base_vm.py index cfbcc2a2..4d315167 100644 --- a/gns3server/modules/base_vm.py +++ b/gns3server/modules/base_vm.py @@ -23,6 +23,7 @@ import asyncio import tempfile from ..utils.asyncio import wait_run_in_executor +from .vm_error import VMError log = logging.getLogger(__name__) @@ -132,7 +133,10 @@ class BaseVM: @property def temporary_directory(self): if self._temporary_directory is None: - self._temporary_directory = tempfile.mkdtemp() + try: + self._temporary_directory = tempfile.mkdtemp() + except OSError as e: + raise VMError("Can't create temporary directory: {}".format(e)) return self._temporary_directory def create(self): diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index f73aa2a2..f195c2ed 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -332,14 +332,21 @@ class IOUVM(BaseVM): @property def iourc_content(self): - with open(os.path.join(self.temporary_directory, "iourc")) as f: - return f.read() + try: + with open(os.path.join(self.temporary_directory, "iourc")) as f: + return f.read() + except OSError: + return None @iourc_content.setter def iourc_content(self, value): if value is not None: - with open(os.path.join(self.temporary_directory, "iourc"), "w+") as f: - f.write(value) + path = os.path.join(self.temporary_directory, "iourc") + try: + with open(path, "w+") as f: + f.write(value) + except OSError as e: + raise IOUError("Could not write iourc file {}: {}".format(path, e)) @asyncio.coroutine def _library_check(self):