1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Rename Device to VM.

This commit is contained in:
Jeremy 2015-01-15 16:50:36 -07:00
parent c1ef406311
commit 9e83329f14
7 changed files with 27 additions and 24 deletions

View File

@ -4,7 +4,7 @@ GNS3-server
This is the GNS3 server repository. This is the GNS3 server repository.
The GNS3 server manages emulators such as Dynamips, VirtualBox or Qemu/KVM. 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. You will need the GNS3 GUI (gns3-gui repository) to control the server.

View File

@ -19,7 +19,7 @@
import asyncio import asyncio
import aiohttp import aiohttp
from .device_error import DeviceError from .vm_error import VMError
class BaseManager: class BaseManager:
@ -69,10 +69,10 @@ class BaseManager:
identifier = i identifier = i
break break
if identifier == 0: if identifier == 0:
raise DeviceError("Maximum number of VM instances reached") raise VMError("Maximum number of VM instances reached")
else: else:
if identifier in self._vms: 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) vm = self._VM_CLASS(vmname, identifier, self.port_manager)
yield from vm.wait_for_creation() yield from vm.wait_for_creation()
self._vms[vm.id] = vm self._vms[vm.id] = vm

View File

@ -17,12 +17,13 @@
import asyncio import asyncio
from .device_error import DeviceError from .vm_error import VMError
from .attic import find_unused_port from .attic import find_unused_port
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class BaseVM: class BaseVM:
_allocated_console_ports = [] _allocated_console_ports = []
@ -40,7 +41,6 @@ class BaseVM:
name=self._name, name=self._name,
id=self._id)) id=self._id))
def _allocate_console(self): def _allocate_console(self):
if not self._console: if not self._console:
# allocate a console port # allocate a console port
@ -50,10 +50,10 @@ class BaseVM:
self._console_host, self._console_host,
ignore_ports=self._allocated_console_ports) ignore_ports=self._allocated_console_ports)
except Exception as e: except Exception as e:
raise DeviceError(e) raise VMError(e)
if self._console in self._allocated_console_ports: 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) self._allocated_console_ports.append(self._console)
@ -76,7 +76,7 @@ class BaseVM:
""" """
if console in self._allocated_console_ports: 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._allocated_console_ports.remove(self._console)
self._console = console self._console = console
@ -122,7 +122,7 @@ class BaseVM:
try: try:
yield from self._create() yield from self._create()
self._created.set_result(True) self._created.set_result(True)
except DeviceError as e: except VMError as e:
self._created.set_exception(e) self._created.set_exception(e)
return return
@ -132,7 +132,7 @@ class BaseVM:
try: try:
yield from asyncio.wait_for(self._execute(subcommand, args), timeout=timeout) yield from asyncio.wait_for(self._execute(subcommand, args), timeout=timeout)
except asyncio.TimeoutError: 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) future.set_result(True)
except Exception as e: except Exception as e:
future.set_exception(e) future.set_exception(e)
@ -141,7 +141,7 @@ class BaseVM:
return self._created return self._created
@asyncio.coroutine @asyncio.coroutine
def start(): def start(self):
""" """
Starts the VM process. Starts the VM process.
""" """
@ -159,5 +159,5 @@ class BaseVM:
args.insert(0, future) args.insert(0, future)
self._queue.put_nowait(args) self._queue.put_nowait(args)
except asyncio.qeues.QueueFull: except asyncio.qeues.QueueFull:
raise DeviceError("Queue is full") raise VMError("Queue is full")
return future return future

View File

@ -18,6 +18,7 @@
import ipaddress import ipaddress
from .attic import find_unused_port from .attic import find_unused_port
class PortManager: class PortManager:
""" """
:param console: TCP console port :param console: TCP console port
@ -53,7 +54,7 @@ class PortManager:
self._used_ports.add(port) self._used_ports.add(port)
return port return port
def reserve_port(port): def reserve_port(self, port):
""" """
Reserve a specific port number Reserve a specific port number
@ -63,11 +64,12 @@ class PortManager:
raise Exception("Port already {} in use".format(port)) raise Exception("Port already {} in use".format(port))
self._used_ports.add(port) self._used_ports.add(port)
def release_port(port): def release_port(self, port):
""" """
Release a specific port number Release a specific port number
:param port: Port number :param port: Port number
""" """
self._used_ports.remove(port) self._used_ports.remove(port)

View File

@ -16,5 +16,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
class DeviceError(Exception): class VMError(Exception):
pass pass

View File

@ -19,9 +19,10 @@
Custom exceptions for VPCS module. 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): def __init__(self, message, original_exception=None):

View File

@ -20,7 +20,7 @@ import jsonschema
import asyncio import asyncio
import aiohttp import aiohttp
from ..modules.device_error import DeviceError from ..modules.vm_error import VMError
from .response import Response from .response import Response
@ -98,7 +98,7 @@ class Route(object):
response = Response(route=route) response = Response(route=route)
response.set_status(e.status) response.set_status(e.status)
response.json({"message": e.text, "status": e.status}) response.json({"message": e.text, "status": e.status})
except DeviceError as e: except VMError as e:
response = Response(route=route) response = Response(route=route)
response.set_status(400) response.set_status(400)
response.json({"message": str(e), "status": 400}) response.json({"message": str(e), "status": 400})