mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Use PATH environnement variable for searching binary
This commit is contained in:
1 parent
bf6f62e629
commit
8e307c8cbb
3 files changed
+35
-62
No files matched your search
@@ -19,74 +19,28 @@
|
||||
import asyncio
|
||||
from .vm_error import VMError
|
||||
from .attic import find_unused_port
|
||||
from ..config import Config
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BaseVM:
|
||||
_allocated_console_ports = []
|
||||
|
||||
def __init__(self, name, identifier, port_manager):
|
||||
|
||||
self._loop = asyncio.get_event_loop()
|
||||
self._allocate_console()
|
||||
self._queue = asyncio.Queue()
|
||||
self._name = name
|
||||
self._id = identifier
|
||||
self._created = asyncio.Future()
|
||||
self._worker = asyncio.async(self._run())
|
||||
self._port_manager = port_manager
|
||||
self._config = Config.instance()
|
||||
log.info("{type} device {name} [id={id}] has been created".format(
|
||||
type=self.__class__.__name__,
|
||||
name=self._name,
|
||||
id=self._id))
|
||||
|
||||
def _allocate_console(self):
|
||||
|
||||
if not self._console:
|
||||
# allocate a console port
|
||||
try:
|
||||
self._console = find_unused_port(self._console_start_port_range,
|
||||
self._console_end_port_range,
|
||||
self._console_host,
|
||||
ignore_ports=self._allocated_console_ports)
|
||||
except Exception as e:
|
||||
raise VMError(e)
|
||||
|
||||
if self._console in self._allocated_console_ports:
|
||||
raise VMError("Console port {} is already used by another VM".format(self._console))
|
||||
self._allocated_console_ports.append(self._console)
|
||||
|
||||
|
||||
@property
|
||||
def console(self):
|
||||
"""
|
||||
Returns the TCP console port.
|
||||
|
||||
:returns: console port (integer)
|
||||
"""
|
||||
|
||||
return self._console
|
||||
|
||||
@console.setter
|
||||
def console(self, console):
|
||||
"""
|
||||
Sets the TCP console port.
|
||||
|
||||
:param console: console port (integer)
|
||||
"""
|
||||
|
||||
if console in self._allocated_console_ports:
|
||||
raise VMError("Console port {} is already used by another VM".format(console))
|
||||
|
||||
self._allocated_console_ports.remove(self._console)
|
||||
self._console = console
|
||||
self._allocated_console_ports.append(self._console)
|
||||
log.info("{type} {name} [id={id}]: console port set to {port}".format(type=self.__class__.__name__,
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
port=console))
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
|
||||
@@ -28,6 +28,7 @@ import shutil
|
||||
import re
|
||||
import asyncio
|
||||
import socket
|
||||
import shutil
|
||||
|
||||
from pkg_resources import parse_version
|
||||
from .vpcs_error import VPCSError
|
||||
@@ -52,17 +53,17 @@ class VPCSDevice(BaseVM):
|
||||
:param console: TCP console port
|
||||
"""
|
||||
def __init__(self, name, vpcs_id, port_manager,
|
||||
path = None,
|
||||
working_dir = None,
|
||||
console=None):
|
||||
working_dir = None, console = None):
|
||||
super().__init__(name, vpcs_id, port_manager)
|
||||
|
||||
#self._path = path
|
||||
#self._working_dir = working_dir
|
||||
# TODO: Hardcodded for testing
|
||||
self._path = "/usr/local/bin/vpcs"
|
||||
self._working_dir = "/tmp"
|
||||
self._path = self._config.get_section_config("VPCS").get("path", "vpcs")
|
||||
|
||||
self._working_dir = "/tmp"
|
||||
self._console = console
|
||||
|
||||
self._command = []
|
||||
self._process = None
|
||||
self._vpcs_stdout_file = ""
|
||||
@@ -89,12 +90,15 @@ class VPCSDevice(BaseVM):
|
||||
raise VPCSError(e)
|
||||
|
||||
self._check_requirements()
|
||||
super().__init__(name, vpcs_id, port_manager)
|
||||
|
||||
def _check_requirements(self):
|
||||
"""
|
||||
Check if VPCS is available with the correct version
|
||||
"""
|
||||
if self._path == "vpcs":
|
||||
self._path = shutil.which("vpcs")
|
||||
|
||||
|
||||
if not self._path:
|
||||
raise VPCSError("No path to a VPCS executable has been set")
|
||||
|
||||
@@ -106,6 +110,16 @@ class VPCSDevice(BaseVM):
|
||||
|
||||
self._check_vpcs_version()
|
||||
|
||||
@property
|
||||
def console(self):
|
||||
"""
|
||||
Returns the console port of this VPCS device.
|
||||
|
||||
:returns: console port
|
||||
"""
|
||||
|
||||
return self._console
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user