How to use the autonetkit.anm.node.NmNode function in autonetkit

To help you get started, we’ve selected a few autonetkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
def node_label(self, node):
        """"""

        return repr(NmNode(self._anm, self._overlay_id, node))
github sk2 / autonetkit / autonetkit / anm / graph.py View on Github external
def _add_node(self, node, **kwargs):
        # TODO: label workaround
        data = {'label': node}
        self._graph.add_nodes_from([(node, data)], **kwargs)
        self._copy_interfaces(node)
        return NmNode(self.anm, self._overlay_id, node)
github sk2 / autonetkit / autonetkit / anm / graph.py View on Github external
def remove_node(self, node_id):
        """Removes a node from the overlay"""
        if isinstance(node_id, NmNode):
            node_id = node_id.node_id

        self._graph.remove_node(node_id)
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
def device(self, key):
        """To access programatically"""

        return NmNode(self._anm, self._overlay_id, key)
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
>>> g_phy.nodes(asn=1)
        [r4, r5, r1, r2, r3]

        >>> g_phy.nodes(asn=3)
        [r7, r8, r9, r10]

        >>> g_phy.nodes(asn=1, ibgp_role="RR")
        [r4, r5]

        >>> g_phy.nodes(asn=1, ibgp_role="RRC")
        [r1, r2, r3]

        """

        result = list(NmNode(self._anm, self._overlay_id, node)
                      for node in self._graph)

        if len(args) or len(kwargs):
            result = self.filter(result, *args, **kwargs)
        return result
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
# from here on look for (src, dst) pairs
        src = edge_to_find
        dst = dst_to_find

        if (isinstance(src, basestring) and isinstance(dst, basestring)):
            src = src.lower()
            dst = dst.lower()
            if self.is_multigraph():
                if self._graph.has_edge(src, dst, key=key):
                    return NmEdge(self._anm, self._overlay_id, src,
                                  dst, key)
            elif self._graph.has_edge(src, dst):
                return NmEdge(self._anm, self._overlay_id, src, dst)

        if isinstance(src, NmNode) and isinstance(dst, NmNode):
            src_id = src.node_id
            dst_id = dst.node_id

            if self.is_multigraph():
                if self._graph.has_edge(src_id, dst_id, key):
                    return NmEdge(self._anm, self._overlay_id, src, dst, key)

            else:
                if self._graph.has_edge(src_id, dst_id):
                    return NmEdge(self._anm, self._overlay_id, src, dst)


        if isinstance(src, NmPort) and isinstance(dst, NmPort):
            # further filter result by ports
            src_id = src.node_id
            dst_id = dst.node_id
github sk2 / autonetkit / autonetkit / anm / interface.py View on Github external
    @property
    def node(self):
        """Returns parent node of this interface"""

        from autonetkit.anm.node import NmNode
        return NmNode(self.anm, self.overlay_id, self.node_id)
github sk2 / autonetkit / autonetkit / anm / graph.py View on Github external
ports = {}
                    if src in self:
                        ports[src] = in_a.interface_id
                    if dst in self:
                        ports[dst] = in_b.interface_id
                    data['_ports'] = ports

                elif isinstance(in_a, NmNode) and isinstance(in_b, NmPort):
                    src = in_a.node_id
                    dst = in_b.node.node_id
                    ports = {}
                    if dst in self:
                        ports[dst] = in_b.interface_id
                    data['_ports'] = ports

                elif isinstance(in_a, NmPort) and isinstance(in_b, NmNode):
                    src = in_a.node.node_id
                    dst = in_b.node_id
                    ports = {}
                    if src in self:
                        ports[src] = in_a.interface_id
                    data['_ports'] = ports

                elif in_a in self and in_b in self:
                    src = in_a
                    dst = in_b

            elif len(in_edge) == 3:
                # (src, dst, ekey) format
                # or (src, dst, data) format
                in_a, in_b, in_c = in_edge[0], in_edge[1], in_edge[2]
                if in_a in self and in_b in self: