|
|
|
@ -89,6 +89,23 @@ class Controller:
|
|
|
|
|
for c in data["computes"]:
|
|
|
|
|
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):
|
|
|
|
|
"""
|
|
|
|
|
:returns: whether the current instance is the controller
|
|
|
|
@ -187,11 +204,12 @@ class Controller:
|
|
|
|
|
del self._projects[project.id]
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
|
def load_project(self, path):
|
|
|
|
|
def load_project(self, path, load=True):
|
|
|
|
|
"""
|
|
|
|
|
Load a project from a .gns3
|
|
|
|
|
|
|
|
|
|
:param path: Path of the .gns3
|
|
|
|
|
:param load: Load the topology
|
|
|
|
|
"""
|
|
|
|
|
topo_data = load_topology(path)
|
|
|
|
|
topology = topo_data.pop("topology")
|
|
|
|
@ -199,8 +217,9 @@ class Controller:
|
|
|
|
|
topo_data.pop("revision")
|
|
|
|
|
topo_data.pop("type")
|
|
|
|
|
|
|
|
|
|
project = yield from self.add_project(path=os.path.dirname(path), **topo_data)
|
|
|
|
|
yield from project.load()
|
|
|
|
|
project = yield from self.add_project(path=os.path.dirname(path), status="closed", **topo_data)
|
|
|
|
|
if load:
|
|
|
|
|
yield from project.load()
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def projects(self):
|
|
|
|
|