From e70ea26639b4ce4b3f48c7288bcbe8fbbb3f39e9 Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 11 Apr 2014 16:24:08 -0600 Subject: [PATCH] Fixes checks for free console and aux ports. --- .../modules/dynamips/dynamips_hypervisor.py | 2 +- gns3server/modules/dynamips/nodes/router.py | 21 ++++++++++++++----- gns3server/modules/iou/iou_device.py | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/modules/dynamips/dynamips_hypervisor.py index 9af7a908..45e6449b 100644 --- a/gns3server/modules/dynamips/dynamips_hypervisor.py +++ b/gns3server/modules/dynamips/dynamips_hypervisor.py @@ -351,7 +351,7 @@ class DynamipsHypervisor(object): socket_type = socket.SOCK_STREAM for port in range(start_port, end_port): - if port > end_port: + if port + 1 == end_port: raise DynamipsError("Could not find a free port between {0} and {1}".format(start_port, end_port)) try: if ":" in host: diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index 331c60b8..ab485b36 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -103,11 +103,9 @@ class Router(object): platform=platform, id=self._id)) - # allocate and check that console and aux ports are unused - console_port = (self._hypervisor.baseconsole - 1) + self._id - self.console = DynamipsHypervisor.find_unused_port(console_port, console_port + 1, self._hypervisor.host) - aux_port = (self._hypervisor.baseaux - 1) + self._id - self.aux = DynamipsHypervisor.find_unused_port(aux_port, aux_port + 1, self._hypervisor.host) + # get console and aux ports + self.console = (self._hypervisor.baseconsole - 1) + self._id + self.aux = (self._hypervisor.baseaux - 1) + self._id # get the default base MAC address self._mac_addr = self._hypervisor.send("{platform} get_mac_addr {name}".format(platform=self._platform, @@ -272,6 +270,19 @@ class Router(object): if self.get_status() == "suspended": self.resume() else: + + if self.console and self.aux: + # check that console and aux ports are available + try: + DynamipsHypervisor.find_unused_port(self.console, self.console + 1, self._hypervisor.host) + except DynamipsError: + raise DynamipsError("console port {} is not available".format(self.console)) + + try: + DynamipsHypervisor.find_unused_port(self.aux, self.aux + 1, self._hypervisor.host) + except DynamipsError: + raise DynamipsError("aux port {} is not available".format(self.aux)) + self._hypervisor.send("vm start {}".format(self._name)) log.info("router {name} [id={id}] has been started".format(name=self._name, id=self._id)) diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index 31cb98e9..5d0940fb 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -793,7 +793,7 @@ class IOUDevice(object): socket_type = socket.SOCK_STREAM for port in range(start_port, end_port): - if port > end_port: + if port + 1 == end_port: raise IOUError("Could not find a free port between {0} and {1}".format(start_port, end_port)) try: if ":" in host: