Пример #1
0
    def interface(self, key):
        """Returns interface based on interface id"""

        try:
            if key.interface_id in self._interface_ids():
                return NmPort(self.anm, self.overlay_id, self.node_id,
                              key.interface_id)
        except AttributeError:

            # try with key as id

            try:
                if key in self._interface_ids():
                    return NmPort(self.anm, self.overlay_id, self.node_id, key)
            except AttributeError:

                # no match for either

                log.warning('Unable to find interface %s in %s ' % (key, self))
                return None

        # try searching for the "id" attribute of the interface eg
        # GigabitEthernet0/0 if set
        search = list(self.interfaces(id=key))
        # TODO: warn if more than one match ie len > 1
        if len(search):
            return search[0]  # first result
Пример #2
0
    def interfaces(self):

        # TODO: warn if interface doesn't exist on node

        return iter(
            NmPort(self.anm, self.overlay_id, node_id, interface_id)
            for (node_id, interface_id) in self._ports.items())
Пример #3
0
    def add_loopback(self, *args, **kwargs):
        '''Public function to add a loopback interface'''

        interface_id = self._add_interface(category='loopback',
                                           *args,
                                           **kwargs)
        return NmPort(self.anm, self.overlay_id, self.node_id, interface_id)
Пример #4
0
    def dst_int(self):
        """Interface bound to destination node of edge"""

        try:
            dst_int_id = self._ports[self.dst_id]
        except KeyError:
            log.warn("Remove interface not present for %s" % self)
        return NmPort(self.anm, self.overlay_id, self.dst_id, dst_int_id)
Пример #5
0
    def add_loopback(self, *args, **kwargs):
        '''Public function to add a loopback interface'''

        interface_id = self._add_interface(category='loopback',
                                           *args,
                                           **kwargs)

        #TODO: want to add loopbacks to all overlays the node is in
        self._sync_loopbacks(interface_id)
        return NmPort(self.anm, self.overlay_id, self.node_id, interface_id)
Пример #6
0
    def dst_int(self):
        """Interface bound to destination node of edge

        >>> anm = autonetkit.topos.house()
        >>> edge = anm['phy'].edge("r1", "r2")
        >>> edge.dst_int
        eth0.r2

        """

        dst_int_id = self._ports[self.dst_id]
        return NmPort(self.anm, self.overlay_id, self.dst_id, dst_int_id)
Пример #7
0
    def src_int(self):
        """Interface bound to source node of edge

        >>> anm = autonetkit.topos.house()
        >>> edge = anm['phy'].edge("r1", "r2")
        >>> edge.src_int
        eth0.r1

        """

        src_int_id = self._ports[self.src_id]
        return NmPort(self.anm, self.overlay_id, self.src_id, src_int_id)
Пример #8
0
    def interfaces(self, *args, **kwargs):
        """Public function to view interfaces"""
        def filter_func(interface):
            """Filter based on args and kwargs"""

            return all(getattr(interface, key) for key in args) \
                and all(getattr(interface, key) == val for (key,
                        val) in kwargs.items())

        all_interfaces = iter(
            NmPort(self.anm, self.overlay_id, self.node_id, interface_id)
            for interface_id in self._interface_ids())

        retval = (i for i in all_interfaces if filter_func(i))
        return retval
Пример #9
0
    def interfaces(self):
        """

        >>> anm = autonetkit.topos.house()
        >>> edge = anm['phy'].edge("r1", "r2")
        >>> list(edge.interfaces())
        [eth0.r1, eth0.r2]

        """

        # TODO: warn if interface doesn't exist on node

        return [
            NmPort(self.anm, self.overlay_id, node_id, interface_id)
            for (node_id, interface_id) in self._ports.items()
        ]
Пример #10
0
    def add_interface(self, *args, **kwargs):
        """Public function to add interface"""

        interface_id = self._add_interface(*args, **kwargs)
        return NmPort(self.anm, self.overlay_id, self.node_id, interface_id)
Пример #11
0
    def src_int(self):
        """Interface bound to source node of edge"""

        src_int_id = self._ports[self.src_id]
        return NmPort(self.anm, self.overlay_id, self.src_id, src_int_id)
Пример #12
0
    def interface(self, interface):
        """"""

        return NmPort(self._anm, self._overlay_id, interface.node_id,
                      interface.interface_id)