mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Let a project be opened when a port cannot be found (can happens if a project is corrupted).
This commit is contained in:
parent
4ba523a0d7
commit
519df3ab35
@ -198,6 +198,8 @@ class Link:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
port = node.get_port(adapter_number, port_number)
|
port = node.get_port(adapter_number, port_number)
|
||||||
|
if port is None:
|
||||||
|
raise aiohttp.web.HTTPNotFound(text="Port {}/{} for {} not found".format(adapter_number, port_number, node.name))
|
||||||
if port.link is not None:
|
if port.link is not None:
|
||||||
raise aiohttp.web.HTTPConflict(text="Port is already used")
|
raise aiohttp.web.HTTPConflict(text="Port is already used")
|
||||||
|
|
||||||
@ -213,6 +215,8 @@ class Link:
|
|||||||
|
|
||||||
# Check if user is not connecting serial => ethernet
|
# Check if user is not connecting serial => ethernet
|
||||||
other_port = other_node["node"].get_port(other_node["adapter_number"], other_node["port_number"])
|
other_port = other_node["node"].get_port(other_node["adapter_number"], other_node["port_number"])
|
||||||
|
if other_port is None:
|
||||||
|
raise aiohttp.web.HTTPNotFound(text="Port {}/{} for {} not found".format(other_node["adapter_number"], other_node["port_number"], other_node["node"].name))
|
||||||
if port.link_type != other_port.link_type:
|
if port.link_type != other_port.link_type:
|
||||||
raise aiohttp.web.HTTPConflict(text="It's not allowed to connect a {} to a {}".format(other_port.link_type, port.link_type))
|
raise aiohttp.web.HTTPConflict(text="It's not allowed to connect a {} to a {}".format(other_port.link_type, port.link_type))
|
||||||
|
|
||||||
|
@ -574,12 +574,12 @@ class Node:
|
|||||||
def get_port(self, adapter_number, port_number):
|
def get_port(self, adapter_number, port_number):
|
||||||
"""
|
"""
|
||||||
Return the port for this adapter_number and port_number
|
Return the port for this adapter_number and port_number
|
||||||
or raise an HTTPNotFound
|
or returns None if the port is not found
|
||||||
"""
|
"""
|
||||||
for port in self.ports:
|
for port in self.ports:
|
||||||
if port.adapter_number == adapter_number and port.port_number == port_number:
|
if port.adapter_number == adapter_number and port.port_number == port_number:
|
||||||
return port
|
return port
|
||||||
raise aiohttp.web.HTTPNotFound(text="Port {}/{} for {} not found".format(adapter_number, port_number, self.name))
|
return None
|
||||||
|
|
||||||
def _list_ports(self):
|
def _list_ports(self):
|
||||||
"""
|
"""
|
||||||
|
@ -783,8 +783,11 @@ class Project:
|
|||||||
for node_link in link_data["nodes"]:
|
for node_link in link_data["nodes"]:
|
||||||
node = self.get_node(node_link["node_id"])
|
node = self.get_node(node_link["node_id"])
|
||||||
port = node.get_port(node_link["adapter_number"], node_link["port_number"])
|
port = node.get_port(node_link["adapter_number"], node_link["port_number"])
|
||||||
|
if port is None:
|
||||||
|
log.warning("Port {}/{} for {} not found".format(node_link["adapter_number"], node_link["port_number"], node.name))
|
||||||
|
continue
|
||||||
if port.link is not None:
|
if port.link is not None:
|
||||||
# the node port is already attached to another link
|
log.warning("Port {}/{} is already connected to link ID {}".format(node_link["adapter_number"], node_link["port_number"], port.link.id))
|
||||||
continue
|
continue
|
||||||
yield from link.add_node(node, node_link["adapter_number"], node_link["port_number"], label=node_link.get("label"), dump=False)
|
yield from link.add_node(node, node_link["adapter_number"], node_link["port_number"], label=node_link.get("label"), dump=False)
|
||||||
if len(link.nodes) != 2:
|
if len(link.nodes) != 2:
|
||||||
|
Loading…
Reference in New Issue
Block a user