From 551b98880b2b142ddacb521259f0bd7a878b6e32 Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 4 Jul 2014 15:18:13 -0600 Subject: [PATCH] Default preferences for remote servers. --- gns3server/modules/dynamips/__init__.py | 34 ++++++++++++++++--- .../modules/dynamips/hypervisor_manager.py | 34 +++++++++++-------- gns3server/modules/dynamips/nodes/router.py | 3 ++ gns3server/modules/dynamips/schemas/vm.py | 3 +- gns3server/modules/iou/__init__.py | 10 +++--- gns3server/modules/vpcs/__init__.py | 10 +++--- 6 files changed, 62 insertions(+), 32 deletions(-) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index d6a94d03..11f50bc2 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -27,6 +27,7 @@ import shutil import glob import socket from gns3server.modules import IModule +from gns3server.config import Config from .hypervisor import Hypervisor from .hypervisor_manager import HypervisorManager @@ -104,8 +105,27 @@ class Dynamips(IModule): def __init__(self, name, *args, **kwargs): - IModule.__init__(self, name, *args, **kwargs) + # get the Dynamips location + config = Config.instance() + dynamips_config = config.get_section_config(name.upper()) + self._dynamips = dynamips_config.get("dynamips_path") + if not self._dynamips or not os.path.isfile(self._dynamips): + paths = [os.getcwd()] + os.environ["PATH"].split(":") + # look for Dynamips in the current working directory and $PATH + for path in paths: + try: + if "dynamips" in os.listdir(path) and os.access(os.path.join(path, "dynamips"), os.X_OK): + self._dynamips = os.path.join(path, "dynamips") + break + except OSError: + continue + if not self._dynamips: + log.warning("dynamips binary couldn't be found!") + elif not os.access(self._dynamips, os.X_OK): + log.warning("dynamips is not executable") + + IModule.__init__(self, name, *args, **kwargs) self._hypervisor_manager = None self._hypervisor_manager_settings = {} self._routers = {} @@ -116,7 +136,6 @@ class Dynamips(IModule): self._projects_dir = kwargs["projects_dir"] self._tempdir = kwargs["temp_dir"] self._working_dir = self._projects_dir - self._dynamips = "" self._host = kwargs["host"] if not sys.platform.startswith("win32"): @@ -278,6 +297,7 @@ class Dynamips(IModule): Optional request parameters: - working_dir (path to a working directory) + - project_name :param request: JSON request """ @@ -450,9 +470,13 @@ class Dynamips(IModule): ghost.ghost_status = 1 ghost.ghost_file = ghost_instance ghost.ram = router.ram - ghost.start() - ghost.stop() - ghost.clean_delete() + try: + ghost.start() + ghost.stop() + except DynamipsError: + raise + finally: + ghost.clean_delete() if router.ghost_file != ghost_instance: # set the ghost file to the router diff --git a/gns3server/modules/dynamips/hypervisor_manager.py b/gns3server/modules/dynamips/hypervisor_manager.py index 7c8153c4..a7451cb5 100644 --- a/gns3server/modules/dynamips/hypervisor_manager.py +++ b/gns3server/modules/dynamips/hypervisor_manager.py @@ -19,6 +19,7 @@ Manages Dynamips hypervisors (load-balancing etc.) """ +from gns3server.config import Config from .hypervisor import Hypervisor from .dynamips_error import DynamipsError from ..attic import find_unused_port @@ -47,21 +48,24 @@ class HypervisorManager(object): self._path = path self._working_dir = working_dir self._host = host - self._hypervisor_start_port_range = 7200 - self._hypervisor_end_port_range = 7700 - self._console_start_port_range = 2001 - self._console_end_port_range = 2500 - self._aux_start_port_range = 2501 - self._aux_end_port_range = 3000 - self._udp_start_port_range = 10001 - self._udp_end_port_range = 20000 - self._ghost_ios_support = True - self._mmap_support = True - self._jit_sharing_support = False - self._sparse_memory_support = True - self._allocate_hypervisor_per_device = True - self._memory_usage_limit_per_hypervisor = 1024 - self._allocate_hypervisor_per_ios_image = True + + config = Config.instance() + dynamips_config = config.get_section_config("DYNAMIPS") + self._hypervisor_start_port_range = dynamips_config.get("hypervisor_start_port_range", 7200) + self._hypervisor_end_port_range = dynamips_config.get("hypervisor_end_port_range", 7700) + self._console_start_port_range = dynamips_config.get("console_start_port_range", 2001) + self._console_end_port_range = dynamips_config.get("console_end_port_range", 2500) + self._aux_start_port_range = dynamips_config.get("aux_start_port_range", 2501) + self._aux_end_port_range = dynamips_config.get("aux_end_port_range", 3000) + self._udp_start_port_range = dynamips_config.get("udp_start_port_range", 10001) + self._udp_end_port_range = dynamips_config.get("udp_end_port_range", 20000) + self._ghost_ios_support = dynamips_config.get("ghost_ios_support", True) + self._mmap_support = dynamips_config.get("mmap_support", True) + self._jit_sharing_support = dynamips_config.get("jit_sharing_support", False) + self._sparse_memory_support = dynamips_config.get("sparse_memory_support", True) + self._allocate_hypervisor_per_device = dynamips_config.get("allocate_hypervisor_per_device", True) + self._memory_usage_limit_per_hypervisor = dynamips_config.get("memory_usage_limit_per_hypervisor", 1024) + self._allocate_hypervisor_per_ios_image = dynamips_config.get("allocate_hypervisor_per_ios_image", True) def __del__(self): """ diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index 9c08ec77..7b26d393 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -774,6 +774,9 @@ class Router(object): :param idlepc: idlepc value (string) """ + if not idlepc: + idlepc = "0x0" + if not self.is_running(): # router is not running self._hypervisor.send("vm set_idle_pc {name} {idlepc}".format(name=self._name, diff --git a/gns3server/modules/dynamips/schemas/vm.py b/gns3server/modules/dynamips/schemas/vm.py index 3548e8e0..328a10db 100644 --- a/gns3server/modules/dynamips/schemas/vm.py +++ b/gns3server/modules/dynamips/schemas/vm.py @@ -202,8 +202,7 @@ VM_UPDATE_SCHEMA = { "idlepc": { "description": "idle-pc value", "type": "string", - "minLength": 1, - "pattern": "^0x[0-9a-fA-F]+$" + "pattern": "^(0x[0-9a-fA-F]+)?$" }, "idlemax": { "description": "idlemax value", diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 63e0a5a8..341177fc 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -66,7 +66,7 @@ class IOU(IModule): # get the iouyap location config = Config.instance() iou_config = config.get_section_config(name.upper()) - self._iouyap = iou_config.get("iouyap") + self._iouyap = iou_config.get("iouyap_path") if not self._iouyap or not os.path.isfile(self._iouyap): paths = [os.getcwd()] + os.environ["PATH"].split(":") # look for iouyap in the current working directory and $PATH @@ -86,11 +86,11 @@ class IOU(IModule): # a new process start when calling IModule IModule.__init__(self, name, *args, **kwargs) self._iou_instances = {} - self._console_start_port_range = 4001 - self._console_end_port_range = 4512 + self._console_start_port_range = iou_config.get("console_start_port_range", 4001) + self._console_end_port_range = iou_config.get("console_end_port_range", 4512) self._allocated_udp_ports = [] - self._udp_start_port_range = 30001 - self._udp_end_port_range = 40001 + self._udp_start_port_range = iou_config.get("udp_start_port_range", 30001) + self._udp_end_port_range = iou_config.get("udp_end_port_range", 40001) self._host = kwargs["host"] self._projects_dir = kwargs["projects_dir"] self._tempdir = kwargs["temp_dir"] diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index 9d2441d9..71709016 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -61,7 +61,7 @@ class VPCS(IModule): # get the VPCS location config = Config.instance() vpcs_config = config.get_section_config(name.upper()) - self._vpcs = vpcs_config.get("vpcs") + self._vpcs = vpcs_config.get("vpcs_path") if not self._vpcs or not os.path.isfile(self._vpcs): paths = [os.getcwd()] + os.environ["PATH"].split(":") # look for VPCS in the current working directory and $PATH @@ -81,11 +81,11 @@ class VPCS(IModule): # a new process start when calling IModule IModule.__init__(self, name, *args, **kwargs) self._vpcs_instances = {} - self._console_start_port_range = 4512 - self._console_end_port_range = 5000 + self._console_start_port_range = vpcs_config.get("console_start_port_range", 4512) + self._console_end_port_range = vpcs_config.get("console_end_port_range", 5000) self._allocated_udp_ports = [] - self._udp_start_port_range = 40001 - self._udp_end_port_range = 40512 + self._udp_start_port_range = vpcs_config.get("udp_start_port_range", 40001) + self._udp_end_port_range = vpcs_config.get("udp_end_port_range", 40512) self._host = kwargs["host"] self._projects_dir = kwargs["projects_dir"] self._tempdir = kwargs["temp_dir"]