Ejemplo n.º 1
0
    def add_link(
        self,
        session_id,
        node_one_id,
        node_two_id,
        interface_one=None,
        interface_two=None,
        options=None,
    ):
        """
        Add a link between nodes.

        :param int session_id: session id
        :param int node_one_id: node one id
        :param int node_two_id: node two id
        :param core_pb2.Interface interface_one: node one interface data
        :param core_pb2.Interface interface_two: node two interface data
        :param core_pb2.LinkOptions options: options for link (jitter, bandwidth, etc)
        :return: response with result of success or failure
        :rtype: core_pb2.AddLinkResponse
        :raises grpc.RpcError: when session or one of the nodes don't exist
        """
        link = core_pb2.Link(
            node_one_id=node_one_id,
            node_two_id=node_two_id,
            type=core_pb2.LinkType.WIRED,
            interface_one=interface_one,
            interface_two=interface_two,
            options=options,
        )
        request = core_pb2.AddLinkRequest(session_id=session_id, link=link)
        return self.stub.AddLink(request)
Ejemplo n.º 2
0
    def add_link(self,
                 session_id: int,
                 link: wrappers.Link,
                 source: str = None
                 ) -> Tuple[bool, wrappers.Interface, wrappers.Interface]:
        """
        Add a link between nodes.

        :param session_id: session id
        :param link: link to add
        :param source: application source
        :return: tuple of result and finalized interface values
        :raises grpc.RpcError: when session or one of the nodes don't exist
        """
        request = core_pb2.AddLinkRequest(session_id=session_id,
                                          link=link.to_proto(),
                                          source=source)
        response = self.stub.AddLink(request)
        iface1 = wrappers.Interface.from_proto(response.iface1)
        iface2 = wrappers.Interface.from_proto(response.iface2)
        return response.result, iface1, iface2