From 9e83329f14b938454c396da55e5eb89eded7ea22 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 15 Jan 2015 16:50:36 -0700 Subject: [PATCH] Rename Device to VM. --- README.rst | 2 +- gns3server/modules/base_manager.py | 6 +++--- gns3server/modules/base_vm.py | 18 +++++++++--------- gns3server/modules/port_manager.py | 14 ++++++++------ .../modules/{device_error.py => vm_error.py} | 2 +- gns3server/modules/vpcs/vpcs_error.py | 5 +++-- gns3server/web/route.py | 4 ++-- 7 files changed, 27 insertions(+), 24 deletions(-) rename gns3server/modules/{device_error.py => vm_error.py} (95%) diff --git a/README.rst b/README.rst index a3fa1600..a91baeed 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ GNS3-server This is the GNS3 server repository. The GNS3 server manages emulators such as Dynamips, VirtualBox or Qemu/KVM. -Clients like the GNS3 GUI controls the server using a JSON-RPC API over Websockets. +Clients like the GNS3 GUI controls the server using a HTTP REST API. You will need the GNS3 GUI (gns3-gui repository) to control the server. diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index abfd5df1..923576b5 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -19,7 +19,7 @@ import asyncio import aiohttp -from .device_error import DeviceError +from .vm_error import VMError class BaseManager: @@ -69,10 +69,10 @@ class BaseManager: identifier = i break if identifier == 0: - raise DeviceError("Maximum number of VM instances reached") + raise VMError("Maximum number of VM instances reached") else: if identifier in self._vms: - raise DeviceError("VM identifier {} is already used by another VM instance".format(identifier)) + raise VMError("VM identifier {} is already used by another VM instance".format(identifier)) vm = self._VM_CLASS(vmname, identifier, self.port_manager) yield from vm.wait_for_creation() self._vms[vm.id] = vm diff --git a/gns3server/modules/base_vm.py b/gns3server/modules/base_vm.py index f9f41827..24c1a037 100644 --- a/gns3server/modules/base_vm.py +++ b/gns3server/modules/base_vm.py @@ -17,12 +17,13 @@ import asyncio -from .device_error import DeviceError +from .vm_error import VMError from .attic import find_unused_port import logging log = logging.getLogger(__name__) + class BaseVM: _allocated_console_ports = [] @@ -40,7 +41,6 @@ class BaseVM: name=self._name, id=self._id)) - def _allocate_console(self): if not self._console: # allocate a console port @@ -50,10 +50,10 @@ class BaseVM: self._console_host, ignore_ports=self._allocated_console_ports) except Exception as e: - raise DeviceError(e) + raise VMError(e) if self._console in self._allocated_console_ports: - raise DeviceError("Console port {} is already used by another device".format(console)) + raise VMError("Console port {} is already used by another device".format(self._console)) self._allocated_console_ports.append(self._console) @@ -76,7 +76,7 @@ class BaseVM: """ if console in self._allocated_console_ports: - raise DeviceError("Console port {} is already used by another VM device".format(console)) + raise VMError("Console port {} is already used by another VM device".format(console)) self._allocated_console_ports.remove(self._console) self._console = console @@ -122,7 +122,7 @@ class BaseVM: try: yield from self._create() self._created.set_result(True) - except DeviceError as e: + except VMError as e: self._created.set_exception(e) return @@ -132,7 +132,7 @@ class BaseVM: try: yield from asyncio.wait_for(self._execute(subcommand, args), timeout=timeout) except asyncio.TimeoutError: - raise DeviceError("{} has timed out after {} seconds!".format(subcommand, timeout)) + raise VMError("{} has timed out after {} seconds!".format(subcommand, timeout)) future.set_result(True) except Exception as e: future.set_exception(e) @@ -141,7 +141,7 @@ class BaseVM: return self._created @asyncio.coroutine - def start(): + def start(self): """ Starts the VM process. """ @@ -159,5 +159,5 @@ class BaseVM: args.insert(0, future) self._queue.put_nowait(args) except asyncio.qeues.QueueFull: - raise DeviceError("Queue is full") + raise VMError("Queue is full") return future diff --git a/gns3server/modules/port_manager.py b/gns3server/modules/port_manager.py index 2b833566..59aed442 100644 --- a/gns3server/modules/port_manager.py +++ b/gns3server/modules/port_manager.py @@ -18,6 +18,7 @@ import ipaddress from .attic import find_unused_port + class PortManager: """ :param console: TCP console port @@ -26,10 +27,10 @@ class PortManager: :param console_end_port_range: TCP console port range end """ def __init__(self, - console_host, - console_bind_to_any, - console_start_port_range=10000, - console_end_port_range=15000): + console_host, + console_bind_to_any, + console_start_port_range=10000, + console_end_port_range=15000): self._console_start_port_range = console_start_port_range self._console_end_port_range = console_end_port_range @@ -53,7 +54,7 @@ class PortManager: self._used_ports.add(port) return port - def reserve_port(port): + def reserve_port(self, port): """ Reserve a specific port number @@ -63,11 +64,12 @@ class PortManager: raise Exception("Port already {} in use".format(port)) self._used_ports.add(port) - def release_port(port): + def release_port(self, port): """ Release a specific port number :param port: Port number """ + self._used_ports.remove(port) diff --git a/gns3server/modules/device_error.py b/gns3server/modules/vm_error.py similarity index 95% rename from gns3server/modules/device_error.py rename to gns3server/modules/vm_error.py index b8eca500..d7b71e14 100644 --- a/gns3server/modules/device_error.py +++ b/gns3server/modules/vm_error.py @@ -16,5 +16,5 @@ # along with this program. If not, see . -class DeviceError(Exception): +class VMError(Exception): pass diff --git a/gns3server/modules/vpcs/vpcs_error.py b/gns3server/modules/vpcs/vpcs_error.py index acb10f71..f32afdaa 100644 --- a/gns3server/modules/vpcs/vpcs_error.py +++ b/gns3server/modules/vpcs/vpcs_error.py @@ -19,9 +19,10 @@ Custom exceptions for VPCS module. """ -from ..device_error import DeviceError +from ..vm_error import VMError -class VPCSError(DeviceError): + +class VPCSError(VMError): def __init__(self, message, original_exception=None): diff --git a/gns3server/web/route.py b/gns3server/web/route.py index 381b35e0..1687cde9 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -20,7 +20,7 @@ import jsonschema import asyncio import aiohttp -from ..modules.device_error import DeviceError +from ..modules.vm_error import VMError from .response import Response @@ -98,7 +98,7 @@ class Route(object): response = Response(route=route) response.set_status(e.status) response.json({"message": e.text, "status": e.status}) - except DeviceError as e: + except VMError as e: response = Response(route=route) response.set_status(400) response.json({"message": str(e), "status": 400})