Method for reloading a topology (not bind to an api handler)

Ref https://github.com/GNS3/gns3-gui/issues/1243
This commit is contained in:
Julien Duponchelle committed 2016-06-15 16:26:16 +02:00
1 parent 3aea16c527
commit 742243e9df
4 files changed
+159 -4

No files matched your search

+24
View File
@@ -26,6 +26,7 @@ from .project import Project
from .compute import Compute
from .notification import Notification
from ..version import __version__
from .topology import load_topology
import logging
log = logging.getLogger(__name__)
@@ -185,6 +186,29 @@ class Controller:
def remove_project(self, project):
del self._projects[project.id]
@asyncio.coroutine
def load_project(self, path):
"""
Load a project from a .gns3
:param path: Path of the .gns3
"""
topo_data = load_topology(path)
topology = topo_data.pop("topology")
topo_data.pop("version")
topo_data.pop("revision")
topo_data.pop("type")
project = yield from self.add_project(path=os.path.dirname(path), **topo_data)
for compute in topology["computes"]:
yield from self.add_compute(**compute)
for node in topology["nodes"]:
compute = self.get_compute(node.pop("compute_id"))
name = node.pop("name")
node_id = node.pop("node_id")
yield from project.add_node(compute, name, node_id, **node)
@property
def projects(self):
"""