mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-01 04:38:12 +00:00
Project status (opened / closed)
This commit is contained in:
parent
0569480953
commit
524f8991bc
@ -89,6 +89,23 @@ class Controller:
|
|||||||
for c in data["computes"]:
|
for c in data["computes"]:
|
||||||
yield from self.add_compute(**c)
|
yield from self.add_compute(**c)
|
||||||
|
|
||||||
|
# Preload the list of projects from disk
|
||||||
|
server_config = Config.instance().get_section_config("Server")
|
||||||
|
projects_path = os.path.expanduser(server_config.get("projects_path", "~/GNS3/projects"))
|
||||||
|
try:
|
||||||
|
for project_path in os.listdir(projects_path):
|
||||||
|
project_dir = os.path.join(projects_path, project_path)
|
||||||
|
if os.path.isdir(project_dir):
|
||||||
|
for file in os.listdir(project_dir):
|
||||||
|
if file.endswith(".gns3"):
|
||||||
|
try:
|
||||||
|
yield from self.load_project(os.path.join(project_dir, file), load=False)
|
||||||
|
except aiohttp.web_exceptions.HTTPConflict:
|
||||||
|
pass # Skip not compatible projects
|
||||||
|
except OSError as e:
|
||||||
|
log.error(str(e))
|
||||||
|
|
||||||
|
|
||||||
def is_enabled(self):
|
def is_enabled(self):
|
||||||
"""
|
"""
|
||||||
:returns: whether the current instance is the controller
|
:returns: whether the current instance is the controller
|
||||||
@ -187,11 +204,12 @@ class Controller:
|
|||||||
del self._projects[project.id]
|
del self._projects[project.id]
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def load_project(self, path):
|
def load_project(self, path, load=True):
|
||||||
"""
|
"""
|
||||||
Load a project from a .gns3
|
Load a project from a .gns3
|
||||||
|
|
||||||
:param path: Path of the .gns3
|
:param path: Path of the .gns3
|
||||||
|
:param load: Load the topology
|
||||||
"""
|
"""
|
||||||
topo_data = load_topology(path)
|
topo_data = load_topology(path)
|
||||||
topology = topo_data.pop("topology")
|
topology = topo_data.pop("topology")
|
||||||
@ -199,7 +217,8 @@ class Controller:
|
|||||||
topo_data.pop("revision")
|
topo_data.pop("revision")
|
||||||
topo_data.pop("type")
|
topo_data.pop("type")
|
||||||
|
|
||||||
project = yield from self.add_project(path=os.path.dirname(path), **topo_data)
|
project = yield from self.add_project(path=os.path.dirname(path), status="closed", **topo_data)
|
||||||
|
if load:
|
||||||
yield from project.load()
|
yield from project.load()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -40,12 +40,14 @@ class Project:
|
|||||||
|
|
||||||
:param project_id: force project identifier (None by default auto generate an UUID)
|
: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 path: path of the project. (None use the standard directory)
|
||||||
|
:param status: Status of the project (opened / closed)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name=None, project_id=None, path=None, controller=None):
|
def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened"):
|
||||||
|
|
||||||
self._controller = controller
|
self._controller = controller
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self._status = status
|
||||||
if project_id is None:
|
if project_id is None:
|
||||||
self._id = str(uuid4())
|
self._id = str(uuid4())
|
||||||
else:
|
else:
|
||||||
@ -82,6 +84,10 @@ class Project:
|
|||||||
def path(self):
|
def path(self):
|
||||||
return self._path
|
return self._path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
return self._status
|
||||||
|
|
||||||
@path.setter
|
@path.setter
|
||||||
def path(self, path):
|
def path(self, path):
|
||||||
check_path_allowed(path)
|
check_path_allowed(path)
|
||||||
@ -355,5 +361,6 @@ class Project:
|
|||||||
return {
|
return {
|
||||||
"name": self._name,
|
"name": self._name,
|
||||||
"project_id": self._id,
|
"project_id": self._id,
|
||||||
"path": self._path
|
"path": self._path,
|
||||||
|
"status": "opened"
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,10 @@ PROJECT_OBJECT_SCHEMA = {
|
|||||||
"description": "Project directory",
|
"description": "Project directory",
|
||||||
"type": ["string", "null"],
|
"type": ["string", "null"],
|
||||||
"minLength": 1
|
"minLength": 1
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"description": "Project status Read only",
|
||||||
|
"enum": ["opened", "closed"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
|
@ -7,11 +7,12 @@
|
|||||||
The purpose of this page is to help for GNS3 debug. This can be dropped
|
The purpose of this page is to help for GNS3 debug. This can be dropped
|
||||||
in futur GNS3 versions.
|
in futur GNS3 versions.
|
||||||
|
|
||||||
<h2>Opened projects</h2>
|
<h2>Projects</h2>
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>ID</td>
|
<th>ID</th>
|
||||||
|
<th>Status</th>
|
||||||
<th>Nodes</th>
|
<th>Nodes</th>
|
||||||
<th>Links</th>
|
<th>Links</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -19,6 +20,7 @@ in futur GNS3 versions.
|
|||||||
<tr>
|
<tr>
|
||||||
<td><a href="/projects/{{project.id}}">{{project.name}}</a></td>
|
<td><a href="/projects/{{project.id}}">{{project.name}}</a></td>
|
||||||
<td><a href="/projects/{{project.id}}">{{project.id}}</a></td>
|
<td><a href="/projects/{{project.id}}">{{project.id}}</a></td>
|
||||||
|
<td>{{project.status}}</td>
|
||||||
<td>{{project.nodes|length}}</td>
|
<td>{{project.nodes|length}}</td>
|
||||||
<td>{{project.links|length}}</td>
|
<td>{{project.links|length}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -43,7 +43,7 @@ def test_affect_uuid():
|
|||||||
|
|
||||||
def test_json(tmpdir):
|
def test_json(tmpdir):
|
||||||
p = Project()
|
p = Project()
|
||||||
assert p.__json__() == {"name": p.name, "project_id": p.id, "path": p.path}
|
assert p.__json__() == {"name": p.name, "project_id": p.id, "path": p.path, "status": "opened"}
|
||||||
|
|
||||||
|
|
||||||
def test_path(tmpdir):
|
def test_path(tmpdir):
|
||||||
|
Loading…
Reference in New Issue
Block a user