Example #1
0
            class AddressFamilyAttributes(AddressFamilySubAttributes):

                mroutes = managedattribute(
                    name='mroutes',
                    finit=typedset(
                        managedattribute.test_isinstance(Mroute)).copy,
                    type=typedset(managedattribute.test_isinstance(
                        Mroute))._from_iterable,
                    doc='A `set` of Mroute associated objects')

                def add_mroute(self, mroute):
                    self.mroutes.add(mroute)

                def remove_mroute(self, mroute):
                    mroute._device = None
                    try:
                        self.mroutes.remove(mroute)
                    except:
                        pass

                # Compatibility
                class InterfaceAttributes(InterfaceSubAttributes):
                    pass

                interface_attr = managedattribute(
                    name='interface_attr',
                    read_only=True,
                    doc=InterfaceAttributes.__doc__)

                @interface_attr.initter
                def interface_attr(self):
                    return SubAttributesDict(self.InterfaceAttributes,
                                             parent=self)
Example #2
0
    class DeviceAutodiscoveryBgpAttributesDefaults(XconnectNamespace):

        enabled = managedattribute(name='enabled',
                                   default=False,
                                   type=managedattribute.test_istype(bool))

        control_word = managedattribute(
            name='control_word',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

        rd = managedattribute(name='rd',
                              default=None,
                              type=(None, RouteDistinguisher,
                                    managedattribute.test_in(('auto', ))))

        export_route_policy = managedattribute(
            name='export_route_policy',
            default=None,
            type=(None, managedattribute.test_istype(str)))

        export_route_targets = managedattribute(
            name='export_route_targets',
            finit=typedset(RouteTarget.ImportExport).copy,
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        import_route_targets = managedattribute(
            name='import_route_targets',
            finit=typedset(RouteTarget.ImportExport).copy,
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        table_policy = managedattribute(
            name='table_policy',
            default=None,
            type=(None, managedattribute.test_istype(str)))

        class DeviceSignalingProtocolBgpAttributesDefaults(XconnectNamespace):

            enabled = managedattribute(name='enabled',
                                       default=False,
                                       type=managedattribute.test_istype(bool))

            ce_range = managedattribute(
                name='ce_range',
                default=None,
                type=(None, managedattribute.test_istype(int),
                      managedattribute.test_istype(str)))

        signaling_protocol_bgp = managedattribute(
            name='signaling_protocol_bgp',
            read_only=True,
            doc=DeviceSignalingProtocolBgpAttributesDefaults.__doc__)

        @signaling_protocol_bgp.initter
        def signaling_protocol_bgp(self):
            return self.DeviceSignalingProtocolBgpAttributesDefaults(
                xconnect=self.xconnect)

        def __init__(self, xconnect):
            super().__init__(xconnect=xconnect)
Example #3
0
            class AddressFamilyAttributes(AddressFamilySubAttributes):

                rp_addresses = managedattribute(
                    name='rp_addresses',
                    finit=typedset(
                        managedattribute.test_isinstance(RPAddressGroup)).copy,
                    type=typedset(
                        managedattribute.test_isinstance(
                            RPAddressGroup))._from_iterable,
                    doc='A `set` of RPAddressGroup associated objects')

                def add_static_rp(self, rp_addresses):
                    self.rp_addresses.add(rp_addresses)

                def remove_static_rp(self, rp_addresses):
                    rp_addresses._device = None
                    try:
                        self.rp_addresses.remove(rp_addresses)
                    except:
                        pass

                class InterfaceAttributes(InterfaceSubAttributes):
                    pass

                interface_attr = managedattribute(
                    name='interface_attr',
                    read_only=True,
                    doc=InterfaceAttributes.__doc__)

                @interface_attr.initter
                def interface_attr(self):
                    return SubAttributesDict(self.InterfaceAttributes,
                                             parent=self)
Example #4
0
    class BgpAttributes(SubAttributes):

        enabled = managedattribute(name='enabled',
                                   default=False,
                                   type=managedattribute.test_istype(bool))

        rd = managedattribute(name='rd',
                              default=None,
                              type=(None, RouteDistinguisher))

        export_route_targets = managedattribute(
            name='export_route_targets',
            finit=typedset(RouteTarget.ImportExport).copy,
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        export_route_target_none = managedattribute(
            name='export_route_target_none',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

        import_route_targets = managedattribute(
            name='import_route_targets',
            finit=typedset(RouteTarget.ImportExport).copy,
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        import_route_target_none = managedattribute(
            name='import_route_target_none',
            default=None,
            type=(None, managedattribute.test_istype(bool)))
Example #5
0
    class DeviceAttributes(DeviceSubAttributes):
        @property
        def vnis(self):
            device = self.device
            return frozenset(
                [vni for vni in self.parent.vnis if vni.device is device])

        @property
        def interfaces(self):
            device = self.device
            return frozenset([
                interface for interface in self.parent.interfaces
                if interface.device is device
            ])

        export_route_targets = managedattribute(
            name='export_route_targets',
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        @export_route_targets.defaulter
        def export_route_targets(self):
            return frozenset(self.parent.export_route_targets)

        import_route_targets = managedattribute(
            name='import_route_targets',
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        @import_route_targets.defaulter
        def import_route_targets(self):
            return frozenset(self.parent.import_route_targets)

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @address_families.defaulter
        def address_families(self):
            return frozenset(self.parent.address_families)

        class AddressFamilyAttributes(AddressFamilySubAttributes):
            class RouteTargetAttributes(KeyedSubAttributes):
                def __init__(self, parent, key):
                    self.rt = key
                    super().__init__(parent)

            route_target_attr = managedattribute(
                name='route_target_attr',
                read_only=True,
                doc=RouteTargetAttributes.__doc__)

            @route_target_attr.initter
            def route_target_attr(self):
                return SubAttributesDict(self.RouteTargetAttributes,
                                         parent=self)

        def __init__(self, *args, **kwargs):
            self.address_family_attr = SubAttributesDict(
                self.AddressFamilyAttributes, parent=self)
            super().__init__(*args, **kwargs)
Example #6
0
        class VrfAttributes(VrfSubAttributes):
            def __init__(self, parent, key):
                self.vrf_id = key
                super().__init__(parent, key)

            ssm = managedattribute(
                name='ssm',
                finit=typedset(managedattribute.test_isinstance(Ssm)).copy,
                type=typedset(
                    managedattribute.test_isinstance(Ssm))._from_iterable,
                doc='A `set` of ssm associated objects')

            def add_ssm(self, ssm):
                self.ssm.add(ssm)

            def remove_ssm(self, ssm):
                ssm._device = None
                try:
                    self.ssm.remove(ssm)
                except:
                    pass

            class InterfaceAttributes(InterfaceSubAttributes):
                def __init__(self, parent, key):
                    self.intf = key
                    super().__init__(parent, key)

                groups = managedattribute(
                    name='groups',
                    finit=typedset(
                        managedattribute.test_isinstance(IgmpGroup)).copy,
                    type=typedset(managedattribute.test_isinstance(
                        IgmpGroup))._from_iterable,
                    doc='A `set` of IgmpGroup associated objects')

                def add_groups(self, groups):
                    self.groups.add(groups)

                def remove_groups(self, groups):
                    groups._device = None
                    try:
                        self.groups.remove(groups)
                    except:
                        pass

            interface_attr = managedattribute(name='interface_attr',
                                              read_only=True,
                                              doc=InterfaceAttributes.__doc__)

            @interface_attr.initter
            def interface_attr(self):
                return SubAttributesDict(self.InterfaceAttributes, parent=self)
Example #7
0
    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):

        backbone_interfaces = managedattribute(
            name='backbone_interfaces',
            type=typedset(
                managedattribute.test_isinstance(Interface))._from_iterable)

        @backbone_interfaces.defaulter
        def backbone_interfaces(self):
            device = self.device
            return frozenset(interface
                             for interface in self.parent.backbone_interfaces
                             if interface.device is device)

        class InterfaceAttributes(
                genie.conf.base.attributes.InterfaceSubAttributes):
            def __init__(self, parent, key):
                super().__init__(parent, key)

        interface_attr = managedattribute(name='interface_attr',
                                          read_only=True,
                                          doc=InterfaceAttributes.__doc__)

        @interface_attr.initter
        def interface_attr(self):
            return SubAttributesDict(self.InterfaceAttributes, parent=self)

        # interfaces -- See DeviceSubAttributes

        def __init__(self, parent, key):
            super().__init__(parent, key)
Example #8
0
            class AddressFamilyAttributes(AddressFamilySubAttributes):

                allowed_keys = (AddressFamily.ipv4, AddressFamily.ipv6)

                advertise_interfaces = managedattribute(
                    name='advertise_interfaces',
                    type=typedset(managedattribute.test_isinstance(
                        Interface))._from_iterable)

                @advertise_interfaces.defaulter
                def advertise_interfaces(self):
                    return frozenset(self.parent.advertise_interfaces)

                class NeighborAttributes(IPLsrNeighborSubAttributes):
                    def __init__(self, **kwargs):
                        super().__init__(**kwargs)

                neighbor_attr = managedattribute(
                    name='neighbor_attr',
                    read_only=True,
                    doc=NeighborAttributes.__doc__)

                @neighbor_attr.initter
                def neighbor_attr(self):
                    return SubAttributesDict(self.NeighborAttributes,
                                             parent=self)

                def __init__(self, **kwargs):
                    super().__init__(**kwargs)
Example #9
0
        class InterfaceAttributes(
                genie.conf.base.attributes.InterfaceSubAttributes):

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            class AddressFamilyAttributes(AddressFamilySubAttributes):

                allowed_keys = (AddressFamily.ipv4, AddressFamily.ipv6)

                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                         parent=self)

            def __init__(self, **kwargs):
                super().__init__(**kwargs)
Example #10
0
        class VrfAttributes(VrfSubAttributes):
            """ VrfAttributes class

            `VrfAttributes` inherits from `SubAttributes' class.
             It contains all vrf related attributes and
             functionalities. Class contains some powers to access
             its parent attributes.

            Args:
                kwargs (`dict`) : gives the user ability to assign some or all
                                  address family attributes while creating the
                                  object.

            """

            def __init__(self, **kwargs):
                super().__init__(**kwargs)

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            class AddressFamilyAttributes(AddressFamilySubAttributes):
                """ AddressFamilyAttributes class

                `AddressFamilyAttributes` inherits from `SubAttributes' class.
                 It contains all address family related attributes and
                 functionalities. Class contains some powers to access
                 its parent attributes.

                Args:
                    kwargs (`dict`) : gives the user ability to assign some or all
                                      address family attributes while creating the
                                      object.

                Class variables:

                    allowed_keys (`List`): list of all allowed 'keys' the object can
                                      access.

                """

                allowed_keys = (
                    AddressFamily.ipv4_unicast,
                    AddressFamily.ipv6_unicast,
                )

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes, parent=self)
Example #11
0
                class InterfaceAttributes(InterfaceSubAttributes):

                    # Interface Static Neighbor multi-line configs
                    intf_staticnbr_keys = managedattribute(
                        name='intf_staticnbr_keys',
                        finit=typedset(managedattribute.test_isinstance(InterfaceStaticNeighbor)).copy,
                        type=typedset(managedattribute.test_isinstance(InterfaceStaticNeighbor))._from_iterable,
                        doc='A `set` of InterfaceStaticNeighbor keys objects')

                    def add_staticnbr_key(self, intf_staticnbr_key):
                        self.intf_staticnbr_keys.add(intf_staticnbr_key)

                    def remove_staticnbr_key(self, intf_staticnbr_key):
                        intf_staticnbr_key._device = None
                        try:
                            self.intf_staticnbr_keys.remove(intf_staticnbr_key)
                        except:
                            pass
Example #12
0
            class InterfaceAttributes(InterfaceSubAttributes):

                groups = managedattribute(
                    name='groups',
                    finit=typedset(
                        managedattribute.test_isinstance(MldGroup)).copy,
                    type=typedset(managedattribute.test_isinstance(
                        MldGroup))._from_iterable,
                    doc='A `set` of MldGroup associated objects')

                def add_groups(self, groups):
                    self.groups.add(groups)

                def remove_groups(self, groups):
                    groups._device = None
                    try:
                        self.groups.remove(groups)
                    except:
                        pass
Example #13
0
            class NeighborAttributes(IPNeighborSubAttributes):
                address_families = managedattribute(
                    name='address_families',
                    finit=typedset(AddressFamily).copy,
                    type=typedset(AddressFamily)._from_iterable)

                @address_families.defaulter
                def address_families(self):
                    return self.parent.address_families.copy()

                class AddressFamilyAttributes(AddressFamilySubAttributes):
                    pass

                address_family_attr = managedattribute(
                    name='address_family_attr',
                    read_only=True,
                    doc=AddressFamilySubAttributes.__doc__)

                @address_family_attr.initter
                def address_family_attr(self):
                    return SubAttributesDict(self.AddressFamilyAttributes,
                                             parent=self)
Example #14
0
            class InterfaceAttributes(InterfaceSubAttributes):
                def __init__(self, parent, key):
                    self.intf = key
                    super().__init__(parent, key)

                groups = managedattribute(
                    name='groups',
                    finit=typedset(
                        managedattribute.test_isinstance(IgmpGroup)).copy,
                    type=typedset(managedattribute.test_isinstance(
                        IgmpGroup))._from_iterable,
                    doc='A `set` of IgmpGroup associated objects')

                def add_groups(self, groups):
                    self.groups.add(groups)

                def remove_groups(self, groups):
                    groups._device = None
                    try:
                        self.groups.remove(groups)
                    except:
                        pass
Example #15
0
                class CeAttributes(KeyedSubAttributes):
                    @classmethod
                    def _sanitize_key(cls, key):
                        return int(key)

                    ce_id = managedattribute(name='ce_id',
                                             read_only=True)  # read-only key

                    interfaces = managedattribute(
                        name='interfaces',
                        finit=typedset(
                            managedattribute.test_isinstance(Interface)).copy,
                        type=typedset(
                            managedattribute.test_isinstance(
                                Interface))._from_iterable)

                    def add_interface(self, intf):  # TODO DEPRECATE
                        self.interfaces.add(intf)

                    def remove_interface(self, intf):  # TODO DEPRECATE
                        self.interfaces.remove(intf)

                    class InterfaceAttributes(InterfaceSubAttributes):

                        remote_ce_id = None
                        #Always only one per interface
                        #    interface GigabitEthernet0/0/1/0 remote-ce-id 2000
                        #    !!% Invalid argument: AC already used by existing xconnect

                    interface_attr = None  # InterfaceAttributes

                    def __init__(self, parent, key):
                        self._ce_id = key
                        super().__init__(parent=parent)
                        self.interface_attr = SubAttributesDict(
                            self.InterfaceAttributes, parent=self)
Example #16
0
    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @address_families.initter
        def address_families(self):
            return frozenset(self.parent.address_families)

        class AddressFamilyAttributes(AddressFamilySubAttributes):

            def __init__(self, parent, key):
                super().__init__(parent, key)

            def add_prefix_sid_map_entry(self,entry):
                self.prefix_sid_map |= {entry}

            def add_connected_prefix_sid_map_entry(self,entry):
                self.connected_prefix_sid_map |= {entry}

            def remove_prefix_sid_map_entry(self,entry):
                self.prefix_sid_map.remove(entry)

            def remove_connected_prefix_sid_map_entry(self,entry):
                self.connected_prefix_sid_map.remove(entry)

        address_family_attr = managedattribute(
            name='address_family_attr',
            read_only=True,
            doc=AddressFamilyAttributes.__doc__)

        @address_family_attr.initter
        def address_family_attr(self):
            return SubAttributesDict(self.AddressFamilyAttributes, parent=self)

        def __init__(self, parent, key):
            super().__init__(parent, key)
Example #17
0
class Bgp(Routing, DeviceFeature):

    bgp_id = managedattribute(
        name='bgp_id',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    asn = managedattribute(
        name='asn',
        type=int,
        doc='AS number (mandatory)')

    address_families = managedattribute(
        name='address_families',
        finit=typedset(AddressFamily, {AddressFamily.ipv4_unicast}).copy,
        type=typedset(AddressFamily)._from_iterable)

    nsr = managedattribute(
        name='nsr',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    # iosxr only
    instance_name = managedattribute(
        name='instance_name',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    ibgp_policy_out_enforce_modifications = managedattribute(
        name='ibgp_policy_out_enforce_modifications',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    activate = managedattribute(
        name='activate',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    # ==== Device attribute section =======
    protocol_shutdown = managedattribute(
        name='protocol_shutdown',
        default=None,
        type=(None, managedattribute.test_istype(bool)),
        doc='Bgp instance shutdown')

    # ==================== NXOS specific ====================

    # feature bgp
    enabled = managedattribute(
        name='enabled',
        default=False,
        type=(None, managedattribute.test_istype(bool)),
        doc='Enable or disable feature bgp')

    # ===========================================================

    # ==== Peer Session section =======
    class PS_TRANSPORT_CONNECTION_MODE(Enum):
        active = 'active'
        passive = 'passive'

    ps_transport_connection_mode = managedattribute(
        name='ps_transport_connection_mode',
        default=None,
        type=(None, PS_TRANSPORT_CONNECTION_MODE),
        doc='Peer session transport connection mode')

    ps_name = managedattribute(
        name='ps_name',
        default=None,
        type=(None, managedattribute.test_istype(str)),
        doc='Peer session name')

    ps_fall_over_bfd = managedattribute(
        name='ps_fall_over_bfd',
        default=None,
        type=(None, managedattribute.test_istype(bool)),
        doc='Peer session fall over bfd')

    ps_suppress_four_byte_as_capability = managedattribute(
        name='ps_suppress_four_byte_as_capability',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ps_description = managedattribute(
        name='ps_description',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    ps_disable_connected_check = managedattribute(
        name='ps_disable_connected_check',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ps_ebgp_multihop = managedattribute(
        name='ps_ebgp_multihop',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ps_ebgp_multihop_max_hop = managedattribute(
        name='ps_ebgp_multihop_max_hop',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    ps_local_as_as_no = managedattribute(
        name='ps_local_as_as_no',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    ps_local_as_no_prepend = managedattribute(
        name='ps_local_as_no_prepend',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ps_local_as_dual_as = managedattribute(
        name='ps_local_as_dual_as',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ps_local_as_replace_as = managedattribute(
        name='ps_local_as_replace_as',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ps_password_text = managedattribute(
        name='ps_password_text',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    ps_remote_as = managedattribute(
        name='ps_remote_as',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    ps_shutdown = managedattribute(
        name='ps_shutdown',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ps_keepalive_interval = managedattribute(
        name='ps_keepalive_interval',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    ps_hodltime = managedattribute(
        name='ps_hodltime',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    ps_update_source = managedattribute(
        name='ps_update_source',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    # ==== Peer Policy section ===================
    class PP_SEND_COMMUNITY(Enum):
        standard = 'standard'
        extended = 'extended'
        both = 'both'

    pp_send_community = managedattribute(
        name='pp_send_community',
        default=None,
        type=(None, PP_SEND_COMMUNITY),
        doc='Peer policy send community type')

    class PP_AF_NAME(Enum):
        ipv4_unicast = 'ipv4 unicast'
        ipv6_unicast = 'ipv6 unicast'

    # XR only
    pp_af_name = managedattribute(
        name='pp_af_name',
        default=None,
        type=(None, PP_AF_NAME),
        doc='Peer policy address-family name')

    pp_name = managedattribute(
        name='pp_name',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    pp_allowas_in = managedattribute(
        name='pp_allowas_in',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    pp_allowas_in_as_number = managedattribute(
        name='pp_allowas_in_as_number',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    pp_as_override = managedattribute(
        name='pp_as_override',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    pp_default_originate = managedattribute(
        name='pp_default_originate',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    pp_default_originate_route_map = managedattribute(
        name='pp_default_originate',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    pp_route_map_name_in = managedattribute(
        name='pp_route_map_name_in',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    pp_route_map_name_out = managedattribute(
        name='pp_route_map_name_out',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    pp_maximum_prefix_max_prefix_no = managedattribute(
        name='pp_maximum_prefix_max_prefix_no',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    pp_maximum_prefix_threshold = managedattribute(
        name='pp_maximum_prefix_threshold',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    pp_maximum_prefix_restart = managedattribute(
        name='pp_maximum_prefix_restart',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    pp_maximum_prefix_warning_only = managedattribute(
        name='pp_maximum_prefix_restart',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    pp_next_hop_self = managedattribute(
        name='pp_next_hop_self',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    pp_route_reflector_client = managedattribute(
        name='pp_route_reflector_client',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    pp_soft_reconfiguration = managedattribute(
        name='pp_soft_reconfiguration',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    pp_soo = managedattribute(
        name='pp_soo',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    # ==== VRF section ===========================
    dynamic_med_interval = managedattribute(
        name='dynamic_med_interval',
        default=None,
        type=(None, managedattribute.test_istype(int)),
        doc='Dynamic med interval time in seconds')

    shutdown = managedattribute(
        name='shutdown',
        default=None,
        type=(None, managedattribute.test_istype(bool)),
        doc='Bgp VRF shutdown')

    flush_routes = managedattribute(
        name='flush_routes',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    isolate = managedattribute(
        name='isolate',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    disable_policy_batching_ipv4 = managedattribute(
        name='disable_policy_batching_ipv4',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    disable_policy_batching_ipv6 = managedattribute(
        name='disable_policy_batching_ipv6',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    always_compare_med = managedattribute(
        name='always_compare_med',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    bestpath_compare_routerid = managedattribute(
        name='bestpath_compare_routerid',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    bestpath_cost_community_ignore = managedattribute(
        name='bestpath_cost_community_ignore',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    bestpath_med_missing_at_worst = managedattribute(
        name='bestpath_med_missing_at_worst',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    cluster_id = managedattribute(
        name='cluster_id',
        default=None,
        type=(None, managedattribute.test_istype(int),
              managedattribute.test_istype(str)))

    confederation_identifier = managedattribute(
        name='confederation_identifier',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    confederation_peers_as = managedattribute(
        name='confederation_peers_as',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    graceful_restart = managedattribute(
        name='graceful_restart',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    graceful_restart_restart_time = managedattribute(
        name='graceful_restart_restart_time',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    graceful_restart_stalepath_time = managedattribute(
        name='graceful_restart_stalepath_time',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    log_neighbor_changes = managedattribute(
        name='log_neighbor_changes',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    router_id = managedattribute(
        name='router_id',
        default=None,
        type=(None, IPv4Address))

    keepalive_interval = managedattribute(
        name='keepalive_interval',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    holdtime = managedattribute(
        name='holdtime',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    enforce_first_as = managedattribute(
        name='enforce_first_as',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    fast_external_fallover = managedattribute(
        name='fast_external_fallover',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    default_choice_ipv4_unicast = managedattribute(
        name='default_choice_ipv4_unicast',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    # ==== Address-family section ================
    class AF_LABEL_ALLOCATION_MODE(Enum):
        per_vrf = 'per-vrf'

    af_label_allocation_mode = managedattribute(
        name='af_label_allocation_mode',
        default=None,
        type=(None, AF_LABEL_ALLOCATION_MODE),
        doc='Address family label allocation mode')
    # vxlan
    af_advertise_pip = managedattribute(
        name='af_advertise_pip',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_name = managedattribute(
        name='af_name',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_dampening = managedattribute(
        name='af_dampening',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_dampening_route_map = managedattribute(
        name='af_dampening_route_map',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_dampening_half_life_time = managedattribute(
        name='af_dampening_half_life_time',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_dampening_reuse_time = managedattribute(
        name='af_dampening_reuse_time',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_dampening_suppress_time = managedattribute(
        name='af_dampening_suppress_time',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_dampening_max_suppress_time = managedattribute(
        name='af_dampening_max_suppress_time',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_nexthop_route_map = managedattribute(
        name='af_nexthop_route_map',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_nexthop_trigger_enable = managedattribute(
        name='af_nexthop_trigger_enable',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_nexthop_trigger_delay_critical = managedattribute(
        name='af_nexthop_trigger_delay_critical',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_nexthop_trigger_delay_non_critical = managedattribute(
        name='af_nexthop_trigger_delay_non_critical',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_client_to_client_reflection = managedattribute(
        name='af_client_to_client_reflection',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_distance_extern_as = managedattribute(
        name='af_distance_extern_as',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_distance_internal_as = managedattribute(
        name='af_distance_internal_as',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_distance_local = managedattribute(
        name='af_distance_local',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_maximum_paths_ebgp = managedattribute(
        name='af_maximum_paths_ebgp',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_maximum_paths_ibgp = managedattribute(
        name='af_maximum_paths_ibgp',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_maximum_paths_eibgp = managedattribute(
        name='af_maximum_paths_eibgp',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_aggregate_address_ipv4_address = managedattribute(
        name='af_aggregate_address_ipv4_address',
        default=None,
        type=(None, IPv4Address))

    af_aggregate_address_ipv4_mask = managedattribute(
        name='af_aggregate_address_ipv4_mask',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_aggregate_address_as_set = managedattribute(
        name='af_aggregate_address_as_set',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_aggregate_address_summary_only = managedattribute(
        name='af_aggregate_address_summary_only',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_network_number = managedattribute(
        name='af_network_number',
        default=None,
        type=(None, IPv4Address))

    af_network_mask = managedattribute(
        name='af_network_mask',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_network_route_map = managedattribute(
        name='af_network_route_map',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_isis = managedattribute(
        name='af_redist_isis',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_isis_metric = managedattribute(
        name='af_redist_isis_metric',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_isis_route_policy = managedattribute(
        name='af_redist_isis_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_ospf = managedattribute(
        name='af_redist_ospf',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_ospf_metric = managedattribute(
        name='af_redist_ospf_metric',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    af_redist_ospf_route_policy = managedattribute(
        name='af_redist_ospf_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_rip = managedattribute(
        name='af_redist_rip',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_redist_rip_metric = managedattribute(
        name='af_redist_rip_metric',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_rip_route_policy = managedattribute(
        name='af_redist_rip_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_static = managedattribute(
        name='af_redist_static',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_redist_static_metric = managedattribute(
        name='af_redist_static_metric',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_static_route_policy = managedattribute(
        name='af_redist_static_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_connected = managedattribute(
        name='af_redist_connected',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_redist_connected_metric = managedattribute(
        name='af_redist_connected_metric',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_redist_connected_route_policy = managedattribute(
        name='af_redist_connected_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_v6_aggregate_address_ipv6_address = managedattribute(
        name='af_v6_aggregate_address_ipv6_address',
        default=None,
        type=(None, IPv6Network))

    af_v6_aggregate_address_as_set = managedattribute(
        name='af_v6_aggregate_address_as_set',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_v6_aggregate_address_summary_only = managedattribute(
        name='af_v6_aggregate_address_summary_only',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_v6_network_number = managedattribute(
        name='af_v6_network_number',
        default=None,
        type=(None, IPv6Network))

    af_v6_network_route_map = managedattribute(
        name='af_v6_network_route_map',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    af_v6_allocate_label_all = managedattribute(
        name='af_v6_allocate_label_all',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    af_retain_rt_all = managedattribute(
        name='af_retain_rt_all',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    # ==== Neighbor section ======================
    class NBR_TRANSPORT_CONNECTION_MODE(Enum):
        active = 'active'
        passive = 'passive'

    nbr_transport_connection_mode = managedattribute(
        name='nbr_transport_connection_mode',
        default=None,
        type=(None, NBR_TRANSPORT_CONNECTION_MODE),
        doc='Neighbor transport connection mode')

    class NBR_PEER_TYPE(Enum):
        fabric_border_leaf = 'fabric-border-leaf'
        fabric_external = 'fabric-external'

    nbr_peer_type = managedattribute(
        name='nbr_peer_type',
        default=None,
        type=(None, NBR_PEER_TYPE),
        doc='Neighbor peer type')

    class NBR_SEND_COMMUNITY(Enum):
        standard = 'standard'
        extended = 'extended'
        both = 'both'

    nbr_send_community = managedattribute(
        name='nbr_send_community',
        default=None,
        type=(None, NBR_SEND_COMMUNITY),
        doc='Neighbor address family send community type')

    nbr_fall_over_bfd = managedattribute(
        name='nbr_fall_over_bfd',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_suppress_four_byte_as_capability = managedattribute(
        name='nbr_suppress_four_byte_as_capability',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_description = managedattribute(
        name='nbr_description',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_disable_connected_check = managedattribute(
        name='nbr_disable_connected_check',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_ebgp_multihop = managedattribute(
        name='nbr_ebgp_multihop',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_ebgp_multihop_max_hop = managedattribute(
        name='nbr_ebgp_multihop_max_hop',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_inherit_peer_session = managedattribute(
        name='nbr_inherit_peer_session',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_local_as_as_no = managedattribute(
        name='nbr_local_as_as_no',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_local_as_no_prepend = managedattribute(
        name='nbr_local_as_no_prepend',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_local_as_replace_as = managedattribute(
        name='nbr_local_as_replace_as',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_local_as_dual_as = managedattribute(
        name='nbr_local_as_dual_as',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_remote_as = managedattribute(
        name='nbr_remote_as',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_remove_private_as = managedattribute(
        name='nbr_remove_private_as',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    class NBR_REMOVE_PRIVATE_AS_AF_NAME(Enum):
        ipv4_unicast = 'ipv4 unicast'
        ipv6_unicast = 'ipv6 unicast'

    nbr_remove_private_as_af_name = managedattribute(
        name='nbr_remove_private_as_af_name',
        default=None,
        type=(None, NBR_REMOVE_PRIVATE_AS_AF_NAME),
        doc='meighbor remove private as')

    nbr_shutdown = managedattribute(
        name='nbr_shutdown',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_keepalive_interval = managedattribute(
        name='nbr_keepalive_interval',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_holdtime = managedattribute(
        name='nbr_holdtime',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_update_source = managedattribute(
        name='nbr_update_source',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_password_text = managedattribute(
        name='nbr_password_text',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    # ==== Neighbor/Address-family section =======
    nbr_af_name = managedattribute(
        name='nbr_af_name',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_af_suppress_signaling_protocol_ldp = managedattribute(
        name='nbr_af_suppress_signaling_protocol_ldp',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_af_allowas_in = managedattribute(
        name='nbr_af_allowas_in',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_af_allowas_in_as_number = managedattribute(
        name='nbr_af_allowas_in_as_number',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_af_inherit_peer_policy = managedattribute(
        name='nbr_af_inherit_peer_policy',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_af_inherit_peer_seq = managedattribute(
        name='nbr_af_inherit_peer_seq',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_af_maximum_prefix_max_prefix_no = managedattribute(
        name='nbr_af_maximum_prefix_max_prefix_no',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_af_maximum_prefix_threshold = managedattribute(
        name='nbr_af_maximum_prefix_threshold',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_af_maximum_prefix_restart = managedattribute(
        name='nbr_af_maximum_prefix_restart',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    nbr_af_maximum_prefix_warning_only = managedattribute(
        name='nbr_af_maximum_prefix_warning_only',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_af_route_map_name_in = managedattribute(
        name='nbr_af_route_map_name_in',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_af_route_map_name_out = managedattribute(
        name='nbr_af_route_map_name_out',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_af_route_reflector_client = managedattribute(
        name='nbr_af_route_reflector_client',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    class NBR_AF_SEND_COMMUNITY(Enum):
        standard = 'standard'
        extended = 'extended'
        both = 'both'

    nbr_af_send_community = managedattribute(
        name='nbr_af_send_community',
        default=None,
        type=(None, NBR_AF_SEND_COMMUNITY),
        doc='Neighbor address family send community type')

    nbr_af_soft_reconfiguration = managedattribute(
        name='nbr_af_soft_reconfiguration',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_af_next_hop_self = managedattribute(
        name='nbr_af_next_hop_self',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_af_as_override = managedattribute(
        name='nbr_af_as_override',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_af_default_originate = managedattribute(
        name='nbr_af_default_originate',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nbr_af_default_originate_route_map = managedattribute(
        name='nbr_af_default_originate_route_map',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_af_soo = managedattribute(
        name='nbr_af_soo',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    nbr_af_rewrite_evpn_rt_asn = managedattribute(
        name='nbr_af_rewrite_evpn_rt_asn',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    # XXXJST TODO Merge with send_community_ebgp
    send_community = managedattribute(
        name='send_community',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    ha_mode = managedattribute(
        name='ha_mode',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    bfd_fast_detect = managedattribute(
        name='bfd_fast_detect',
        default=None,
        type=(None,
              managedattribute.test_istype(bool),
              managedattribute.test_in((
                  'strict-mode',
              ))))
    # this will configured under vrf in Takashi's structure
    # this one is under vrf/neighbor
    bfd_minimum_interval = managedattribute(
        name='bfd_minimum_interval',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    bfd_multiplier = managedattribute(
        name='bfd_multiplier',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    # ########
    # only supports in XR, TODO apply in other platforms
    encapsulation_type = managedattribute(
        name='encapsulation_type',
        default=None,
        type=(None, managedattribute.test_in((
            'mpls',
            'vxlan',
        ))))

    import_stitching_rt = managedattribute(
        name='import_stitching_rt',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    import_re_originate = managedattribute(
        name='import_re_originate',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    import_re_originate_stitching_rt = managedattribute(
        name='import_re_originate_stitching_rt',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    import_stitching_rt_re_originate = managedattribute(
        name='import_stitching_rt_re_originate',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    advertise_l2vpn_evpn_re_originated = managedattribute(
        name='advertise_l2vpn_evpn_re_originated',
        default=None,
        type=(None,
              managedattribute.test_istype(bool),
              managedattribute.test_in((
                  'regular-rt',
                  'stitching-rt',
              ))))

    advertise_vpnv4_unicast = managedattribute(
        name='advertise_vpnv4_unicast',
        default=None,
        type=(None, managedattribute.test_istype(bool)))
    # ##############

    route_policy_in = managedattribute(
        name='route_policy_in',
        default=None,
        type=(None,
              managedattribute.test_istype(RoutePolicy)))

    route_policy_out = managedattribute(
        name='route_policy_out',
        default=None,
        type=(None,
              managedattribute.test_istype(RoutePolicy)))

    send_community_ebgp = managedattribute(
        name='send_community_ebgp',
        default=None,
        type=(None,
              managedattribute.test_istype(bool)))

    retain_route_target = managedattribute(
        name='retain_route_target',
        default=None,
        type=(None,
              managedattribute.test_istype(bool),
              managedattribute.test_istype(RoutePolicy)))

    disable_bgp_default_ipv4_unicast = managedattribute(
        name='disable_bgp_default_ipv4_unicast',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    route_reflector_client = managedattribute(
        name='route_reflector_client',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    route_reflector_client_inheritance_disable = managedattribute(
        name='route_reflector_client_inheritance_disable',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nexthop_self = managedattribute(
        name='nexthop_self',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nexthop_self_inheritance_disable = managedattribute(
        name='nexthop_self_inheritance_disable',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ebgp_multihop_max_hop_count = managedattribute(
        name='ebgp_multihop_max_hop_count',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    ebgp_multihop_mpls = managedattribute(
        name='ebgp_multihop_mpls',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    send_extended_community_ebgp = managedattribute(
        name='send_extended_community_ebgp',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    send_extended_community_ebgp_inheritance_disable = managedattribute(
        name='send_extended_community_ebgp_inheritance_disable',
        default=None,
        type=(None, managedattribute.test_istype(bool)))
 
    # ########
    # only supports in XR, TODO apply in other platforms
    nexthop_mpls_forwarding_ibgp = managedattribute(
        name='nexthop_mpls_forwarding_ibgp',
        default=None,
        type=(None, managedattribute.test_istype(bool)))
    # #########

    as_override = managedattribute(
        name='as_override',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    as_override_inheritance = managedattribute(
        name='as_override_inheritance',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    allocate_label = managedattribute(
        name='allocate_label',
        default=None,
        type=(None,
              managedattribute.test_istype(RoutePolicy),
              managedattribute.test_in((
                  'all',
              ))))

    label_mode = managedattribute(
        name='label_mode',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    maximum_paths_ibgp = managedattribute(
        name='maximum_paths_ibgp',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    maximum_paths_ebgp = managedattribute(
        name='maximum_paths_ebgp',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    redistributes = managedattribute(
        name='redistributes',
        fdef=list,
        type=managedattribute.test_list_of(Redistribution))

    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):

        update_source = managedattribute(
            name='update_source',
            default=None,
            type=(None, managedattribute.test_isinstance(Interface)))

        vrfs = managedattribute(
            name='vrfs',
            finit=typedset(managedattribute.test_isinstance((
                type(None), Vrf)), {None}).copy,
            type=typedset(managedattribute.test_isinstance((
                type(None), Vrf)))._from_iterable)

        def add_vrf(self, vrf):  # TODO DEPRECATE
            self.vrfs.add(vrf)

        def remove_vrf(self, vrf):  # TODO DEPRECATE
            self.vrfs.remove(vrf)

        @property
        def router_id(self):
            return self.vrf_attr[None].router_id

        @router_id.setter
        def router_id(self, value):
            self.vrf_attr[None].router_id = value

        class PeerSessionAttributes(KeyedSubAttributes):
            def __init__(self, parent, key):
                self.ps_name = key
                super().__init__(parent)

        peer_session_attr = managedattribute(
            name='peer_session_attr',
            read_only=True,
            doc=PeerSessionAttributes.__doc__)

        @peer_session_attr.initter
        def peer_session_attr(self):
            return SubAttributesDict(self.PeerSessionAttributes, parent=self)

        class PeerPolicyAttributes(KeyedSubAttributes):
            def __init__(self, parent, key):
                self.pp_name = key
                super().__init__(parent)

        peer_policy_attr = managedattribute(
            name='peer_policy_attr',
            read_only=True,
            doc=PeerPolicyAttributes.__doc__)

        @peer_policy_attr.initter
        def peer_policy_attr(self):
            return SubAttributesDict(self.PeerPolicyAttributes, parent=self)

        class VrfAttributes(VrfSubAttributes):

            rd = Vrf.rd.copy()

            @rd.defaulter
            def rd(self):
                vrf = self.vrf
                return vrf and vrf.rd

            address_families = managedattribute(
                name='address_families',
                finit=typedset(AddressFamily).copy,
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return self.parent.address_families.copy()

            class AddressFamilyAttributes(AddressFamilySubAttributes):
                pass

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilySubAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                        parent=self)

            class NeighborAttributes(IPNeighborSubAttributes):

                address_families = managedattribute(
                    name='address_families',
                    finit=typedset(AddressFamily).copy,
                    type=typedset(AddressFamily)._from_iterable)

                @address_families.defaulter
                def address_families(self):
                    return self.parent.address_families.copy()

                class AddressFamilyAttributes(AddressFamilySubAttributes):
                    pass

                address_family_attr = managedattribute(
                    name='address_family_attr',
                    read_only=True,
                    doc=AddressFamilySubAttributes.__doc__)

                @address_family_attr.initter
                def address_family_attr(self):
                    return SubAttributesDict(self.AddressFamilyAttributes,
                                             parent=self)


            neighbor_attr = managedattribute(
                name='neighbor_attr',
                read_only=True,
                doc=NeighborAttributes.__doc__)

            @neighbor_attr.initter
            def neighbor_attr(self):
                return SubAttributesDict(self.NeighborAttributes, parent=self)

            router_id = managedattribute(
                name='router_id',
                default=None,
                type=(None, IPv4Address))

            neighbors = managedattribute(
                name='neighbors',
                finit=set,
                type=managedattribute.test_set_of(IPNeighbor),
                gettype=frozenset)

            neighbors = managedattribute(
                name='neighbors',
                finit=typedset(IPNeighbor).copy,
                type=typedset(IPNeighbor)._from_iterable)

            def add_neighbor(self, neighbor):  # TODO DEPRECATE
                self.neighbors.add(neighbor)

            def remove_neighbor(self, neighbor):  # TODO DEPRECATE
                self.neighbors.remove(neighbor)

        vrf_attr = managedattribute(
            name='vrf_attr',
            read_only=True,
            doc=VrfAttributes.__doc__)

        @vrf_attr.initter
        def vrf_attr(self):
            return SubAttributesDict(self.VrfAttributes, parent=self)

        @property
        def neighbors(self):
            return self.vrf_attr[None].neighbors

        @property
        def add_neighbor(self):
            return self.vrf_attr[None].add_neighbor

        @property
        def remove_neighbor(self):
            return self.vrf_attr[None].remove_neighbor

        @property
        def address_family_attr(self):
            return self.vrf_attr[None].address_family_attr

        @property
        def neighbor_attr(self):
            return self.vrf_attr[None].neighbor_attr

        def __init__(self, parent, key):
            super().__init__(parent, key)

    device_attr = managedattribute(
        name='device_attr',
        read_only=True,
        doc=DeviceAttributes.__doc__)

    @device_attr.initter
    def device_attr(self):
        return SubAttributesDict(self.DeviceAttributes, parent=self)

    def __init__(self, asn=None, bgp_id=None, instance_name=None, *args, **kwargs):
        if asn:
            self.asn = asn
        if bgp_id:
            self.bgp_id = int(bgp_id)
        if instance_name:
            self.instance_name = instance_name
        # Make sure at least one was populated:
        if not asn and not bgp_id:
            raise TypeError("__init__() requires either 'asn' or 'bgp_id' "
                            "to be provided")
        super().__init__(*args, **kwargs)

    def build_config(self, devices=None, apply=True, attributes=None,
                     **kwargs):
        cfgs = {}
        assert not kwargs, kwargs
        attributes = AttributesHelper(self, attributes)

        if devices is None:
            devices = self.devices
        devices = set(devices)

        for key, sub, attributes2 in attributes.mapping_items(
                'device_attr',
                keys=devices, sort=True):
            cfgs[key] = sub.build_config(apply=False, attributes=attributes2)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs

    def build_unconfig(self, devices=None, apply=True, attributes=None,
                       **kwargs):
        cfgs = {}
        assert not kwargs, kwargs
        attributes = AttributesHelper(self, attributes)

        if devices is None:
            devices = self.devices
        devices = set(devices)

        for key, sub, attributes2 in attributes.mapping_items(
                'device_attr',
                keys=devices, sort=True):
            cfgs[key] = sub.build_unconfig(apply=False, attributes=attributes2)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs

    @classmethod
    def learn_config(self, device, **kwargs):
        '''
            A method that learn the device configurational state and create
            a conf object with the same configuration.

            Args:
                self (`obj`): Conf object.
                device (`obj`): The device that will be used to parse the
                    command.
        '''

        # Abstracting the show running bgp as per device os
        ret = Lookup.from_device(device)
        cmd = ret.parser.show_bgp.ShowRunningConfigBgp

        maker = ops_Base(device=device)

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][bgp_id]',
                       dest='bgp[instance][(?P<instance>.*)][bgp_id]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)]'
                           '[protocol_shutdown]',
                       dest='bgp[instance][(?P<instance>.*)]'
                            '[protocol_shutdown]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][pp_name]'
                           '[(?P<pp_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][peer_policy_attr]'
                            '[(?P<pp_name>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][ps_name]'
                           '[(?P<ps_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)]'
                            '[peer_session_attr][(?P<ps_name>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)]'
                           '[vrf][(?P<vrf>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][vrf]'
                           '[(?P<vrf>.*)][af_name][(?P<af_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)][address_family_attr]'
                            '[(?P<af_name>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][vrf]'
                           '[(?P<vrf>.*)][neighbor_id][(?P<neighbor_id>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)][neighbor_attr]'
                            '[(?P<neighbor_id>.*)]')

        maker.add_leaf(cmd=cmd,
                       src='[bgp][instance][(?P<instance>.*)][vrf]'
                           '[(?P<vrf>.*)][neighbor_id][(?P<neighbor_id>.*)]'
                           '[nbr_af_name][(?P<nbr_af_name>.*)]',
                       dest='bgp[instance][(?P<instance>.*)][vrf_attr]'
                            '[(?P<vrf>.*)][neighbor_attr][(?P<neighbor_id>.*)]'
                            '[address_family_attr][(?P<nbr_af_name>.*)]')

        # A workaround to pass the context as in maker it expects Context.cli
        # not just a string 'cli.
        maker.context_manager[cmd] = Context.cli

        maker.make()

        # Take a copy of the object dictionary
        if not hasattr(maker, 'bgp'):
            maker.bgp = {}
        new_bgp = maker.bgp

        # List of mapped conf objects
        conf_obj_list = []

        # Main structure attributes in the conf object
        structure_keys = ['peer_policy_attr',
                          'vrf_attr',
                          'peer_session_attr',
                          'address_family_attr',
                          'neighbor_attr']

        # Deleting the old format keys from the object and building the
        # conf objects
        for instance_key in new_bgp['instance']:
            if 'vrf_attr' in new_bgp['instance'][instance_key]:
                for vrf in new_bgp['instance'][instance_key]['vrf_attr']:
                    if 'neighbor_id' in new_bgp['instance'][instance_key]\
                        ['vrf_attr'][vrf]:
                        del new_bgp['instance'][instance_key]['vrf_attr'][vrf]\
                            ['neighbor_id']
                    if 'af_name' in new_bgp['instance'][instance_key]\
                        ['vrf_attr'][vrf]:
                        del new_bgp['instance'][instance_key]['vrf_attr'][vrf]\
                            ['af_name']
                    if 'neighbor_attr' in new_bgp['instance'][instance_key]\
                        ['vrf_attr'][vrf]:
                        for neighbor in new_bgp['instance'][instance_key]\
                            ['vrf_attr'][vrf]['neighbor_attr'].keys():
                            if 'nbr_af_name' in new_bgp['instance']\
                                [instance_key]['vrf_attr'][vrf]\
                                ['neighbor_attr'][neighbor]:
                                del new_bgp['instance'][instance_key]\
                                    ['vrf_attr'][vrf]['neighbor_attr']\
                                    [neighbor]['nbr_af_name']

            # Instiantiate a BGP conf object
            conf_obj = self(bgp_id=new_bgp['instance'][instance_key]['bgp_id'])

            # Pass the class method not the instnace.
            maker.dict_to_obj(conf=conf_obj,\
                              struct=structure_keys,\
                              struct_to_map=new_bgp['instance'][instance_key])

            conf_obj_list.append(conf_obj)

        # List of mapped conf objects
        return conf_obj_list
Example #18
0
        class VrfAttributes(VrfSubAttributes):

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            advertise_interfaces = managedattribute(
                name='advertise_interfaces',
                type=typedset(managedattribute.test_isinstance(
                    Interface))._from_iterable)

            @advertise_interfaces.defaulter
            def advertise_interfaces(self):
                return frozenset(self.parent.advertise_interfaces)

            # implicit: interface_attr = parent.interface_attr
            # implicit: interfaces = parent.interfaces

            router_id = managedattribute(
                name='router_id',
                default=None,
                type=(None, IPv4Address,\
                      managedattribute.test_isinstance(Interface)))

            class NeighborAttributes(IPLsrNeighborSubAttributes):
                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            neighbor_attr = managedattribute(name='neighbor_attr',
                                             read_only=True,
                                             doc=NeighborAttributes.__doc__)

            @neighbor_attr.initter
            def neighbor_attr(self):
                return SubAttributesDict(self.NeighborAttributes, parent=self)

            neighbors = managedattribute(
                name='neighbors',
                finit=typedset(_ldp_neighbor).copy,
                type=typedset(_ldp_neighbor)._from_iterable)

            class AddressFamilyAttributes(AddressFamilySubAttributes):

                allowed_keys = (AddressFamily.ipv4, AddressFamily.ipv6)

                advertise_interfaces = managedattribute(
                    name='advertise_interfaces',
                    type=typedset(managedattribute.test_isinstance(
                        Interface))._from_iterable)

                @advertise_interfaces.defaulter
                def advertise_interfaces(self):
                    return frozenset(self.parent.advertise_interfaces)

                class NeighborAttributes(IPLsrNeighborSubAttributes):
                    def __init__(self, **kwargs):
                        super().__init__(**kwargs)

                neighbor_attr = managedattribute(
                    name='neighbor_attr',
                    read_only=True,
                    doc=NeighborAttributes.__doc__)

                @neighbor_attr.initter
                def neighbor_attr(self):
                    return SubAttributesDict(self.NeighborAttributes,
                                             parent=self)

                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                         parent=self)

            def __init__(self, **kwargs):
                super().__init__(**kwargs)
Example #19
0
    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):

        enabled_feature = managedattribute(
            name='enabled_feature',
            default=False,
            type=managedattribute.test_istype(bool),
            doc='''Argument to control 'feature ldp' CLI''')

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @address_families.defaulter
        def address_families(self):
            return frozenset(self.parent.address_families)

        advertise_interfaces = managedattribute(
            name='advertise_interfaces',
            type=typedset(
                managedattribute.test_isinstance(Interface))._from_iterable)

        @advertise_interfaces.defaulter
        def advertise_interfaces(self):
            device = self.device
            return frozenset(interface
                             for interface in self.parent.advertise_interfaces
                             if interface.device is device)

        @property
        def vrfs(self):
            return \
                self.force_vrfs | \
                {intf.vrf for intf in self.interfaces}

        @property
        def interfaces(self):
            device = self.device
            interfaces = set(self.parent.interfaces)
            #interfaces.update(*[link.interfaces for link in self.parent.links])
            interfaces = {intf for intf in interfaces if intf.device is device}
            return frozenset(interfaces)

        class MldpAttributes(SubAttributes):
            def __init__(self, _device_attr):
                self._device_attr = _device_attr
                super().__init__(
                    # Ldp.mldp
                    parent=_device_attr.parent.mldp)

            @property
            def testbed(self):
                return self._device_attr.testbed

            @property
            def device_name(self):
                return self._device_attr.device_name

            @property
            def device(self):
                return self._device_attr.device

        mldp = managedattribute(name='mldp',
                                read_only=True,
                                doc=MldpAttributes.__doc__)

        @mldp.initter
        def mldp(self):
            return self.MldpAttributes(_device_attr=self)

        class VrfAttributes(VrfSubAttributes):

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            advertise_interfaces = managedattribute(
                name='advertise_interfaces',
                type=typedset(managedattribute.test_isinstance(
                    Interface))._from_iterable)

            @advertise_interfaces.defaulter
            def advertise_interfaces(self):
                return frozenset(self.parent.advertise_interfaces)

            # implicit: interface_attr = parent.interface_attr
            # implicit: interfaces = parent.interfaces

            router_id = managedattribute(
                name='router_id',
                default=None,
                type=(None, IPv4Address,\
                      managedattribute.test_isinstance(Interface)))

            class NeighborAttributes(IPLsrNeighborSubAttributes):
                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            neighbor_attr = managedattribute(name='neighbor_attr',
                                             read_only=True,
                                             doc=NeighborAttributes.__doc__)

            @neighbor_attr.initter
            def neighbor_attr(self):
                return SubAttributesDict(self.NeighborAttributes, parent=self)

            neighbors = managedattribute(
                name='neighbors',
                finit=typedset(_ldp_neighbor).copy,
                type=typedset(_ldp_neighbor)._from_iterable)

            class AddressFamilyAttributes(AddressFamilySubAttributes):

                allowed_keys = (AddressFamily.ipv4, AddressFamily.ipv6)

                advertise_interfaces = managedattribute(
                    name='advertise_interfaces',
                    type=typedset(managedattribute.test_isinstance(
                        Interface))._from_iterable)

                @advertise_interfaces.defaulter
                def advertise_interfaces(self):
                    return frozenset(self.parent.advertise_interfaces)

                class NeighborAttributes(IPLsrNeighborSubAttributes):
                    def __init__(self, **kwargs):
                        super().__init__(**kwargs)

                neighbor_attr = managedattribute(
                    name='neighbor_attr',
                    read_only=True,
                    doc=NeighborAttributes.__doc__)

                @neighbor_attr.initter
                def neighbor_attr(self):
                    return SubAttributesDict(self.NeighborAttributes,
                                             parent=self)

                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                         parent=self)

            def __init__(self, **kwargs):
                super().__init__(**kwargs)

        vrf_attr = managedattribute(name='vrf_attr',
                                    read_only=True,
                                    doc=VrfAttributes.__doc__)

        @vrf_attr.initter
        def vrf_attr(self):
            return SubAttributesDict(self.VrfAttributes, parent=self)

        @property
        def router_id(self):
            return self.vrf_attr[None].router_id

        @router_id.setter
        def router_id(self, value):
            self.vrf_attr[None].router_id = value

        @property
        def neighbor_attr(self):
            return self.vrf_attr[None].neighbor_attr

        @property
        def address_family_attr(self):
            return self.vrf_attr[None].address_family_attr

        class InterfaceAttributes(
                genie.conf.base.attributes.InterfaceSubAttributes):

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            class AddressFamilyAttributes(AddressFamilySubAttributes):

                allowed_keys = (AddressFamily.ipv4, AddressFamily.ipv6)

                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                         parent=self)

            def __init__(self, **kwargs):
                super().__init__(**kwargs)

        interface_attr = managedattribute(name='interface_attr',
                                          read_only=True,
                                          doc=InterfaceAttributes.__doc__)

        @interface_attr.initter
        def interface_attr(self):
            return SubAttributesDict(self.InterfaceAttributes, parent=self)

        def __init__(self, **kwargs):
            super().__init__(**kwargs)
Example #20
0
class Ldp(DeviceFeature, LinkFeature):
    @property
    def interfaces(self):
        interfaces = set()
        interfaces.update(*[link.interfaces for link in self.links])
        return frozenset(interfaces)

    @property
    def vrfs(self):
        return \
            self.force_vrfs | \
            {intf.vrf for intf in self.interfaces}

    force_vrfs = managedattribute(name='force_vrfs',
                                  read_only=True,
                                  finit=set,
                                  gettype=frozenset)

    # XXXJST TODO force_vrfs needs to also be accessible per-device. Being read_only, that can't happen

    def add_force_vrf(self, vrf):
        assert vrf is None or isinstance(vrf, Vrf)
        self.force_vrfs  # init!
        self._force_vrfs.add(vrf)

    def remove_force_vrf(self, vrf):
        assert vrf is None or isinstance(vrf, Vrf)
        self.force_vrfs  # init!
        self._force_vrfs.remove(vrf)

    address_families = managedattribute(
        name='address_families',
        finit=typedset(AddressFamily, {AddressFamily.ipv4}).copy,
        type=typedset(AddressFamily)._from_iterable)

    # Top level configs

    shutdown = managedattribute(name='shutdown',
                                default=None,
                                type=(None,
                                      managedattribute.test_istype(bool)))

    default_route = managedattribute(name='default_route',
                                     default=None,
                                     type=(None,
                                           managedattribute.test_istype(bool)))

    capabilities_cisco_iosxr = managedattribute(
        name='capabilities_cisco_iosxr',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    default_vrf_impl_ipv4 = managedattribute(
        name='default_vrf_impl_ipv4',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    ds_tlv = managedattribute(name='ds_tlv',
                              default=None,
                              type=(None, managedattribute.test_istype(bool)))

    hello_holdtime = managedattribute(name='hello_holdtime',
                                      default=None,
                                      type=(None,
                                            managedattribute.test_istype(int)))

    targetted_hello_holdtime = managedattribute(
        name='targetted_hello_holdtime',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    hello_interval = managedattribute(name='hello_interval',
                                      default=None,
                                      type=(None,
                                            managedattribute.test_istype(int)))

    targetted_hello_interval = managedattribute(
        name='targetted_hello_interval',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    instance_tlv = managedattribute(name='instance_tlv',
                                    default=None,
                                    type=(None,
                                          managedattribute.test_istype(bool)))

    quickstart = managedattribute(name='quickstart',
                                  default=None,
                                  type=(None,
                                        managedattribute.test_istype(bool)))

    targeted_hello_holdtime = managedattribute(
        name='targeted_hello_holdtime',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    targeted_hello_interval = managedattribute(
        name='targeted_hello_interval',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    entropy_label = managedattribute(name='entropy_label',
                                     default=None,
                                     type=(None,
                                           managedattribute.test_istype(bool)))

    gr = managedattribute(name='gr',
                          default=None,
                          type=(None, managedattribute.test_istype(bool)))

    gr_fwdstate_holdtime = managedattribute(
        name='gr_fwdstate_holdtime',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    gr_max_recovery = managedattribute(
        name='gr_max_recovery',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    gr_neighbor_liveness = managedattribute(
        name='gr_neighbor_liveness',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    gr_reconnect_timeout = managedattribute(
        name='gr_reconnect_timeout',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    igp_sync = managedattribute(name='igp_sync',
                                default=None,
                                type=(None,
                                      managedattribute.test_istype(bool)))

    igp_sync_delay_time = managedattribute(
        name='igp_sync_delay_time',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    igp_sync_delay_on_proc_restart = managedattribute(
        name='igp_sync_delay_on_proc_restart',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    igp_sync_delay_on_session_up = managedattribute(
        name='igp_sync_delay_on_session_up',
        default=None,
        type=(None, managedattribute.test_istype(int),
              managedattribute.test_in((False, ))))

    log_gr = managedattribute(name='log_gr',
                              default=None,
                              type=(None, managedattribute.test_istype(bool)))

    log_hello_adj = managedattribute(name='log_hello_adj',
                                     default=None,
                                     type=(None,
                                           managedattribute.test_istype(bool)))

    log_neighbor = managedattribute(name='log_neighbor',
                                    default=None,
                                    type=(None,
                                          managedattribute.test_istype(bool)))

    log_nsr = managedattribute(name='log_nsr',
                               default=None,
                               type=(None, managedattribute.test_istype(bool)))

    log_sess_prot = managedattribute(name='log_sess_prot',
                                     default=None,
                                     type=(None,
                                           managedattribute.test_istype(bool)))

    ltrace_buffer_multiplier = managedattribute(
        name='ltrace_buffer_multiplier',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    dualstack_tlv_compliance = managedattribute(
        name='dualstack_tlv_compliance',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    dualstack_transport_max_wait = managedattribute(
        name='dualstack_transport_max_wait',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    dualstack_transport_prefer_ipv4 = managedattribute(
        name='dualstack_transport_prefer_ipv4',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    password_type = managedattribute(name='password_type',
                                     default=None,
                                     type=(None, PasswordType))

    password = managedattribute(name='password',
                                default=None,
                                type=(None, managedattribute.test_istype(str)))

    password_for_acl = managedattribute(
        name='password_for_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    disable_password = managedattribute(
        name='disable_password',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    nsr = managedattribute(name='nsr',
                           default=None,
                           type=(None, managedattribute.test_istype(bool)))

    session_backoff_init = managedattribute(
        name='session_backoff_init',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    session_backoff_max = managedattribute(
        name='session_backoff_max',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    session_holdtime = managedattribute(
        name='session_holdtime',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    session_protection = managedattribute(
        name='session_protection',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    session_protection_for_acl = managedattribute(
        name='session_protection_for_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    session_protection_dur = managedattribute(
        name='session_protection_dur',
        default=None,
        type=(None, managedattribute.test_istype(int),
              managedattribute.test_in((float('inf'), ))))

    signalling_dscp = managedattribute(
        name='signalling_dscp',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    session_dod_with_acl = managedattribute(
        name='session_dod_with_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    gr_maintain_acl = managedattribute(
        name='gr_maintain_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    disc_hello_dualstack_tlv = managedattribute(
        name='disc_hello_dualstack_tlv',
        default=None,
        type=(None,
              managedattribute.test_in((
                  AddressFamily.ipv4,
                  AddressFamily.ipv6,
              ))))

    igp_autoconfig = managedattribute(
        name='igp_autoconfig',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    transport_address = managedattribute(name='transport_address',
                                         default=None,
                                         type=(None,
                                               managedattribute.test_in(
                                                   ('interface', )),
                                               IPv4Address, IPv6Address))

    targeted = managedattribute(name='targeted',
                                default=None,
                                type=(None,
                                      managedattribute.test_istype(bool)))

    advertise = managedattribute(name='advertise',
                                 default=None,
                                 type=(None,
                                       managedattribute.test_istype(bool)))

    advertise_expnull = managedattribute(
        name='advertise_expnull',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    advertise_expnull_for_acl = managedattribute(
        name='advertise_expnull_for_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    advertise_expnull_to_acl = managedattribute(
        name='advertise_expnull_to_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    advertise_interfaces = managedattribute(
        name='advertise_interfaces',
        finit=typedset(managedattribute.test_isinstance(Interface)).copy,
        type=typedset(
            managedattribute.test_isinstance(Interface))._from_iterable)

    allocate_for_acl = managedattribute(
        name='allocate_for_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    allocate_for_host_routes = managedattribute(
        name='allocate_for_host_routes',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    default_route = managedattribute(name='default_route',
                                     default=None,
                                     type=(None,
                                           managedattribute.test_istype(bool)))

    impnull_override_for_acl = managedattribute(
        name='impnull_override_for_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    targeted_hello_accept = managedattribute(
        name='targeted_hello_accept',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    targeted_hello_accept_from_acl = managedattribute(
        name='targeted_hello_accept_from_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    redist_bgp = managedattribute(name='redist_bgp',
                                  default=None,
                                  type=(None,
                                        managedattribute.test_istype(bool)))

    redist_bgp_advto_acl = managedattribute(
        name='redist_bgp_advto_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    redist_bgp_as = managedattribute(name='redist_bgp_as',
                                     default=None,
                                     type=(None,
                                           managedattribute.test_istype(int)))

    te_autotunnel_mesh_group_id = managedattribute(
        name='te_autotunnel_mesh_group_id',
        default=None,
        type=(None, managedattribute.test_in(
            ('all', )), managedattribute.test_istype(int)))

    advertise_for_acl = managedattribute(
        name='advertise_for_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    advertise_to_acl = managedattribute(
        name='advertise_to_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    accept_for_acl = managedattribute(
        name='accept_for_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    session_dod_acl = managedattribute(
        name='session_dod_acl',
        default=None,
        type=(None, managedattribute.test_isinstance(AccessList)))

    class MldpAttributes(object):

        enabled = managedattribute(name='enabled',
                                   default=False,
                                   type=managedattribute.test_istype(bool))

        csc = managedattribute(name='csc',
                               default=None,
                               type=(None, managedattribute.test_istype(bool)))

        forwarding_recursive = managedattribute(
            name='forwarding_recursive',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

        forwarding_recursive_route_policy = managedattribute(
            name='forwarding_recursive_route_policy',
            default=None,
            type=(None, managedattribute.test_isinstance(RoutePolicy)))

        make_before_break = managedattribute(
            name='make_before_break',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

        make_before_break_delay = managedattribute(
            name='make_before_break_delay',
            default=None,
            type=(None, managedattribute.test_istype(int)))

        make_before_break_delete_delay = managedattribute(
            name='make_before_break_delete_delay',
            default=None,
            type=(None, managedattribute.test_istype(int)))

        make_before_break_route_policy = managedattribute(
            name='make_before_break_route_policy',
            default=None,
            type=(None, managedattribute.test_istype(int)))

        mofrr = managedattribute(name='mofrr',
                                 default=None,
                                 type=(None,
                                       managedattribute.test_istype(bool)))

        mofrr_route_policy = managedattribute(
            name='mofrr_route_policy',
            default=None,
            type=(None, managedattribute.test_isinstance(RoutePolicy)))

        route_policy_in = managedattribute(
            name='route_policy_in',
            default=None,
            type=(None, managedattribute.test_isinstance(RoutePolicy)))

        recursive_fec = managedattribute(
            name='recursive_fec',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

        recorsive_fec_route_policy = managedattribute(
            name='recorsive_fec_route_policy',
            default=None,
            type=(None, managedattribute.test_isinstance(RoutePolicy)))

        rib_unicast_always = managedattribute(
            name='rib_unicast_always',
            default=None,
            type=(None, managedattribute.test_istype(int)))

        # TODO need support for multiple root_ip/num_lsps
        mp2mp_static_root_ip = managedattribute(name='mp2mp_static_root_ip',
                                                default=None,
                                                type=(None, IPv4Address))

        mp2mp_static_num_lsps = managedattribute(
            name='mp2mp_static_num_lsps',
            default=None,
            type=(None, managedattribute.test_istype(int)))

        p2mp_static_root_ip = managedattribute(name='p2mp_static_root_ip',
                                               default=None,
                                               type=(None, IPv4Address))

        p2mp_static_num_lsps = managedattribute(
            name='p2mp_static_num_lsps',
            default=None,
            type=(None, managedattribute.test_istype(int)))

        log_internal = managedattribute(
            name='log_internal',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

        log_notifications = managedattribute(
            name='log_notifications',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

    mldp = managedattribute(name='mldp',
                            read_only=True,
                            finit=MldpAttributes,
                            doc=MldpAttributes.__doc__)

    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):

        enabled_feature = managedattribute(
            name='enabled_feature',
            default=False,
            type=managedattribute.test_istype(bool),
            doc='''Argument to control 'feature ldp' CLI''')

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @address_families.defaulter
        def address_families(self):
            return frozenset(self.parent.address_families)

        advertise_interfaces = managedattribute(
            name='advertise_interfaces',
            type=typedset(
                managedattribute.test_isinstance(Interface))._from_iterable)

        @advertise_interfaces.defaulter
        def advertise_interfaces(self):
            device = self.device
            return frozenset(interface
                             for interface in self.parent.advertise_interfaces
                             if interface.device is device)

        @property
        def vrfs(self):
            return \
                self.force_vrfs | \
                {intf.vrf for intf in self.interfaces}

        @property
        def interfaces(self):
            device = self.device
            interfaces = set(self.parent.interfaces)
            #interfaces.update(*[link.interfaces for link in self.parent.links])
            interfaces = {intf for intf in interfaces if intf.device is device}
            return frozenset(interfaces)

        class MldpAttributes(SubAttributes):
            def __init__(self, _device_attr):
                self._device_attr = _device_attr
                super().__init__(
                    # Ldp.mldp
                    parent=_device_attr.parent.mldp)

            @property
            def testbed(self):
                return self._device_attr.testbed

            @property
            def device_name(self):
                return self._device_attr.device_name

            @property
            def device(self):
                return self._device_attr.device

        mldp = managedattribute(name='mldp',
                                read_only=True,
                                doc=MldpAttributes.__doc__)

        @mldp.initter
        def mldp(self):
            return self.MldpAttributes(_device_attr=self)

        class VrfAttributes(VrfSubAttributes):

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            advertise_interfaces = managedattribute(
                name='advertise_interfaces',
                type=typedset(managedattribute.test_isinstance(
                    Interface))._from_iterable)

            @advertise_interfaces.defaulter
            def advertise_interfaces(self):
                return frozenset(self.parent.advertise_interfaces)

            # implicit: interface_attr = parent.interface_attr
            # implicit: interfaces = parent.interfaces

            router_id = managedattribute(
                name='router_id',
                default=None,
                type=(None, IPv4Address,\
                      managedattribute.test_isinstance(Interface)))

            class NeighborAttributes(IPLsrNeighborSubAttributes):
                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            neighbor_attr = managedattribute(name='neighbor_attr',
                                             read_only=True,
                                             doc=NeighborAttributes.__doc__)

            @neighbor_attr.initter
            def neighbor_attr(self):
                return SubAttributesDict(self.NeighborAttributes, parent=self)

            neighbors = managedattribute(
                name='neighbors',
                finit=typedset(_ldp_neighbor).copy,
                type=typedset(_ldp_neighbor)._from_iterable)

            class AddressFamilyAttributes(AddressFamilySubAttributes):

                allowed_keys = (AddressFamily.ipv4, AddressFamily.ipv6)

                advertise_interfaces = managedattribute(
                    name='advertise_interfaces',
                    type=typedset(managedattribute.test_isinstance(
                        Interface))._from_iterable)

                @advertise_interfaces.defaulter
                def advertise_interfaces(self):
                    return frozenset(self.parent.advertise_interfaces)

                class NeighborAttributes(IPLsrNeighborSubAttributes):
                    def __init__(self, **kwargs):
                        super().__init__(**kwargs)

                neighbor_attr = managedattribute(
                    name='neighbor_attr',
                    read_only=True,
                    doc=NeighborAttributes.__doc__)

                @neighbor_attr.initter
                def neighbor_attr(self):
                    return SubAttributesDict(self.NeighborAttributes,
                                             parent=self)

                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                         parent=self)

            def __init__(self, **kwargs):
                super().__init__(**kwargs)

        vrf_attr = managedattribute(name='vrf_attr',
                                    read_only=True,
                                    doc=VrfAttributes.__doc__)

        @vrf_attr.initter
        def vrf_attr(self):
            return SubAttributesDict(self.VrfAttributes, parent=self)

        @property
        def router_id(self):
            return self.vrf_attr[None].router_id

        @router_id.setter
        def router_id(self, value):
            self.vrf_attr[None].router_id = value

        @property
        def neighbor_attr(self):
            return self.vrf_attr[None].neighbor_attr

        @property
        def address_family_attr(self):
            return self.vrf_attr[None].address_family_attr

        class InterfaceAttributes(
                genie.conf.base.attributes.InterfaceSubAttributes):

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            class AddressFamilyAttributes(AddressFamilySubAttributes):

                allowed_keys = (AddressFamily.ipv4, AddressFamily.ipv6)

                def __init__(self, **kwargs):
                    super().__init__(**kwargs)

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                         parent=self)

            def __init__(self, **kwargs):
                super().__init__(**kwargs)

        interface_attr = managedattribute(name='interface_attr',
                                          read_only=True,
                                          doc=InterfaceAttributes.__doc__)

        @interface_attr.initter
        def interface_attr(self):
            return SubAttributesDict(self.InterfaceAttributes, parent=self)

        def __init__(self, **kwargs):
            super().__init__(**kwargs)

    device_attr = managedattribute(name='device_attr',
                                   read_only=True,
                                   doc=DeviceAttributes.__doc__)

    @device_attr.initter
    def device_attr(self):
        return SubAttributesDict(self.DeviceAttributes, parent=self)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def build_config(self, links=None, apply=True, attributes=None, **kwargs):
        attributes = AttributesHelper(self, attributes)

        cfgs = {}

        if links is None:
            devices = self.devices
        else:
            devices = set().union(*[link.devices for link in links])

        for key, sub, attributes2 in attributes.mapping_items('device_attr',
                                                              keys=devices,
                                                              sort=True):
            cfgs[key] = sub.build_config(apply=False, attributes=attributes2)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs

    def build_unconfig(self,
                       links=None,
                       apply=True,
                       attributes=None,
                       **kwargs):
        attributes = AttributesHelper(self, attributes)

        cfgs = {}

        if links is None:
            devices = self.devices
        else:
            devices = set().union(*[link.devices for link in links])

        for key, sub, attributes2 in attributes.mapping_items('device_attr',
                                                              keys=devices,
                                                              sort=True):
            cfgs[key] = sub.build_unconfig(apply=False, attributes=attributes2)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs
Example #21
0
 def vnis(self):
     from genie.libs.conf.evpn import Vni
     return typedset(managedattribute.test_isinstance(Vni))
Example #22
0
class Vrf(DeviceFeature):

    vnis = managedattribute(
        name='vnis',
        #finit=typedset(managedattribute.test_isinstance(Evi)).copy,  # circular dependency!
        #type=typedset(managedattribute.test_isinstance(Evi))._from_iterable)  # circular dependency!
        doc='A `set` of Evi associated objects')

    @vnis.initter
    def vnis(self):
        from genie.libs.conf.evpn import Vni
        return typedset(managedattribute.test_isinstance(Vni))

    @vnis.setter
    def vnis(self, value):
        from genie.libs.conf.evpn import Vni
        self._vnis = typedset(managedattribute.test_isinstance(Vni), value)

    @property
    def interfaces(self):
        return frozenset([
            interface for interface in self.testbed.interfaces
            if interface.vrf is self
        ])

    name = managedattribute(name='name', read_only=True)  # read-only hash key

    description = managedattribute(name='description',
                                   default=None,
                                   type=(None,
                                         managedattribute.test_istype(str)))

    amt_flush_routes = managedattribute(
        name='amt_flush_routes',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    amt_pseudo_interface = managedattribute(
        name='amt_pseudo_interface',
        default=None,
        type=(None, managedattribute.test_isinstance(Interface)))

    fallback_vrf = managedattribute(
        name='fallback_vrf',
        default=None,
        # Self-reference; Done after: type=(None, managedattribute.test_isinstance(Vrf))
    )

    mhost_ipv4_default_interface = managedattribute(
        name='mhost_ipv4_default_interface',
        default=None,
        type=(None, managedattribute.test_isinstance(Interface)))

    mhost_ipv6_default_interface = managedattribute(
        name='mhost_ipv6_default_interface',
        default=None,
        type=(None, managedattribute.test_isinstance(Interface)))

    scale_mode = managedattribute(name='scale_mode',
                                  default=None,
                                  type=(None,
                                        managedattribute.test_in(('big', ))))

    remote_route_filtering = managedattribute(
        name='remote_route_filtering',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    vpn_id = managedattribute(name='vpn_id',
                              default=None,
                              type=(None,
                                    managedattribute.test_isinstance(VpnId)))

    rd = managedattribute(name='rd',
                          default=None,
                          type=(None, RouteDistinguisher,
                                managedattribute.test_in(('auto', ))))

    address_families = managedattribute(
        name='address_families',
        finit=typedset(AddressFamily, {AddressFamily.ipv4_unicast}).copy,
        type=typedset(AddressFamily)._from_iterable)

    export_route_policy = managedattribute(
        name='export_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(RoutePolicy)))

    export_route_targets = managedattribute(
        name='export_route_targets',
        finit=typedset(RouteTarget.ImportExport).copy,
        type=typedset(RouteTarget.ImportExport)._from_iterable)

    export_to_default_vrf_route_policy = managedattribute(
        name='export_to_default_vrf_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(RoutePolicy)))

    export_to_vrf_allow_imported_vpn = managedattribute(
        name='export_to_vrf_allow_imported_vpn',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    export_to_vrf_import_stitching_rt = managedattribute(
        name='export_to_vrf_import_stitching_rt',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    import_from_default_vrf_route_policy = managedattribute(
        name='import_from_default_vrf_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(RoutePolicy)))

    import_from_default_vrf_route_policy_maximum_prefixes = managedattribute(
        name='import_from_default_vrf_route_policy_maximum_prefixes',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    import_from_default_vrf_advertise_as_vpn = managedattribute(
        name='import_from_default_vrf_advertise_as_vpn',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    import_route_policy = managedattribute(
        name='import_route_policy',
        default=None,
        type=(None, managedattribute.test_istype(RoutePolicy)))

    import_route_targets = managedattribute(
        name='import_route_targets',
        finit=typedset(RouteTarget.ImportExport).copy,
        type=typedset(RouteTarget.ImportExport)._from_iterable)

    maximum_prefix = managedattribute(name='maximum_prefix',
                                      default=None,
                                      type=(None,
                                            managedattribute.test_istype(int)))

    maximum_prefix_threshold = managedattribute(
        name='maximum_prefix_threshold',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    maximum_prefix_reinstall_threshold = managedattribute(
        name='maximum_prefix_reinstall_threshold',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    maximum_prefix_warning_only = managedattribute(
        name='maximum_prefix_warning_only',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    shutdown = managedattribute(name='shutdown',
                                default=None,
                                type=(None,
                                      managedattribute.test_istype(bool)))

    import_from_global_map = managedattribute(
        name='import_from_global_map',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    export_to_global_map = managedattribute(
        name='export_to_global_map',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    routing_table_limit_number = managedattribute(
        name='routing_table_limit_number',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    alert_percent_value = managedattribute(
        name='alert_percent_value',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    simple_alert = managedattribute(name='simple_alert ',
                                    default=None,
                                    type=(None,
                                          managedattribute.test_istype(bool)))

    class RTTYPE(Enum):
        type1 = 'import'
        type2 = 'export'
        type3 = 'both'

    rt_type = managedattribute(name='rt_type',
                               default=None,
                               type=(None, RTTYPE),
                               doc='import export or both')

    vni = managedattribute(name='vni',
                           default=None,
                           type=(None, managedattribute.test_istype(int)))

    class DeviceAttributes(DeviceSubAttributes):
        @property
        def vnis(self):
            device = self.device
            return frozenset(
                [vni for vni in self.parent.vnis if vni.device is device])

        @property
        def interfaces(self):
            device = self.device
            return frozenset([
                interface for interface in self.parent.interfaces
                if interface.device is device
            ])

        export_route_targets = managedattribute(
            name='export_route_targets',
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        @export_route_targets.defaulter
        def export_route_targets(self):
            return frozenset(self.parent.export_route_targets)

        import_route_targets = managedattribute(
            name='import_route_targets',
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        @import_route_targets.defaulter
        def import_route_targets(self):
            return frozenset(self.parent.import_route_targets)

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @address_families.defaulter
        def address_families(self):
            return frozenset(self.parent.address_families)

        class AddressFamilyAttributes(AddressFamilySubAttributes):
            class RouteTargetAttributes(KeyedSubAttributes):
                def __init__(self, parent, key):
                    self.rt = key
                    super().__init__(parent)

            route_target_attr = managedattribute(
                name='route_target_attr',
                read_only=True,
                doc=RouteTargetAttributes.__doc__)

            @route_target_attr.initter
            def route_target_attr(self):
                return SubAttributesDict(self.RouteTargetAttributes,
                                         parent=self)

        def __init__(self, *args, **kwargs):
            self.address_family_attr = SubAttributesDict(
                self.AddressFamilyAttributes, parent=self)
            super().__init__(*args, **kwargs)

    device_attr = managedattribute(name='device_attr',
                                   read_only=True,
                                   doc=DeviceAttributes.__doc__)

    @device_attr.initter
    def device_attr(self):
        return SubAttributesDict(self.DeviceAttributes, parent=self)

    def __init__(self, name, *args, **kwargs):
        assert isinstance(name, str)
        self._name = name
        super().__init__(*args, **kwargs)

    def __eq__(self, other):
        if not isinstance(other, Vrf):
            return NotImplemented
        return (self.name, self.testbed) \
            == (other.name, other.testbed)

    def __lt__(self, other):
        if not isinstance(other, Vrf):
            return NotImplemented
        return (self.name, self.testbed) \
            < (other.name, other.testbed)

    def __hash__(self):
        return hash(self.name)

    def build_config(self,
                     devices=None,
                     apply=True,
                     attributes=None,
                     **kwargs):
        cfgs = {}
        assert not kwargs, kwargs
        attributes = AttributesHelper(self, attributes)

        if devices is None:
            devices = self.devices
        devices = set(devices)

        for key, sub, attributes2 in attributes.mapping_items('device_attr',
                                                              keys=devices,
                                                              sort=True):
            cfgs[key] = sub.build_config(apply=False, attributes=attributes2)

        cfgs = {key: value for key, value in cfgs.items() if value}
        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs

    def build_unconfig(self,
                       devices=None,
                       apply=True,
                       attributes=None,
                       **kwargs):
        cfgs = {}
        assert not kwargs, kwargs
        attributes = AttributesHelper(self, attributes)

        if devices is None:
            devices = self.devices
        devices = set(devices)

        for key, sub, attributes2 in attributes.mapping_items('device_attr',
                                                              keys=devices,
                                                              sort=True):
            cfgs[key] = sub.build_unconfig(apply=False, attributes=attributes2)

        cfgs = {key: value for key, value in cfgs.items() if value}
        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs
Example #23
0
            class AddressFamilyAttributes(AddressFamilySubAttributes):
                def __init__(self, parent, key):
                    super().__init__(parent, key)

                # summary-address multi-line configs
                sumadd_keys = managedattribute(
                    name='sumadd_keys',
                    finit=OrderedSet,
                    type=OrderedSet()._from_iterable,
                    doc='A `set` of SummaryAddress keys objects')

                def add_sumadd_key(self, sumadd_key):
                    self.sumadd_keys.add(sumadd_key)

                def remove_sumadd_key(self, sumadd_key):
                    sumadd_key._device = None
                    try:
                        self.sumadd_keys.remove(sumadd_key)
                    except:
                        pass

                # Area Range multi-line configs
                arearange_keys = managedattribute(
                    name='arearange_keys',
                    finit=typedset(
                        managedattribute.test_isinstance(AreaRange)).copy,
                    type=typedset(managedattribute.test_isinstance(
                        AreaRange))._from_iterable,
                    doc='A `set` of AreaRange keys objects')

                def add_arearange_key(self, arearange_key):
                    self.arearange_keys.add(arearange_key)

                def remove_arearange_key(self, arearange_key):
                    arearange_key._device = None
                    try:
                        self.arearange_keys.remove(arearange_key)
                    except:
                        pass

                # Area route map multi-line configs
                arearoutemap_keys = managedattribute(
                    name='arearoutemap_keys',
                    finit=typedset(
                        managedattribute.test_isinstance(AreaRouteMap)).copy,
                    type=typedset(
                        managedattribute.test_isinstance(
                            AreaRouteMap))._from_iterable,
                    doc='A `set` of AreaRouteMap keys objects')

                def add_arearoutemap_key(self, arearoutemap_key):
                    self.arearoutemap_keys.add(arearoutemap_key)

                def remove_arearoutemap_key(self, arearoutemap_key):
                    arearoutemap_key._device = None
                    try:
                        self.arearoutemap_keys.remove(arearoutemap_key)
                    except:
                        pass

                # Area default cost multi-line configs
                areacost_keys = managedattribute(
                    name='areacost_keys',
                    finit=typedset(
                        managedattribute.test_isinstance(
                            AreaDefaultCost)).copy,
                    type=typedset(
                        managedattribute.test_isinstance(
                            AreaDefaultCost))._from_iterable,
                    doc='A `set` of AreaDefaultCost keys objects')

                def add_areacost_key(self, areacost_key):
                    self.areacost_keys.add(areacost_key)

                def remove_arearoutemap_key(self, areacost_key):
                    areacost_key._device = None
                    try:
                        self.areacost_keys.remove(areacost_key)
                    except:
                        pass
Example #24
0
        class VrfAttributes(VrfSubAttributes):

            rd = Vrf.rd.copy()

            @rd.defaulter
            def rd(self):
                vrf = self.vrf
                return vrf and vrf.rd

            address_families = managedattribute(
                name='address_families',
                finit=typedset(AddressFamily).copy,
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return self.parent.address_families.copy()

            class AddressFamilyAttributes(AddressFamilySubAttributes):
                pass

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilySubAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                        parent=self)

            class NeighborAttributes(IPNeighborSubAttributes):

                address_families = managedattribute(
                    name='address_families',
                    finit=typedset(AddressFamily).copy,
                    type=typedset(AddressFamily)._from_iterable)

                @address_families.defaulter
                def address_families(self):
                    return self.parent.address_families.copy()

                class AddressFamilyAttributes(AddressFamilySubAttributes):
                    pass

                address_family_attr = managedattribute(
                    name='address_family_attr',
                    read_only=True,
                    doc=AddressFamilySubAttributes.__doc__)

                @address_family_attr.initter
                def address_family_attr(self):
                    return SubAttributesDict(self.AddressFamilyAttributes,
                                             parent=self)


            neighbor_attr = managedattribute(
                name='neighbor_attr',
                read_only=True,
                doc=NeighborAttributes.__doc__)

            @neighbor_attr.initter
            def neighbor_attr(self):
                return SubAttributesDict(self.NeighborAttributes, parent=self)

            router_id = managedattribute(
                name='router_id',
                default=None,
                type=(None, IPv4Address))

            neighbors = managedattribute(
                name='neighbors',
                finit=set,
                type=managedattribute.test_set_of(IPNeighbor),
                gettype=frozenset)

            neighbors = managedattribute(
                name='neighbors',
                finit=typedset(IPNeighbor).copy,
                type=typedset(IPNeighbor)._from_iterable)

            def add_neighbor(self, neighbor):  # TODO DEPRECATE
                self.neighbors.add(neighbor)

            def remove_neighbor(self, neighbor):  # TODO DEPRECATE
                self.neighbors.remove(neighbor)
Example #25
0
    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):

        update_source = managedattribute(
            name='update_source',
            default=None,
            type=(None, managedattribute.test_isinstance(Interface)))

        vrfs = managedattribute(
            name='vrfs',
            finit=typedset(managedattribute.test_isinstance((
                type(None), Vrf)), {None}).copy,
            type=typedset(managedattribute.test_isinstance((
                type(None), Vrf)))._from_iterable)

        def add_vrf(self, vrf):  # TODO DEPRECATE
            self.vrfs.add(vrf)

        def remove_vrf(self, vrf):  # TODO DEPRECATE
            self.vrfs.remove(vrf)

        @property
        def router_id(self):
            return self.vrf_attr[None].router_id

        @router_id.setter
        def router_id(self, value):
            self.vrf_attr[None].router_id = value

        class PeerSessionAttributes(KeyedSubAttributes):
            def __init__(self, parent, key):
                self.ps_name = key
                super().__init__(parent)

        peer_session_attr = managedattribute(
            name='peer_session_attr',
            read_only=True,
            doc=PeerSessionAttributes.__doc__)

        @peer_session_attr.initter
        def peer_session_attr(self):
            return SubAttributesDict(self.PeerSessionAttributes, parent=self)

        class PeerPolicyAttributes(KeyedSubAttributes):
            def __init__(self, parent, key):
                self.pp_name = key
                super().__init__(parent)

        peer_policy_attr = managedattribute(
            name='peer_policy_attr',
            read_only=True,
            doc=PeerPolicyAttributes.__doc__)

        @peer_policy_attr.initter
        def peer_policy_attr(self):
            return SubAttributesDict(self.PeerPolicyAttributes, parent=self)

        class VrfAttributes(VrfSubAttributes):

            rd = Vrf.rd.copy()

            @rd.defaulter
            def rd(self):
                vrf = self.vrf
                return vrf and vrf.rd

            address_families = managedattribute(
                name='address_families',
                finit=typedset(AddressFamily).copy,
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return self.parent.address_families.copy()

            class AddressFamilyAttributes(AddressFamilySubAttributes):
                pass

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilySubAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                        parent=self)

            class NeighborAttributes(IPNeighborSubAttributes):

                address_families = managedattribute(
                    name='address_families',
                    finit=typedset(AddressFamily).copy,
                    type=typedset(AddressFamily)._from_iterable)

                @address_families.defaulter
                def address_families(self):
                    return self.parent.address_families.copy()

                class AddressFamilyAttributes(AddressFamilySubAttributes):
                    pass

                address_family_attr = managedattribute(
                    name='address_family_attr',
                    read_only=True,
                    doc=AddressFamilySubAttributes.__doc__)

                @address_family_attr.initter
                def address_family_attr(self):
                    return SubAttributesDict(self.AddressFamilyAttributes,
                                             parent=self)


            neighbor_attr = managedattribute(
                name='neighbor_attr',
                read_only=True,
                doc=NeighborAttributes.__doc__)

            @neighbor_attr.initter
            def neighbor_attr(self):
                return SubAttributesDict(self.NeighborAttributes, parent=self)

            router_id = managedattribute(
                name='router_id',
                default=None,
                type=(None, IPv4Address))

            neighbors = managedattribute(
                name='neighbors',
                finit=set,
                type=managedattribute.test_set_of(IPNeighbor),
                gettype=frozenset)

            neighbors = managedattribute(
                name='neighbors',
                finit=typedset(IPNeighbor).copy,
                type=typedset(IPNeighbor)._from_iterable)

            def add_neighbor(self, neighbor):  # TODO DEPRECATE
                self.neighbors.add(neighbor)

            def remove_neighbor(self, neighbor):  # TODO DEPRECATE
                self.neighbors.remove(neighbor)

        vrf_attr = managedattribute(
            name='vrf_attr',
            read_only=True,
            doc=VrfAttributes.__doc__)

        @vrf_attr.initter
        def vrf_attr(self):
            return SubAttributesDict(self.VrfAttributes, parent=self)

        @property
        def neighbors(self):
            return self.vrf_attr[None].neighbors

        @property
        def add_neighbor(self):
            return self.vrf_attr[None].add_neighbor

        @property
        def remove_neighbor(self):
            return self.vrf_attr[None].remove_neighbor

        @property
        def address_family_attr(self):
            return self.vrf_attr[None].address_family_attr

        @property
        def neighbor_attr(self):
            return self.vrf_attr[None].neighbor_attr

        def __init__(self, parent, key):
            super().__init__(parent, key)
Example #26
0
class Rip(Routing, DeviceFeature, LinkFeature, InterfaceFeature):
    """Rip class

    `Rip` inherits `Feature' class. The class defines all rip related
    information and functionalities.

    Args:


    Returns:
            a `Rip` object

    """

    # When adding a rip instance to a link, all the interfaces in this link
    # needs to be told about the rip object.
    # this syntax means : all interfaces
    register_name = {}
    register_name['interfaces'] = 'rip'

    instance_id = managedattribute(
        name='instance_id',
        read_only=True,  # mandatory
        doc='RIP Instance ID')

    shutdown = managedattribute(
        name='shutdown',
        default=None,
        type=(None, managedattribute.test_istype(bool)))

    address_families = managedattribute(
        name='address_families',
        finit=typedset(AddressFamily, {AddressFamily.ipv4_unicast}).copy,
        type=typedset(AddressFamily)._from_iterable)

    # AddressFamilyAttributes

    distance = managedattribute(
        name='distance',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    maximum_paths = managedattribute(
        name='maximum_paths',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    default_metric = managedattribute(
        name='default_metric',
        default=None,
        type=(None, managedattribute.test_istype(int)))

    redistribute_lisp_rmap = managedattribute(
        name='redistribute_lisp_rmap',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    redistribute_direct_rmap = managedattribute(
        name='redistribute_direct_rmap',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    redistribute_static_rmap = managedattribute(
        name='redistribute_static_rmap',
        default=None,
        type=(None, managedattribute.test_istype(str)))

    @property
    def vrfs(self):
        return \
            self.force_vrfs | \
            {intf.vrf for intf in self.interfaces}

    force_vrfs = managedattribute(
        name='force_vrfs',
        read_only=True,
        finit=set,
        gettype=frozenset)
    # XXXJST TODO force_vrfs needs to also be accessible per-device. Being read_only, that can't happen

    def add_force_vrf(self, vrf):
        assert vrf is None or isinstance(vrf, Vrf)
        self.force_vrfs  # init!
        self._force_vrfs.add(vrf)

    def remove_force_vrf(self, vrf):
        assert vrf is None or isinstance(vrf, Vrf)
        self.force_vrfs  # init!
        self._force_vrfs.remove(vrf)

    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):
        """DeviceAttributes class

        `DeviceAttributes` contains attributes and functionalities
        that are specific for a device.

        Args:
            kwargs (`dict`) : assign attributes to this object while
                              creating it.

        Returns:
            a `DeviceAttributes` object
        """

        enabled_feature = managedattribute(
            name='enabled_feature',
            default=False,
            type=managedattribute.test_istype(bool),
            doc='''Argument to control 'feature rip' CLI''')

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @address_families.defaulter
        def address_families(self):
            return frozenset(self.parent.address_families)

        @property
        def vrfs(self):
            return \
                self.force_vrfs | \
                {intf.vrf for intf in self.interfaces}

        def __init__(self, **kwargs):
            super().__init__(**kwargs)

        class VrfAttributes(VrfSubAttributes):
            """ VrfAttributes class

            `VrfAttributes` inherits from `SubAttributes' class.
             It contains all vrf related attributes and
             functionalities. Class contains some powers to access
             its parent attributes.

            Args:
                kwargs (`dict`) : gives the user ability to assign some or all
                                  address family attributes while creating the
                                  object.

            """

            def __init__(self, **kwargs):
                super().__init__(**kwargs)

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            class AddressFamilyAttributes(AddressFamilySubAttributes):
                """ AddressFamilyAttributes class

                `AddressFamilyAttributes` inherits from `SubAttributes' class.
                 It contains all address family related attributes and
                 functionalities. Class contains some powers to access
                 its parent attributes.

                Args:
                    kwargs (`dict`) : gives the user ability to assign some or all
                                      address family attributes while creating the
                                      object.

                Class variables:

                    allowed_keys (`List`): list of all allowed 'keys' the object can
                                      access.

                """

                allowed_keys = (
                    AddressFamily.ipv4_unicast,
                    AddressFamily.ipv6_unicast,
                )

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes, parent=self)

        vrf_attr = managedattribute(
            name='vrf_attr',
            read_only=True,
            doc=VrfAttributes.__doc__)

        @vrf_attr.initter
        def vrf_attr(self):
            return SubAttributesDict(self.VrfAttributes, parent=self)

    device_attr = managedattribute(
        name='device_attr',
        read_only=True,
        doc=DeviceAttributes.__doc__)

    @device_attr.initter
    def device_attr(self):
        return SubAttributesDict(self.DeviceAttributes, parent=self)

    def __init__(self, instance_id, **kwargs):
        '''Rip Base class'''
        self._instance_id = int(instance_id)
        super().__init__(**kwargs)

    def build_config(self, devices=None, apply=True, attributes=None, **kwargs):
        """method to build the configuration based on attributes

        Api to build the configuration of an Rip object.
        This configuration depends of the configurable attributes of
        this object.

        If Apply is set to True, then it will apply on the device(s)
        If it is set to False, then it will return a dictionary.

        If any kwargs are passed, then the configuration that is built
        will use those kwargs given, and not the object attributes. This
        is useful for modifying the configuration, without re-applying
        everything.


        Args:
            apply (`bool`): If True will apply the configuration on the device
                            and if False will return the configuration in a
                            dictionary
            kwargs (`dict`): If there is kwargs, then it will use those
                             attributes to configure the feature. Otherwise
                             will use the object attributes

        Return:
            `str`
        """
        attributes = AttributesHelper(self, attributes)

        # Get devices if none were passed
        if devices is None:
            devices = self.devices

        # For each device, loop over device_attr
        cfgs = {}
        for key, sub, attributes2 in attributes.mapping_items('device_attr', keys=devices):
            cfgs[key] = sub.build_config(apply=False, attributes=attributes2, **kwargs)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            # Return configuration
            return cfgs

    def build_unconfig(self, devices=None, apply=True, attributes=None, **kwargs):
        """method to build the unconfiguration based on attributes

        Api to build the unconfiguration of an Rip object.
        This configuration depends of the configurable attributes of
        this object.

        If Apply is set to True, then it will apply on the device(s)
        If it is set to False, then it will return a dictionary.

        If any kwargs are passed, then the configuration that is built
        will use those kwargs given, and not the object attributes. This
        is useful for modifying the configuration, without re-applying
        everything.


        Args:
            apply (`bool`): If True will apply the configuration on the device
                            and if False will return the configuration in a
                            dictionary
            kwargs (`dict`): If there is kwargs, then it will use those
                             attributes to configure the feature. Otherwise
                             will use the object attributes

        Return:
            `str`
        """
        attributes = AttributesHelper(self, attributes)

        # Get devices if none were passed
        if devices is None:
            devices = self.devices

        # For each device, loop over device_attr
        cfgs = {}
        for key, sub, attributes2 in attributes.mapping_items('device_attr', keys=devices):
            cfgs[key] = sub.build_unconfig(apply=False, attributes=attributes2, **kwargs)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            # Return configuration
            return cfgs
Example #27
0
    class AutodiscoveryBgpAttributes(ConfigurableVfiNamespace):

        enabled = managedattribute(
            name='enabled',
            default=False,
            type=managedattribute.test_istype(bool))

        control_word = managedattribute(
            name='control_word',
            default=None,
            type=(None, managedattribute.test_istype(bool)))

        rd = managedattribute(
            name='rd',
            default=None,
            type=(None, RouteDistinguisher,
                  managedattribute.test_in((
                      'auto',
                  ))))

        export_route_policy = managedattribute(
            name='export_route_policy',
            default=None,
            type=(None, managedattribute.test_istype(str)))

        export_route_targets = managedattribute(
            name='export_route_targets',
            finit=typedset(RouteTarget.ImportExport).copy,
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        import_route_targets = managedattribute(
            name='import_route_targets',
            finit=typedset(RouteTarget.ImportExport).copy,
            type=typedset(RouteTarget.ImportExport)._from_iterable)

        table_policy = managedattribute(
            name='table_policy',
            default=None,
            type=(None, managedattribute.test_istype(str)))

        class SignalingProtocolBgpAttributes(ConfigurableVfiNamespace):

            enabled = managedattribute(
                name='enabled',
                default=False,
                type=managedattribute.test_istype(bool))

            ve_id = managedattribute(
                name='ve_id',
                default=None,
                type=(None, managedattribute.test_istype(int)))

            ve_range = managedattribute(
                name='ve_range',
                default=None,
                type=(None,
                      managedattribute.test_istype(int),
                      managedattribute.test_istype(str)))

        signaling_protocol_bgp = managedattribute(
            name='signaling_protocol_bgp',
            read_only=True,
            doc=SignalingProtocolBgpAttributes.__doc__)

        @signaling_protocol_bgp.initter
        def signaling_protocol_bgp(self):
            return self.SignalingProtocolBgpAttributes(vfi=self.vfi)

        class SignalingProtocolLdpAttributes(ConfigurableVfiNamespace):

            enabled = managedattribute(
                name='enabled',
                default=False,
                type=managedattribute.test_istype(bool))

            vpls_id = managedattribute(
                name='vpls_id',
                default=None,
                type=(None, RouteTarget))

        signaling_protocol_ldp = managedattribute(
            name='signaling_protocol_ldp',
            read_only=True,
            doc=SignalingProtocolLdpAttributes.__doc__)

        @signaling_protocol_ldp.initter
        def signaling_protocol_ldp(self):
            return self.SignalingProtocolLdpAttributes(vfi=self.vfi)

        def __init__(self, vfi):
            super().__init__(vfi=vfi)
Example #28
0
    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):
        """DeviceAttributes class

        `DeviceAttributes` contains attributes and functionalities
        that are specific for a device.

        Args:
            kwargs (`dict`) : assign attributes to this object while
                              creating it.

        Returns:
            a `DeviceAttributes` object
        """

        enabled_feature = managedattribute(
            name='enabled_feature',
            default=False,
            type=managedattribute.test_istype(bool),
            doc='''Argument to control 'feature rip' CLI''')

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @address_families.defaulter
        def address_families(self):
            return frozenset(self.parent.address_families)

        @property
        def vrfs(self):
            return \
                self.force_vrfs | \
                {intf.vrf for intf in self.interfaces}

        def __init__(self, **kwargs):
            super().__init__(**kwargs)

        class VrfAttributes(VrfSubAttributes):
            """ VrfAttributes class

            `VrfAttributes` inherits from `SubAttributes' class.
             It contains all vrf related attributes and
             functionalities. Class contains some powers to access
             its parent attributes.

            Args:
                kwargs (`dict`) : gives the user ability to assign some or all
                                  address family attributes while creating the
                                  object.

            """

            def __init__(self, **kwargs):
                super().__init__(**kwargs)

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            class AddressFamilyAttributes(AddressFamilySubAttributes):
                """ AddressFamilyAttributes class

                `AddressFamilyAttributes` inherits from `SubAttributes' class.
                 It contains all address family related attributes and
                 functionalities. Class contains some powers to access
                 its parent attributes.

                Args:
                    kwargs (`dict`) : gives the user ability to assign some or all
                                      address family attributes while creating the
                                      object.

                Class variables:

                    allowed_keys (`List`): list of all allowed 'keys' the object can
                                      access.

                """

                allowed_keys = (
                    AddressFamily.ipv4_unicast,
                    AddressFamily.ipv6_unicast,
                )

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes, parent=self)

        vrf_attr = managedattribute(
            name='vrf_attr',
            read_only=True,
            doc=VrfAttributes.__doc__)

        @vrf_attr.initter
        def vrf_attr(self):
            return SubAttributesDict(self.VrfAttributes, parent=self)
Example #29
0
 def vnis(self, value):
     from genie.libs.conf.evpn import Vni
     self._vnis = typedset(managedattribute.test_isinstance(Vni), value)
Example #30
0
    class DeviceAttributes(genie.conf.base.attributes.DeviceSubAttributes):

        address_families = managedattribute(
            name='address_families',
            type=typedset(AddressFamily)._from_iterable)

        @property
        def vrfs(self):
            return \
                self.force_vrfs | \
                {intf.vrf for intf in self.interfaces}

        @address_families.defaulter
        def address_families(self):
            return frozenset(self.parent.address_families)

        class VrfAttributes(VrfSubAttributes):

            address_families = managedattribute(
                name='address_families',
                type=typedset(AddressFamily)._from_iterable)

            @address_families.defaulter
            def address_families(self):
                return frozenset(self.parent.address_families)

            class AddressFamilyAttributes(AddressFamilySubAttributes):

                rp_addresses = managedattribute(
                    name='rp_addresses',
                    finit=typedset(
                        managedattribute.test_isinstance(RPAddressGroup)).copy,
                    type=typedset(
                        managedattribute.test_isinstance(
                            RPAddressGroup))._from_iterable,
                    doc='A `set` of RPAddressGroup associated objects')

                def add_static_rp(self, rp_addresses):
                    self.rp_addresses.add(rp_addresses)

                def remove_static_rp(self, rp_addresses):
                    rp_addresses._device = None
                    try:
                        self.rp_addresses.remove(rp_addresses)
                    except:
                        pass

                class InterfaceAttributes(InterfaceSubAttributes):
                    pass

                interface_attr = managedattribute(
                    name='interface_attr',
                    read_only=True,
                    doc=InterfaceAttributes.__doc__)

                @interface_attr.initter
                def interface_attr(self):
                    return SubAttributesDict(self.InterfaceAttributes,
                                             parent=self)

            address_family_attr = managedattribute(
                name='address_family_attr',
                read_only=True,
                doc=AddressFamilyAttributes.__doc__)

            @address_family_attr.initter
            def address_family_attr(self):
                return SubAttributesDict(self.AddressFamilyAttributes,
                                         parent=self)

        vrf_attr = managedattribute(name='vrf_attr',
                                    read_only=True,
                                    doc=VrfAttributes.__doc__)

        @vrf_attr.initter
        def vrf_attr(self):
            return SubAttributesDict(self.VrfAttributes, parent=self)

        def __init__(self, parent, key):
            super().__init__(parent, key)