mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 15:21:13 +02:00
API for duplication a Node
Support: * VPCS * Dynamips router * Ethernet switch Ref #1065
This commit is contained in:
18 files changed
+382
-32
No files matched your search
@@ -256,6 +256,37 @@ class BaseManager:
|
||||
project.add_node(node)
|
||||
return node
|
||||
|
||||
@asyncio.coroutine
|
||||
def duplicate_node(self, source_node_id, destination_node_id):
|
||||
"""
|
||||
Duplicate a node
|
||||
|
||||
:param source_node_id: Source node identifier
|
||||
:param destination_node_id: Destination node identifier
|
||||
:returns: New node instance
|
||||
"""
|
||||
source_node = self.get_node(source_node_id)
|
||||
destination_node = self.get_node(destination_node_id)
|
||||
|
||||
# Some node don't have working dir like switch
|
||||
if not hasattr(destination_node, "working_dir"):
|
||||
return destination_node
|
||||
|
||||
destination_dir = destination_node.working_dir
|
||||
try:
|
||||
shutil.rmtree(destination_dir)
|
||||
shutil.copytree(source_node.working_dir, destination_dir)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Can't duplicate node data: {}".format(e))
|
||||
|
||||
# We force a refresh of the name. This force the rewrite
|
||||
# of some configuration files
|
||||
node_name = destination_node.name
|
||||
destination_node.name = node_name + "tmp"
|
||||
destination_node.name = node_name
|
||||
|
||||
return destination_node
|
||||
|
||||
@asyncio.coroutine
|
||||
def close_node(self, node_id):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user