mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Rename Device to VM.
This commit is contained in:
parent
c1ef406311
commit
9e83329f14
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -18,6 +18,7 @@
|
||||
import ipaddress
|
||||
from .attic import find_unused_port
|
||||
|
||||
|
||||
class PortManager:
|
||||
"""
|
||||
:param console: TCP console port
|
||||
@ -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)
|
||||
|
||||
|
@ -16,5 +16,5 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
class DeviceError(Exception):
|
||||
class VMError(Exception):
|
||||
pass
|
@ -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):
|
||||
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user