mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
Fixes issues to restore the correct working directories for IOU and VPCS devices when loading a project.
Prevent multiple clients to use the same server (this is not supported yet).
This commit is contained in:
1 parent
9ef715e341
commit
f9ee38dd55
6 files changed
+49
-58
No files matched your search
@@ -263,30 +263,6 @@ class IOU(IModule):
|
||||
|
||||
log.debug("received request {}".format(request))
|
||||
|
||||
def test_result(self, message, result="error"):
|
||||
"""
|
||||
"""
|
||||
|
||||
return {"result": result, "message": message}
|
||||
|
||||
@IModule.route("iou.test_settings")
|
||||
def test_settings(self, request):
|
||||
"""
|
||||
"""
|
||||
|
||||
response = []
|
||||
|
||||
# test iourc
|
||||
if self._iourc == "":
|
||||
response.append(self.test_result("No iourc file has been added"))
|
||||
elif not os.path.isfile(self._iourc):
|
||||
response.append(self.test_result("iourc file {} is not accessible".format(self._iourc)))
|
||||
else:
|
||||
#TODO: check hostname + license inside the file
|
||||
pass
|
||||
|
||||
self.send_response(response)
|
||||
|
||||
@IModule.route("iou.create")
|
||||
def iou_create(self, request):
|
||||
"""
|
||||
@@ -312,17 +288,10 @@ class IOU(IModule):
|
||||
return
|
||||
|
||||
name = request["name"]
|
||||
console = request.get("console")
|
||||
iou_path = request["path"]
|
||||
console = request.get("console")
|
||||
|
||||
try:
|
||||
try:
|
||||
os.makedirs(self._working_dir)
|
||||
except FileExistsError:
|
||||
pass
|
||||
except OSError as e:
|
||||
raise IOUError("Could not create working directory {}".format(e))
|
||||
|
||||
iou_instance = IOUDevice(name,
|
||||
iou_path,
|
||||
self._working_dir,
|
||||
|
||||
@@ -83,7 +83,7 @@ class IOUDevice(object):
|
||||
self._iourc = ""
|
||||
self._iouyap = ""
|
||||
self._console = console
|
||||
self._working_dir = working_dir
|
||||
self._working_dir = None
|
||||
self._command = []
|
||||
self._process = None
|
||||
self._iouyap_process = None
|
||||
@@ -106,8 +106,8 @@ class IOUDevice(object):
|
||||
self._ram = 256 # Megabytes
|
||||
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
|
||||
|
||||
# update the working directory
|
||||
self.working_dir = working_dir
|
||||
# create the device own working directory
|
||||
self.working_dir = os.path.join(working_dir, "iou", "{}".format(self._name))
|
||||
|
||||
if not self._console:
|
||||
# allocate a console port
|
||||
@@ -183,6 +183,18 @@ class IOUDevice(object):
|
||||
:param new_name: name
|
||||
"""
|
||||
|
||||
if self._started:
|
||||
raise IOUError("Cannot change the name to {} while the device is running".format(new_name))
|
||||
|
||||
new_working_dir = os.path.join(os.path.dirname(self._working_dir), new_name)
|
||||
try:
|
||||
shutil.move(self._working_dir, new_working_dir)
|
||||
self._working_dir = new_working_dir
|
||||
except OSError as e:
|
||||
raise IOUError("Could not move working directory from {} to {}: {}".format(self._working_dir,
|
||||
new_working_dir,
|
||||
e))
|
||||
|
||||
if self._startup_config:
|
||||
# update the startup-config
|
||||
config_path = os.path.join(self._working_dir, "startup-config")
|
||||
@@ -288,8 +300,6 @@ class IOUDevice(object):
|
||||
:param working_dir: path to the working directory
|
||||
"""
|
||||
|
||||
# create our own working directory
|
||||
working_dir = os.path.join(working_dir, "iou", "device-{}".format(self._id))
|
||||
try:
|
||||
os.makedirs(working_dir)
|
||||
except FileExistsError:
|
||||
@@ -345,7 +355,8 @@ class IOUDevice(object):
|
||||
"""
|
||||
|
||||
self.stop()
|
||||
self._instances.remove(self._id)
|
||||
if self._id in self._instances:
|
||||
self._instances.remove(self._id)
|
||||
|
||||
if self.console:
|
||||
self._allocated_console_ports.remove(self.console)
|
||||
@@ -359,7 +370,8 @@ class IOUDevice(object):
|
||||
"""
|
||||
|
||||
self.stop()
|
||||
self._instances.remove(self._id)
|
||||
if self._id in self._instances:
|
||||
self._instances.remove(self._id)
|
||||
|
||||
if self.console:
|
||||
self._allocated_console_ports.remove(self.console)
|
||||
|
||||
Reference in new issue
Block a user