How to use the autonetkit.anm.edge.NmEdge 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
return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst, edge.ekey)
            elif (self._graph.has_edge(edge.src, edge.dst)):
                return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst)

        if isinstance(edge_to_find, NmEdge):
            src_id = edge_to_find.src
            dst_id = edge_to_find.dst
            search_key = key

            if self.is_multigraph():
                for (src, dst, rkey) in self._graph.edges(src_id,
                                                          keys=True):
                    if dst == dst_id and rkey == search_key:
                        return NmEdge(self._anm, self._overlay_id, src,
                                      dst, search_key)

            for (src, dst) in self._graph.edges(src_id):
                if dst == dst_id:
                    return NmEdge(self._anm, self._overlay_id, src, dst)

        # 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,
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
dst, search_key)

            for (src, dst) in self._graph.edges(src_id):
                if dst == dst_id:
                    return NmEdge(self._anm, self._overlay_id, src, dst)

        # 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)
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
if isinstance(edge_to_find, NmEdge):
            src_id = edge_to_find.src
            dst_id = edge_to_find.dst
            search_key = key

            if self.is_multigraph():
                for (src, dst, rkey) in self._graph.edges(src_id,
                                                          keys=True):
                    if dst == dst_id and rkey == search_key:
                        return NmEdge(self._anm, self._overlay_id, src,
                                      dst, search_key)

            for (src, dst) in self._graph.edges(src_id):
                if dst == dst_id:
                    return NmEdge(self._anm, self._overlay_id, src, dst)

        # 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):
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
>>> eth0_r2 = anm["phy"].node("r2").interface("eth0")
        >>> anm["phy"].has_edge(eth0_r1, eth0_r2)
        True
        >>> anm["phy"].has_edge(eth3_r1, eth0_r2)
        False

        '''

        # TODO: handle multigraphs
        if isinstance(edge_to_find, NmEdge):
            # TODO: tidy this logic
            edge = edge_to_find  # alias for neater code
            if (edge.is_multigraph() and self.is_multigraph()
                and self._graph.has_edge(edge.src,
                                         edge.dst, key=edge.ekey)):
                return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst, edge.ekey)
            elif (self._graph.has_edge(edge.src, edge.dst)):
                return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst)

        if isinstance(edge_to_find, NmEdge):
            src_id = edge_to_find.src
            dst_id = edge_to_find.dst
            search_key = key

            if self.is_multigraph():
                for (src, dst, rkey) in self._graph.edges(src_id,
                                                          keys=True):
                    if dst == dst_id and rkey == search_key:
                        return NmEdge(self._anm, self._overlay_id, src,
                                      dst, search_key)
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
valid_edges = list((src, dst, default_key)
                               for (src, dst) in self._graph.edges(src_nbunch))

        if dst_nbunch:
            try:
                dst_nbunch = dst_nbunch.node_id
                dst_nbunch = set([dst_nbunch])
            except AttributeError:
                dst_nbunch = (n.node_id for n in dst_nbunch)
                dst_nbunch = set(dst_nbunch)

            valid_edges = list((src, dst, key) for (src, dst, key) in
                               valid_edges if dst in dst_nbunch)

        if len(args) or len(kwargs):
            all_edges = [NmEdge(self._anm, self._overlay_id, src, dst,
                                key) for (src, dst, key) in valid_edges]
            result = list(edge for edge in all_edges
                          if filter_func(edge))
        else:
            result = list(NmEdge(self._anm, self._overlay_id, src, dst,
                                 key) for (src, dst, key) in valid_edges)

        return list(result)
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
if dst == dst_id:
                    return NmEdge(self._anm, self._overlay_id, src, dst)

        # 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
github sk2 / autonetkit / autonetkit / anm / graph.py View on Github external
if bidirectional:
                    edges_to_add.append((dst, src, dict(data)))


            #TODO: warn if not multigraph

            self._graph.add_edges_from(edges_to_add)
            all_edges += edges_to_add

        if self.is_multigraph():
            return [
            NmEdge(self.anm, self._overlay_id, src, dst, ekey) if ekey
            else NmEdge(self.anm, self._overlay_id, src, dst) # default no ekey set
            for src, dst, ekey, _ in all_edges]
        else:
            return [NmEdge(self.anm, self._overlay_id, src, dst)
            for src, dst, _ in all_edges]
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
>>> anm["phy"].has_edge(eth3_r1, eth0_r2)
        False

        '''

        # TODO: handle multigraphs
        if isinstance(edge_to_find, NmEdge):
            # TODO: tidy this logic
            edge = edge_to_find  # alias for neater code
            if (edge.is_multigraph() and self.is_multigraph()
                and self._graph.has_edge(edge.src,
                                         edge.dst, key=edge.ekey)):
                return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst, edge.ekey)
            elif (self._graph.has_edge(edge.src, edge.dst)):
                return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst)

        if isinstance(edge_to_find, NmEdge):
            src_id = edge_to_find.src
            dst_id = edge_to_find.dst
            search_key = key

            if self.is_multigraph():
                for (src, dst, rkey) in self._graph.edges(src_id,
                                                          keys=True):
                    if dst == dst_id and rkey == search_key:
                        return NmEdge(self._anm, self._overlay_id, src,
                                      dst, search_key)

            for (src, dst) in self._graph.edges(src_id):
                if dst == dst_id:
github sk2 / autonetkit / autonetkit / anm / base.py View on Github external
>>> e1 == e2
        False

        >>> autonetkit.update_http(anm)
        >>> eth0_r1 = anm["phy"].node("r1").interface("eth0")
        >>> eth3_r1 = anm["phy"].node("r1").interface("eth3")
        >>> eth0_r2 = anm["phy"].node("r2").interface("eth0")
        >>> anm["phy"].has_edge(eth0_r1, eth0_r2)
        True
        >>> anm["phy"].has_edge(eth3_r1, eth0_r2)
        False

        '''

        # TODO: handle multigraphs
        if isinstance(edge_to_find, NmEdge):
            # TODO: tidy this logic
            edge = edge_to_find  # alias for neater code
            if (edge.is_multigraph() and self.is_multigraph()
                and self._graph.has_edge(edge.src,
                                         edge.dst, key=edge.ekey)):
                return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst, edge.ekey)
            elif (self._graph.has_edge(edge.src, edge.dst)):
                return NmEdge(self._anm, self._overlay_id,
                              edge.src, edge.dst)

        if isinstance(edge_to_find, NmEdge):
            src_id = edge_to_find.src
            dst_id = edge_to_find.dst
            search_key = key