mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-16 02:51:00 +00:00
Support for project names on remote server.
This commit is contained in:
parent
872515fa78
commit
f99128b2a4
@ -23,6 +23,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import base64
|
import base64
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import shutil
|
||||||
from gns3server.modules import IModule
|
from gns3server.modules import IModule
|
||||||
import gns3server.jsonrpc as jsonrpc
|
import gns3server.jsonrpc as jsonrpc
|
||||||
|
|
||||||
@ -105,13 +106,12 @@ class Dynamips(IModule):
|
|||||||
|
|
||||||
self._hypervisor_manager = None
|
self._hypervisor_manager = None
|
||||||
self._hypervisor_manager_settings = {}
|
self._hypervisor_manager_settings = {}
|
||||||
self._remote_server = False
|
|
||||||
self._routers = {}
|
self._routers = {}
|
||||||
self._ethernet_switches = {}
|
self._ethernet_switches = {}
|
||||||
self._frame_relay_switches = {}
|
self._frame_relay_switches = {}
|
||||||
self._atm_switches = {}
|
self._atm_switches = {}
|
||||||
self._ethernet_hubs = {}
|
self._ethernet_hubs = {}
|
||||||
self._projects_dir = os.path.join(kwargs["projects_dir"], "dynamips")
|
self._projects_dir = kwargs["projects_dir"]
|
||||||
self._tempdir = kwargs["temp_dir"]
|
self._tempdir = kwargs["temp_dir"]
|
||||||
self._working_dir = self._projects_dir
|
self._working_dir = self._projects_dir
|
||||||
self._dynamips = ""
|
self._dynamips = ""
|
||||||
@ -189,7 +189,6 @@ class Dynamips(IModule):
|
|||||||
self._atm_switches.clear()
|
self._atm_switches.clear()
|
||||||
|
|
||||||
self._hypervisor_manager = None
|
self._hypervisor_manager = None
|
||||||
self._remote_server = False
|
|
||||||
log.info("dynamips module has been reset")
|
log.info("dynamips module has been reset")
|
||||||
|
|
||||||
def start_hypervisor_manager(self):
|
def start_hypervisor_manager(self):
|
||||||
@ -206,18 +205,19 @@ class Dynamips(IModule):
|
|||||||
raise DynamipsError("Dynamips {} is not executable".format(self._dynamips))
|
raise DynamipsError("Dynamips {} is not executable".format(self._dynamips))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(self._working_dir)
|
workdir = os.path.join(self._working_dir, "dynamips")
|
||||||
|
os.makedirs(workdir)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise DynamipsError("Could not create working directory {}".format(e))
|
raise DynamipsError("Could not create working directory {}".format(e))
|
||||||
|
|
||||||
# check if the working directory is writable
|
# check if the working directory is writable
|
||||||
if not os.access(self._working_dir, os.W_OK):
|
if not os.access(workdir, os.W_OK):
|
||||||
raise DynamipsError("Cannot write to working directory {}".format(self._working_dir))
|
raise DynamipsError("Cannot write to working directory {}".format(workdir))
|
||||||
|
|
||||||
log.info("starting the hypervisor manager with Dynamips working directory set to '{}'".format(self._working_dir))
|
log.info("starting the hypervisor manager with Dynamips working directory set to '{}'".format(workdir))
|
||||||
self._hypervisor_manager = HypervisorManager(self._dynamips, self._working_dir, self._host)
|
self._hypervisor_manager = HypervisorManager(self._dynamips, workdir, self._host)
|
||||||
|
|
||||||
for name, value in self._hypervisor_manager_settings.items():
|
for name, value in self._hypervisor_manager_settings.items():
|
||||||
if hasattr(self._hypervisor_manager, name) and getattr(self._hypervisor_manager, name) != value:
|
if hasattr(self._hypervisor_manager, name) and getattr(self._hypervisor_manager, name) != value:
|
||||||
@ -244,22 +244,39 @@ class Dynamips(IModule):
|
|||||||
log.debug("received request {}".format(request))
|
log.debug("received request {}".format(request))
|
||||||
|
|
||||||
#TODO: JSON schema validation
|
#TODO: JSON schema validation
|
||||||
# starts the hypervisor manager if it hasn't been started yet
|
|
||||||
if not self._hypervisor_manager:
|
if not self._hypervisor_manager:
|
||||||
self._dynamips = request.pop("path")
|
self._dynamips = request.pop("path")
|
||||||
|
|
||||||
if "working_dir" in request:
|
if "working_dir" in request:
|
||||||
self._working_dir = os.path.join(request.pop("working_dir"), "dynamips")
|
self._working_dir = request.pop("working_dir")
|
||||||
log.info("this server is local")
|
log.info("this server is local")
|
||||||
else:
|
else:
|
||||||
self._remote_server = True
|
|
||||||
log.info("this server is remote")
|
|
||||||
self._working_dir = os.path.join(self._projects_dir, request["project_name"])
|
self._working_dir = os.path.join(self._projects_dir, request["project_name"])
|
||||||
log.info("this server is remote with working directory path to {}".format(self._working_dir))
|
log.info("this server is remote with working directory path to {}".format(self._working_dir))
|
||||||
|
|
||||||
self._hypervisor_manager_settings = request
|
self._hypervisor_manager_settings = request
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
if "project_name" in request:
|
||||||
|
new_working_dir = os.path.join(self._projects_dir, request["project_name"])
|
||||||
|
if self._projects_dir != self._working_dir != new_working_dir:
|
||||||
|
|
||||||
|
# trick to avoid file locks by Dynamips on Windows
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
self._hypervisor_manager.working_dir = tempfile.gettempdir()
|
||||||
|
|
||||||
|
if not os.path.isdir(new_working_dir):
|
||||||
|
try:
|
||||||
|
shutil.move(self._working_dir, new_working_dir)
|
||||||
|
except OSError as e:
|
||||||
|
log.error("could not move working directory from {} to {}: {}".format(self._working_dir,
|
||||||
|
new_working_dir,
|
||||||
|
e))
|
||||||
|
return
|
||||||
|
|
||||||
|
self._hypervisor_manager.working_dir = os.path.join(new_working_dir, "dynamips")
|
||||||
|
self._working_dir = new_working_dir
|
||||||
|
|
||||||
# apply settings to the hypervisor manager
|
# apply settings to the hypervisor manager
|
||||||
for name, value in request.items():
|
for name, value in request.items():
|
||||||
if hasattr(self._hypervisor_manager, name) and getattr(self._hypervisor_manager, name) != value:
|
if hasattr(self._hypervisor_manager, name) and getattr(self._hypervisor_manager, name) != value:
|
||||||
|
@ -26,6 +26,7 @@ import tempfile
|
|||||||
import fcntl
|
import fcntl
|
||||||
import struct
|
import struct
|
||||||
import socket
|
import socket
|
||||||
|
import shutil
|
||||||
from gns3server.modules import IModule
|
from gns3server.modules import IModule
|
||||||
from gns3server.config import Config
|
from gns3server.config import Config
|
||||||
from .iou_device import IOUDevice
|
from .iou_device import IOUDevice
|
||||||
@ -75,7 +76,6 @@ class IOU(IModule):
|
|||||||
|
|
||||||
# a new process start when calling IModule
|
# a new process start when calling IModule
|
||||||
IModule.__init__(self, name, *args, **kwargs)
|
IModule.__init__(self, name, *args, **kwargs)
|
||||||
self._remote_server = False
|
|
||||||
self._iou_instances = {}
|
self._iou_instances = {}
|
||||||
self._console_start_port_range = 4001
|
self._console_start_port_range = 4001
|
||||||
self._console_end_port_range = 4512
|
self._console_end_port_range = 4512
|
||||||
@ -84,7 +84,7 @@ class IOU(IModule):
|
|||||||
self._udp_end_port_range = 40001
|
self._udp_end_port_range = 40001
|
||||||
self._current_udp_port = self._udp_start_port_range
|
self._current_udp_port = self._udp_start_port_range
|
||||||
self._host = kwargs["host"]
|
self._host = kwargs["host"]
|
||||||
self._projects_dir = os.path.join(kwargs["projects_dir"], "iou")
|
self._projects_dir = kwargs["projects_dir"]
|
||||||
self._tempdir = kwargs["temp_dir"]
|
self._tempdir = kwargs["temp_dir"]
|
||||||
self._working_dir = self._projects_dir
|
self._working_dir = self._projects_dir
|
||||||
self._iourc = ""
|
self._iourc = ""
|
||||||
@ -202,16 +202,26 @@ class IOU(IModule):
|
|||||||
|
|
||||||
if "working_dir" in request:
|
if "working_dir" in request:
|
||||||
new_working_dir = os.path.join(request["working_dir"], "iou")
|
new_working_dir = os.path.join(request["working_dir"], "iou")
|
||||||
if self._working_dir != new_working_dir:
|
log.info("this server is local with working directory path to {}".format(new_working_dir))
|
||||||
self._working_dir = new_working_dir
|
|
||||||
log.info("this server is local with working directory path to {}".format(self._working_dir))
|
|
||||||
for iou_id in self._iou_instances:
|
|
||||||
iou_instance = self._iou_instances[iou_id]
|
|
||||||
iou_instance.working_dir = self._working_dir
|
|
||||||
else:
|
else:
|
||||||
self._remote_server = True
|
new_working_dir = os.path.join(self._projects_dir, request["project_name"])
|
||||||
self._working_dir = os.path.join(self._projects_dir, request["project_name"])
|
log.info("this server is remote with working directory path to {}".format(new_working_dir))
|
||||||
log.info("this server is remote with working directory path to {}".format(self._working_dir))
|
if self._projects_dir != self._working_dir != new_working_dir:
|
||||||
|
if not os.path.isdir(new_working_dir):
|
||||||
|
try:
|
||||||
|
shutil.move(self._working_dir, new_working_dir)
|
||||||
|
except OSError as e:
|
||||||
|
log.error("could not move working directory from {} to {}: {}".format(self._working_dir,
|
||||||
|
new_working_dir,
|
||||||
|
e))
|
||||||
|
return
|
||||||
|
|
||||||
|
# update the working directory if it has changed
|
||||||
|
if self._working_dir != new_working_dir:
|
||||||
|
self._working_dir = new_working_dir
|
||||||
|
for iou_id in self._iou_instances:
|
||||||
|
iou_instance = self._iou_instances[iou_id]
|
||||||
|
iou_instance.working_dir = self._working_dir
|
||||||
|
|
||||||
if "console_start_port_range" in request and "console_end_port_range" in request:
|
if "console_start_port_range" in request and "console_end_port_range" in request:
|
||||||
self._console_start_port_range = request["console_start_port_range"]
|
self._console_start_port_range = request["console_start_port_range"]
|
||||||
|
@ -245,7 +245,7 @@ class IOUDevice(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# create our own working directory
|
# create our own working directory
|
||||||
working_dir = os.path.join(working_dir, "device-{}".format(self._id))
|
working_dir = os.path.join(working_dir, "iou", "device-{}".format(self._id))
|
||||||
try:
|
try:
|
||||||
os.makedirs(working_dir)
|
os.makedirs(working_dir)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
|
4
setup.py
4
setup.py
@ -45,8 +45,8 @@ setup(
|
|||||||
description="GNS3 server to asynchronously manage emulators",
|
description="GNS3 server to asynchronously manage emulators",
|
||||||
long_description=open("README.rst", "r").read(),
|
long_description=open("README.rst", "r").read(),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"tornado >= 2.0",
|
"tornado >= 3.1",
|
||||||
"pyzmq",
|
"pyzmq == 14.0.1",
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
"console_scripts": [
|
"console_scripts": [
|
||||||
|
Loading…
Reference in New Issue
Block a user