示例#1
0
 def add_wired_edge(self, src: CanvasNode, dst: CanvasNode,
                    link: Link) -> None:
     token = create_edge_token(src.id, dst.id)
     if token in self.edges and link.options.unidirectional:
         edge = self.edges[token]
         edge.asymmetric_link = link
     elif token not in self.edges:
         node1 = src.core_node
         node2 = dst.core_node
         src_pos = (node1.position.x, node1.position.y)
         dst_pos = (node2.position.x, node2.position.y)
         edge = CanvasEdge(self, src.id, src_pos, dst_pos)
         edge.token = token
         edge.dst = dst.id
         edge.set_link(link)
         edge.check_wireless()
         src.edges.add(edge)
         dst.edges.add(edge)
         self.edges[edge.token] = edge
         self.core.links[edge.token] = edge
         if link.iface1:
             iface1 = link.iface1
             self.core.iface_to_edge[(node1.id, iface1.id)] = token
             src.ifaces[iface1.id] = iface1
             edge.src_iface = iface1
         if link.iface2:
             iface2 = link.iface2
             self.core.iface_to_edge[(node2.id, iface2.id)] = edge.token
             dst.ifaces[iface2.id] = iface2
             edge.dst_iface = iface2
示例#2
0
 def create_link(self, edge: CanvasEdge, canvas_src_node: CanvasNode,
                 canvas_dst_node: CanvasNode) -> None:
     """
     Create core link for a pair of canvas nodes, with token referencing
     the canvas edge.
     """
     src_node = canvas_src_node.core_node
     dst_node = canvas_dst_node.core_node
     self.ifaces_manager.determine_subnets(canvas_src_node, canvas_dst_node)
     src_iface = None
     if NodeUtils.is_container_node(src_node.type):
         src_iface = self.create_iface(canvas_src_node)
         self.iface_to_edge[(src_node.id, src_iface.id)] = edge.token
         edge.src_iface = src_iface
         canvas_src_node.ifaces[src_iface.id] = src_iface
     dst_iface = None
     if NodeUtils.is_container_node(dst_node.type):
         dst_iface = self.create_iface(canvas_dst_node)
         self.iface_to_edge[(dst_node.id, dst_iface.id)] = edge.token
         edge.dst_iface = dst_iface
         canvas_dst_node.ifaces[dst_iface.id] = dst_iface
     link = Link(
         type=LinkType.WIRED,
         node1_id=src_node.id,
         node2_id=dst_node.id,
         iface1=src_iface,
         iface2=dst_iface,
     )
     edge.set_link(link)
     self.links[edge.token] = edge
     logging.info("added link between %s and %s", src_node.name,
                  dst_node.name)
示例#3
0
    def create_link(
        self, edge: CanvasEdge, canvas_src_node: CanvasNode, canvas_dst_node: CanvasNode
    ) -> None:
        """
        Create core link for a pair of canvas nodes, with token referencing
        the canvas edge.
        """
        src_node = canvas_src_node.core_node
        dst_node = canvas_dst_node.core_node

        # determine subnet
        self.ifaces_manager.determine_subnets(canvas_src_node, canvas_dst_node)

        src_iface = None
        if NodeUtils.is_container_node(src_node.type):
            src_iface = self.create_iface(canvas_src_node)
            self.iface_to_edge[(src_node.id, src_iface.id)] = edge.token

        dst_iface = None
        if NodeUtils.is_container_node(dst_node.type):
            dst_iface = self.create_iface(canvas_dst_node)
            self.iface_to_edge[(dst_node.id, dst_iface.id)] = edge.token

        link = Link(
            type=LinkType.WIRED,
            node1_id=src_node.id,
            node2_id=dst_node.id,
            iface1=src_iface,
            iface2=dst_iface,
        )
        # assign after creating link proto, since interfaces are copied
        if src_iface:
            iface1 = link.iface1
            edge.src_iface = iface1
            canvas_src_node.ifaces[iface1.id] = iface1
        if dst_iface:
            iface2 = link.iface2
            edge.dst_iface = iface2
            canvas_dst_node.ifaces[iface2.id] = iface2
        edge.set_link(link)
        self.links[edge.token] = edge
        logging.info("Add link between %s and %s", src_node.name, dst_node.name)