mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Prevent multiple projects with the same ID to be created.
This commit is contained in:
1 parent
349d9d4540
commit
54fc873be5
10 files changed
+61
-27
No files matched your search
@@ -165,6 +165,7 @@ class BaseManager:
|
||||
if hasattr(self, "get_legacy_vm_workdir_name"):
|
||||
# move old project VM files to a new location
|
||||
|
||||
log.info("Converting old project...")
|
||||
project_name = os.path.basename(project.path)
|
||||
project_files_dir = os.path.join(project.path, "{}-files".format(project_name))
|
||||
module_path = os.path.join(project_files_dir, self.module_name.lower())
|
||||
@@ -175,17 +176,21 @@ class BaseManager:
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not move VM working directory: {} to {} {}".format(vm_working_dir, new_vm_working_dir, e))
|
||||
|
||||
if os.listdir(module_path) == []:
|
||||
try:
|
||||
try:
|
||||
if not os.listdir(module_path):
|
||||
os.rmdir(module_path)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not delete {}: {}".format(module_path, e))
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not delete {}: {}".format(module_path, e))
|
||||
except FileNotFoundError as e:
|
||||
log.warning(e)
|
||||
|
||||
if os.listdir(project_files_dir) == []:
|
||||
try:
|
||||
try:
|
||||
if not os.listdir(project_files_dir):
|
||||
os.rmdir(project_files_dir)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not delete {}: {}".format(project_files_dir, e))
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not delete {}: {}".format(project_files_dir, e))
|
||||
except FileNotFoundError as e:
|
||||
log.warning(e)
|
||||
|
||||
if not vm_id:
|
||||
vm_id = str(uuid4())
|
||||
|
||||
@@ -310,6 +310,7 @@ class Router(BaseVM):
|
||||
# router is already closed
|
||||
return
|
||||
|
||||
log.debug('Router "{name}" [{id}] is closing'.format(name=self._name, id=self._id))
|
||||
if self._dynamips_id in self._dynamips_ids[self._project.id]:
|
||||
self._dynamips_ids[self._project.id].remove(self._dynamips_id)
|
||||
|
||||
|
||||
@@ -105,6 +105,8 @@ class IOUVM(BaseVM):
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
|
||||
log.debug('IOU "{name}" [{id}] is closing'.format(name=self._name, id=self._id))
|
||||
|
||||
if self._console:
|
||||
self._manager.port_manager.release_tcp_port(self._console)
|
||||
self._console = None
|
||||
|
||||
@@ -70,7 +70,7 @@ class Project:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
|
||||
self.path = path
|
||||
|
||||
log.debug("Create project {id} in directory {path}".format(path=self._path, id=self._id))
|
||||
log.info("Project {id} with path '{path}' created".format(path=self._path, id=self._id))
|
||||
|
||||
def __json__(self):
|
||||
|
||||
@@ -278,8 +278,11 @@ class Project:
|
||||
if cleanup and os.path.exists(self.path):
|
||||
try:
|
||||
yield from wait_run_in_executor(shutil.rmtree, self.path)
|
||||
log.info("Project {id} with path '{path}' deleted".format(path=self._path, id=self._id))
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not delete the project directory: {}".format(e))
|
||||
else:
|
||||
log.info("Project {id} with path '{path}' closed".format(path=self._path, id=self._id))
|
||||
|
||||
port_manager = PortManager.instance()
|
||||
if port_manager.tcp_ports:
|
||||
|
||||
@@ -60,13 +60,26 @@ class ProjectManager:
|
||||
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
|
||||
return self._projects[project_id]
|
||||
|
||||
def create_project(self, **kwargs):
|
||||
def create_project(self, project_id=None, path=None, temporary=False):
|
||||
"""
|
||||
Create a project and keep a references to it in project manager.
|
||||
|
||||
See documentation of Project for arguments
|
||||
"""
|
||||
|
||||
project = Project(**kwargs)
|
||||
if project_id is not None and project_id in self._projects:
|
||||
raise aiohttp.web.HTTPConflict(text="Project ID {} is already in use on this server".format(project_id))
|
||||
project = Project(project_id=project_id, path=path, temporary=temporary)
|
||||
self._projects[project.id] = project
|
||||
return project
|
||||
|
||||
def remove_project(self, project_id):
|
||||
"""
|
||||
Removes a Project instance from the list of projects in use.
|
||||
|
||||
:param project_id: Project identifier
|
||||
"""
|
||||
|
||||
if project_id not in self._projects:
|
||||
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
|
||||
del self._projects[project_id]
|
||||
@@ -647,6 +647,7 @@ class QemuVM(BaseVM):
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
|
||||
log.debug('QEMU VM "{name}" [{id}] is closing'.format(name=self._name, id=self._id))
|
||||
yield from self.stop()
|
||||
if self._console:
|
||||
self._manager.port_manager.release_tcp_port(self._console)
|
||||
|
||||
@@ -297,6 +297,7 @@ class VirtualBoxVM(BaseVM):
|
||||
# VM is already closed
|
||||
return
|
||||
|
||||
log.debug("VirtualBox VM '{name}' [{id}] is closing".format(name=self.name, id=self.id))
|
||||
if self._console:
|
||||
self._manager.port_manager.release_tcp_port(self._console)
|
||||
self._console = None
|
||||
|
||||
@@ -72,6 +72,7 @@ class VPCSVM(BaseVM):
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
|
||||
log.debug("VPCS {name} [{id}] is closing".format(name=self._name, id=self._id))
|
||||
if self._console:
|
||||
self._manager.port_manager.release_tcp_port(self._console)
|
||||
self._console = None
|
||||
@@ -297,10 +298,10 @@ class VPCSVM(BaseVM):
|
||||
port_number=port_number))
|
||||
|
||||
self._ethernet_adapter.add_nio(port_number, nio)
|
||||
log.info("VPCS {name} {id}]: {nio} added to port {port_number}".format(name=self._name,
|
||||
id=self.id,
|
||||
nio=nio,
|
||||
port_number=port_number))
|
||||
log.info("VPCS {name} [{id}]: {nio} added to port {port_number}".format(name=self._name,
|
||||
id=self.id,
|
||||
nio=nio,
|
||||
port_number=port_number))
|
||||
return nio
|
||||
|
||||
def port_remove_nio_binding(self, port_number):
|
||||
|
||||
Reference in new issue
Block a user