示例#1
0
    def _on_feature_links_updated(self):
        '''Called when the `links` list is updated.

        This particular implementation updates the `interfaces` list.
        '''
        self.interfaces = WeakList(self._interfaces_with_feature())
        super()._on_feature_links_updated()
示例#2
0
    def _on_removed_from_link(self, link):
        """Action to be taken when removing a feature from a link

        Action to be taken when removing a feature from a link

        Args:
            link (`Link`): link object

        Returns:
            `None`

        """
        self.links = WeakList(self._links_with_feature())
        self._on_feature_links_updated()
示例#3
0
    def _on_removed_from_interface(self, interface):
        """Action to be taken when removing a feature from an interface

        Action to be taken when removing a feature from an interface. A feature
        can be part of multiple interfaces.

        Args:
            interface (`Interface`): interface object

        Returns:
            `None`

        """
        self.interfaces = WeakList(self._interfaces_with_feature())
        self._on_feature_interfaces_updated()
示例#4
0
    def _on_removed_from_device(self, device):
        """Action to be taken when removing a feature from a device

        Action to be taken when removing a feature from a device. A feature
        can be part of multiple devices.

        Args:
            `None`

        Returns:
            `None`

        """
        self.devices = WeakList(self._devices_with_feature())
        self._on_feature_devices_updated()
示例#5
0
 def link_interfaces_from_segment(self, segment):
     link_interfaces = set()
     if isinstance(segment, Evi):
         pass
     elif isinstance(segment, Vni):
         pass
     elif isinstance(segment, Interface):
         if isinstance(segment, BviInterface):
             link_interfaces.add(segment)
         else:
             # Links under Genie Interface object is deprecated
             # Placed the below workaround to bypass the Unittest
             from pyats.datastructures import WeakList
             segment_links = set(WeakList()) - set([self.link])
             # Priority to L2 virtual links...
             if not link_interfaces:
                 for link in segment_links:
                     if isinstance(link,
                                   (BridgeDomainLink,
                                    genie.libs.conf.l2vpn.XconnectLink)):
                         link_interfaces.update(link.interfaces)
                         link_interfaces.discard(segment)
             # ... then emulated links
             if not link_interfaces:
                 for link in segment_links:
                     if isinstance(link, EmulatedLink):
                         link_interfaces.update(link.interfaces)
                         link_interfaces.discard(segment)
             # ... finally, all links
             if not link_interfaces:
                 for link in segment_links:
                     link_interfaces.update(link.interfaces)
                     link_interfaces.discard(segment)
             # For VLAN TGEN connections, the CE interface is the peer of
             # the AC interface's parent
             if not link_interfaces:
                 parent_interface = segment.parent_interface
                 if parent_interface:
                     # recurse
                     link_interfaces = self.link_interfaces_from_segment(
                         parent_interface)
     elif isinstance(segment, Pseudowire):
         pass
     elif isinstance(segment, Vfi):
         pass
     else:
         raise ValueError(segment)
     return link_interfaces
示例#6
0
 def _init_links_list(self):
     self.links = WeakList()
示例#7
0
class LinkFeature(FeatureBase):
    """Base class for all link-based Feature objects

    Base class for all configurable link-based Feature objects.

    Contains a weaklist for all links related to this `Feature`

    """
    @log_it
    def __init__(self, **kwargs):
        self._init_links_list()
        super().__init__(**kwargs)

    def _init_links_list(self):
        self.links = WeakList()

    def _links_with_feature(self):
        '''Called to determine the set of links on which this feature is
        enabled in order to update the `links` list.

        If overridding, call this method and add more links.

        This particular implementation filters the `links` list to confirm
        which still have the feature enabled.
        '''
        links = set()
        for link in self.links:
            if self in link.features:
                links.add(link)
        return links | super()._links_with_feature()

    def _interfaces_with_feature(self):
        '''Called to determine the set of interfaces on which this feature is
        enabled in order to update the `interfaces` list.

        If overridding, call this method and add more interfaces.

        This particular implementation walks the `links` list to find out
        which interfaces have the feature indirectly enabled.
        '''
        interfaces = set()
        for link in self._links_with_feature():
            interfaces.update(link.interfaces)
        return interfaces | super()._interfaces_with_feature()

    def _devices_with_feature(self):
        '''Called to determine the set of devices on which this feature is
        enabled in order to update the `devices` list.

        If overridding, call this method and add more devices.

        This particular implementation walks the `links` list to find out
        which devices have the feature indirectly enabled.
        '''
        devices = set()
        for link in self._links_with_feature():
            devices.update(link.devices)
        return devices | super()._devices_with_feature()

    @log_it
    def _on_added_from_link(self, link):
        """Action to be taken when adding a feature to a link

        Action to be taken when adding a feature to a link

        Args:
            link (`Link`): link object

        Returns:
            `None`

        """
        if link not in self.links:
            self.links.append(link)
        self._on_feature_links_updated()

    @log_it
    def _on_removed_from_link(self, link):
        """Action to be taken when removing a feature from a link

        Action to be taken when removing a feature from a link

        Args:
            link (`Link`): link object

        Returns:
            `None`

        """
        self.links = WeakList(self._links_with_feature())
        self._on_feature_links_updated()
示例#8
0
 def _init_interfaces_list(self):
     self.interfaces = WeakList()
示例#9
0
class InterfaceFeature(FeatureBase):
    """Base class for all interface-based Feature objects

    Base class for all configurable interface-based Feature objects.

    Contains a weaklist for all interface related to this `Feature`

    """
    @log_it
    def __init__(self, **kwargs):
        self._init_interfaces_list()
        super().__init__(**kwargs)

    def _init_interfaces_list(self):
        self.interfaces = WeakList()

    def _interfaces_with_feature(self):
        '''Called to determine the set of interfaces on which this feature is
        enabled in order to update the `interfaces` list.

        If overridding, call this method and add more interfaces.

        This particular implementation filters the `interfaces` list to confirm
        which still have the feature enabled.
        '''
        interfaces = set()
        for interface in self.interfaces:
            if self in interface.features:
                interfaces.add(interface)
        return interfaces | super()._interfaces_with_feature()

    def _devices_with_feature(self):
        '''Called to determine the set of devices on which this feature is
        enabled in order to update the `devices` list.

        If overridding, call this method and add more devices.

        This particular implementation walks the `interfaces` list to find out
        which devices have the feature indirectly enabled.
        '''
        devices = set()
        for interface in self._interfaces_with_feature():
            devices.add(interface.device)
        return devices | super()._devices_with_feature()

    @log_it
    def _on_added_from_interface(self, interface):
        """Action to be taken when adding a feature to an interface

        Action to be taken when adding a feature to an interface. A feature
        can be part of multiple interfaces.

        Args:
            interface (`Interface`): interface object

        Returns:
            `None`

        """
        if interface not in self.interfaces:
            self.interfaces.append(interface)
        self._on_feature_interfaces_updated()

    @log_it
    def _on_removed_from_interface(self, interface):
        """Action to be taken when removing a feature from an interface

        Action to be taken when removing a feature from an interface. A feature
        can be part of multiple interfaces.

        Args:
            interface (`Interface`): interface object

        Returns:
            `None`

        """
        self.interfaces = WeakList(self._interfaces_with_feature())
        self._on_feature_interfaces_updated()

    def _on_feature_links_updated(self):
        '''Called when the `links` list is updated.

        This particular implementation updates the `interfaces` list.
        '''
        self.interfaces = WeakList(self._interfaces_with_feature())
        super()._on_feature_links_updated()
示例#10
0
 def _init_devices_list(self):
     self.devices = WeakList()