mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
parent
f3596767c1
commit
c91999c532
@ -322,35 +322,43 @@ class Project:
|
|||||||
|
|
||||||
@open_required
|
@open_required
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def add_node(self, compute, name, node_id, **kwargs):
|
def add_node(self, compute, name, node_id, node_type=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Create a node or return an existing node
|
Create a node or return an existing node
|
||||||
|
|
||||||
:param kwargs: See the documentation of node
|
:param kwargs: See the documentation of node
|
||||||
"""
|
"""
|
||||||
if node_id not in self._nodes:
|
if node_id in self._nodes:
|
||||||
node = Node(self, compute, name, node_id=node_id, **kwargs)
|
return self._nodes[node_id]
|
||||||
if compute not in self._project_created_on_compute:
|
|
||||||
# For a local server we send the project path
|
|
||||||
if compute.id == "local":
|
|
||||||
yield from compute.post("/projects", data={
|
|
||||||
"name": self._name,
|
|
||||||
"project_id": self._id,
|
|
||||||
"path": self._path
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
yield from compute.post("/projects", data={
|
|
||||||
"name": self._name,
|
|
||||||
"project_id": self._id,
|
|
||||||
})
|
|
||||||
|
|
||||||
self._project_created_on_compute.add(compute)
|
# Due to a limitation all iou need to run on the same
|
||||||
yield from node.create()
|
# compute server otherwise you have mac address conflict
|
||||||
self._nodes[node.id] = node
|
if node_type == "iou":
|
||||||
self.controller.notification.emit("node.created", node.__json__())
|
for node in self._nodes.values():
|
||||||
self.dump()
|
if node.node_type == node_type and node.compute != compute:
|
||||||
return node
|
raise aiohttp.web.HTTPConflict(text="All IOU nodes need to run on the same server.")
|
||||||
return self._nodes[node_id]
|
|
||||||
|
node = Node(self, compute, name, node_id=node_id, node_type=node_type, **kwargs)
|
||||||
|
if compute not in self._project_created_on_compute:
|
||||||
|
# For a local server we send the project path
|
||||||
|
if compute.id == "local":
|
||||||
|
yield from compute.post("/projects", data={
|
||||||
|
"name": self._name,
|
||||||
|
"project_id": self._id,
|
||||||
|
"path": self._path
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
yield from compute.post("/projects", data={
|
||||||
|
"name": self._name,
|
||||||
|
"project_id": self._id,
|
||||||
|
})
|
||||||
|
|
||||||
|
self._project_created_on_compute.add(compute)
|
||||||
|
yield from node.create()
|
||||||
|
self._nodes[node.id] = node
|
||||||
|
self.controller.notification.emit("node.created", node.__json__())
|
||||||
|
self.dump()
|
||||||
|
return node
|
||||||
|
|
||||||
@open_required
|
@open_required
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -178,6 +178,28 @@ def test_add_node_non_local(async_run, controller):
|
|||||||
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
controller.notification.emit.assert_any_call("node.created", node.__json__())
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_iou_on_multiple_node(async_run, controller):
|
||||||
|
"""
|
||||||
|
Due to mac address collision you can't create an IOU node
|
||||||
|
on two different server
|
||||||
|
"""
|
||||||
|
compute = MagicMock()
|
||||||
|
compute.id = "remote"
|
||||||
|
|
||||||
|
compute2 = MagicMock()
|
||||||
|
compute2.id = "remote2"
|
||||||
|
|
||||||
|
project = Project(controller=controller, name="Test")
|
||||||
|
|
||||||
|
response = MagicMock()
|
||||||
|
response.json = {"console": 2048}
|
||||||
|
compute.post = AsyncioMagicMock(return_value=response)
|
||||||
|
|
||||||
|
node1 = async_run(project.add_node(compute, "test", None, node_type="iou"))
|
||||||
|
with pytest.raises(aiohttp.web_exceptions.HTTPConflict):
|
||||||
|
async_run(project.add_node(compute2, "test2", None, node_type="iou"))
|
||||||
|
|
||||||
|
|
||||||
def test_delete_node(async_run, controller):
|
def test_delete_node(async_run, controller):
|
||||||
"""
|
"""
|
||||||
For a local server we send the project path
|
For a local server we send the project path
|
||||||
|
Loading…
Reference in New Issue
Block a user