From 9fc7650f3fdda3bab999a72a33588d103dadbdeb Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 6 Jul 2014 16:34:38 -0600 Subject: [PATCH] Find an alternative IOS or IOU image if one cannot be found when importing a topology. --- gns3server/modules/base.py | 10 ++++++++++ gns3server/modules/dynamips/backends/vm.py | 4 ++++ gns3server/modules/iou/__init__.py | 4 ++++ gns3server/version.py | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gns3server/modules/base.py b/gns3server/modules/base.py index 620737c0..bc4f27de 100644 --- a/gns3server/modules/base.py +++ b/gns3server/modules/base.py @@ -19,6 +19,7 @@ Base class (interface) for modules """ +import os import sys import traceback import gns3server.jsonrpc as jsonrpc @@ -26,6 +27,7 @@ import multiprocessing import zmq import signal +from gns3server.config import Config from jsonschema import validate, ValidationError import logging @@ -45,6 +47,9 @@ class IModule(multiprocessing.Process): def __init__(self, name, *args, **kwargs): + config = Config.instance() + server_config = config.get_default_section() + self._images_dir = os.path.expandvars(os.path.expanduser(server_config.get("upload_directory", "~/GNS3/images"))) multiprocessing.Process.__init__(self, name=name) self._context = None self._ioloop = None @@ -328,3 +333,8 @@ class IModule(multiprocessing.Process): cls.modules[module][destination] = method return method return wrapper + + @property + def images_directory(self): + + return self._images_dir diff --git a/gns3server/modules/dynamips/backends/vm.py b/gns3server/modules/dynamips/backends/vm.py index d8b3c1e6..c105aa0f 100644 --- a/gns3server/modules/dynamips/backends/vm.py +++ b/gns3server/modules/dynamips/backends/vm.py @@ -138,6 +138,10 @@ class VM(object): chassis = request.get("chassis") router_id = request.get("router_id") + updated_image_path = os.path.join(self.images_directory, image) + if os.path.isfile(updated_image_path): + image = updated_image_path + try: if platform not in PLATFORMS: diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 341177fc..d00b614b 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -295,6 +295,10 @@ class IOU(IModule): console = request.get("console") iou_id = request.get("iou_id") + updated_iou_path = os.path.join(self.images_directory, iou_path) + if os.path.isfile(updated_iou_path): + iou_path = updated_iou_path + try: iou_instance = IOUDevice(name, iou_path, diff --git a/gns3server/version.py b/gns3server/version.py index 2f9aa0ab..6bc258c4 100644 --- a/gns3server/version.py +++ b/gns3server/version.py @@ -23,5 +23,5 @@ # or negative for a release candidate or beta (after the base version # number has been incremented) -__version__ = "1.0a8.dev1" +__version__ = "1.0a8.dev2" __version_info__ = (1, 0, 0, -99)