Prevent connect a node to himself

Fix https://github.com/GNS3/gns3-gui/issues/1553
This commit is contained in:
Julien Duponchelle committed 2016-10-03 12:31:01 +02:00
1 parent 420168015c
commit 99bdf37ec3
7 files changed
+79 -7

No files matched your search

+2
View File
@@ -463,6 +463,7 @@ class BaseNode:
:param command: command to send
"""
print(self._ubridge_hypervisor)
if not self._ubridge_hypervisor or not self._ubridge_hypervisor.is_running():
raise NodeError("Cannot send command '{}': uBridge is not running".format(command))
try:
@@ -498,6 +499,7 @@ class BaseNode:
"""
if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running():
log.info("Stopping uBridge hypervisor {}:{}".format(self._ubridge_hypervisor.host, self._ubridge_hypervisor.port))
yield from self._ubridge_hypervisor.stop()
@asyncio.coroutine
@@ -259,6 +259,9 @@ class Cloud(BaseNode):
self._nios[port_number] = nio
try:
yield from self._add_ubridge_connection(nio, port_number)
except NodeError as e:
del self._nios[port_number]
raise e
# Cleanup stuff
except UbridgeError as e:
try:
+3
View File
@@ -61,6 +61,9 @@ class Link:
self._link_type = port.link_type
for other_node in self._nodes:
if other_node["node"] == node:
raise aiohttp.web.HTTPConflict(text="Cannot connect to itself")
if node.node_type in ["nat", "cloud"]:
if other_node["node"].node_type in ["nat", "cloud"]:
raise aiohttp.web.HTTPConflict(text="It's not allowed to connect a {} to a {}".format(other_node["node"].node_type, node.node_type))
@@ -64,11 +64,15 @@ class LinkHandler:
controller = Controller.instance()
project = controller.get_project(request.match_info["project_id"])
link = yield from project.add_link()
for node in request.json["nodes"]:
yield from link.add_node(project.get_node(node["node_id"]),
node.get("adapter_number", 0),
node.get("port_number", 0),
label=node.get("label"))
try:
for node in request.json["nodes"]:
yield from link.add_node(project.get_node(node["node_id"]),
node.get("adapter_number", 0),
node.get("port_number", 0),
label=node.get("label"))
except aiohttp.web_exceptions.HTTPException as e:
yield from project.delete_link(link.id)
raise e
response.set_status(201)
response.json(link)