Drop code for temporary projects

Fix https://github.com/GNS3/gns3-gui/issues/982
This commit is contained in:
Julien Duponchelle committed 2016-05-24 17:57:04 +02:00
1 parent df73f80bf5
commit a797038aeb
12 files changed
+25 -224

No files matched your search

+3 -68
View File
@@ -44,10 +44,9 @@ class Project:
:param project_id: force project identifier (None by default auto generate an UUID)
:param path: path of the project. (None use the standard directory)
:param temporary: boolean to tell if the project is a temporary project (destroy when closed)
"""
def __init__(self, name=None, project_id=None, path=None, temporary=False):
def __init__(self, name=None, project_id=None, path=None):
self._name = name
try:
@@ -58,7 +57,6 @@ class Project:
self._nodes = set()
self._nodes_to_destroy = set()
self.temporary = temporary
self._used_tcp_ports = set()
self._used_udp_ports = set()
@@ -83,8 +81,7 @@ class Project:
return {
"name": self._name,
"project_id": self._id,
"temporary": self._temporary
"project_id": self._id
}
def _config(self):
@@ -114,19 +111,6 @@ class Project:
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modify the project directory path")
self._path = path
self._update_temporary_file()
@asyncio.coroutine
def clean_old_path(self, old_path):
"""
Called after a project location change. All the compute should
have been notified before
"""
if self._temporary:
try:
yield from wait_run_in_executor(shutil.rmtree, old_path)
except OSError as e:
log.warn("Can't remove temporary directory {}: {}".format(old_path, e))
@property
def name(self):
@@ -145,20 +129,6 @@ class Project:
return self._nodes
@property
def temporary(self):
return self._temporary
@temporary.setter
def temporary(self, temporary):
if hasattr(self, 'temporary') and temporary == self._temporary:
return
self._temporary = temporary
self._update_temporary_file()
def record_tcp_port(self, port):
"""
Associate a reserved TCP port number with this project.
@@ -199,27 +169,6 @@ class Project:
if port in self._used_udp_ports:
self._used_udp_ports.remove(port)
def _update_temporary_file(self):
"""
Update the .gns3_temporary file in order to reflect the current project status.
"""
if not hasattr(self, "_path"):
return
if self._temporary:
try:
with open(os.path.join(self._path, ".gns3_temporary"), 'w+') as f:
f.write("1")
except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not create temporary project: {}".format(e))
else:
if os.path.exists(os.path.join(self._path, ".gns3_temporary")):
try:
os.remove(os.path.join(self._path, ".gns3_temporary"))
except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not mark project as no longer temporary: {}".format(e))
def module_working_directory(self, module_name):
"""
Returns a working directory for the module
@@ -319,7 +268,7 @@ class Project:
for module in self.compute():
yield from module.instance().project_closing(self)
yield from self._close_and_clean(self._temporary)
yield from self._close_and_clean(False)
for module in self.compute():
yield from module.instance().project_closed(self)
@@ -395,20 +344,6 @@ class Project:
for module in self.compute():
yield from module.instance().project_closed(self)
@classmethod
def clean_project_directory(cls):
"""
At startup drop old temporary project. After a crash for example
"""
directory = get_default_project_directory()
if os.path.exists(directory):
for project in os.listdir(directory):
path = os.path.join(directory, project)
if os.path.exists(os.path.join(path, ".gns3_temporary")):
log.warning("Purge old temporary project {}".format(project))
shutil.rmtree(path)
def compute(self):
"""
Returns all loaded modules from compute.
+2 -2
View File
@@ -70,7 +70,7 @@ class ProjectManager:
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
return self._projects[project_id]
def create_project(self, name=None, project_id=None, path=None, temporary=False):
def create_project(self, name=None, project_id=None, path=None):
"""
Create a project and keep a references to it in project manager.
@@ -79,7 +79,7 @@ class ProjectManager:
if project_id is not None and project_id in self._projects:
return self._projects[project_id]
project = Project(name=name, project_id=project_id, path=path, temporary=temporary)
project = Project(name=name, project_id=project_id, path=path)
self._projects[project.id] = project
return project
+6 -9
View File
@@ -46,16 +46,14 @@ class Controller:
self._config_file = os.path.join(config_path, "gns3_controller.conf")
server_config = Config.instance().get_section_config("Server")
print(server_config)
if server_config.getboolean("local", False) is True:
print("MMOOOOOOONKEYYYYYY")
self._computes["local"] = Compute(compute_id="local",
controller=self,
protocol=server_config.get("protocol", "http"),
host=server_config.get("host", "localhost"),
port=server_config.getint("port", 3080),
user=server_config.get("user", ""),
password=server_config.get("password", ""))
controller=self,
protocol=server_config.get("protocol", "http"),
host=server_config.get("host", "localhost"),
port=server_config.getint("port", 3080),
user=server_config.get("user", ""),
password=server_config.get("password", ""))
def save(self):
"""
@@ -107,7 +105,6 @@ class Controller:
"""
if compute_id not in self._computes:
# We disallow to create from the outside the
if compute_id == 'local':
return None
+1 -10
View File
@@ -34,10 +34,9 @@ class Project:
:param project_id: force project identifier (None by default auto generate an UUID)
:param path: path of the project. (None use the standard directory)
:param temporary: boolean to tell if the project is a temporary project (destroy when closed)
"""
def __init__(self, name=None, project_id=None, path=None, temporary=False, controller=None):
def __init__(self, name=None, project_id=None, path=None, controller=None):
self._controller = controller
self._name = name
@@ -54,7 +53,6 @@ class Project:
path = os.path.join(get_default_project_directory(), self._id)
self.path = path
self._temporary = temporary
self._computes = set()
self._nodes = {}
self._links = {}
@@ -74,10 +72,6 @@ class Project:
def id(self):
return self._id
@property
def temporary(self):
return self._temporary
@property
def path(self):
return self._path
@@ -126,14 +120,12 @@ class Project:
yield from compute.post("/projects", data={
"name": self._name,
"project_id": self._id,
"temporary": self._temporary,
"path": self._path
})
else:
yield from compute.post("/projects", data={
"name": self._name,
"project_id": self._id,
"temporary": self._temporary
})
self._project_created_on_compute.add(compute)
@@ -235,6 +227,5 @@ class Project:
return {
"name": self._name,
"project_id": self._id,
"temporary": self._temporary,
"path": self._path
}
@@ -73,8 +73,7 @@ class ProjectHandler:
p = pm.create_project(
name=request.json.get("name"),
path=request.json.get("path"),
project_id=request.json.get("project_id"),
temporary=request.json.get("temporary", False)
project_id=request.json.get("project_id")
)
response.set_status(201)
response.json(p)
@@ -120,9 +119,6 @@ class ProjectHandler:
project.path = project_path
for module in MODULES:
yield from module.instance().project_moved(project)
yield from project.clean_old_path(old_path)
# Very important: we need to remove temporary flag after moving the project
project.temporary = request.json.get("temporary", project.temporary)
response.json(project)
@Route.post(
@@ -47,8 +47,7 @@ class ProjectHandler:
controller = Controller.instance()
project = yield from controller.add_project(name=request.json.get("name"),
path=request.json.get("path"),
project_id=request.json.get("project_id"),
temporary=request.json.get("temporary", False))
project_id=request.json.get("project_id"))
response.set_status(201)
response.json(project)
-3
View File
@@ -31,7 +31,6 @@ from gns3server.web.web_server import WebServer
from gns3server.web.logger import init_logger
from gns3server.version import __version__
from gns3server.config import Config
from gns3server.compute.project import Project
from gns3server.crash_report import CrashReport
@@ -224,8 +223,6 @@ def run():
log.critical("The current working directory doesn't exist")
return
Project.clean_project_directory()
CrashReport.instance()
host = server_config["host"]
port = int(server_config["port"])
+2 -14
View File
@@ -37,11 +37,7 @@ PROJECT_CREATE_SCHEMA = {
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"temporary": {
"description": "Whether the project is a temporary project or not",
"type": "boolean"
},
}
},
"additionalProperties": False,
}
@@ -56,10 +52,6 @@ PROJECT_UPDATE_SCHEMA = {
"type": ["string", "null"],
"minLength": 1
},
"temporary": {
"description": "Whether the project is a temporary project or not",
"type": "boolean"
},
"path": {
"description": "Path of the project on the server (work only with --local)",
"type": ["string", "null"]
@@ -85,10 +77,6 @@ PROJECT_OBJECT_SCHEMA = {
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"temporary": {
"description": "Whether the project is a temporary project or not",
"type": "boolean"
},
"path": {
"description": "Project directory",
"type": ["string", "null"],
@@ -96,7 +84,7 @@ PROJECT_OBJECT_SCHEMA = {
}
},
"additionalProperties": False,
"required": ["project_id", "temporary"]
"required": ["project_id"]
}
PROJECT_LIST_SCHEMA = {