Exemple #1
0
    def build_config(self,
                     apply=True,
                     attributes=None,
                     unconfig=False,
                     **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder(unconfig=unconfig)
        interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()
        interface_configuration = interface_configurations.InterfaceConfiguration(
        )
        interface_configuration.active = "act"
        interface_configuration.interface_name = attributes.value('name')
        interface_configuration.interface_virtual = Empty()
        # name is a mandatory arguments
        #keep = string.digits
        #ydk_obj.name =  int(''.join(i for i in attributes.value('name') if i in keep))

        if unconfig and attributes.iswildcard:
            pass
        else:
            vrf = attributes.value('vrf')
            if vrf:
                interface_configuration.vrf = vrf.name

            ipv4 = attributes.value('ipv4')
            if ipv4:
                primary = interface_configuration.ipv4_network.addresses.Primary(
                )
                primary.address = str(ipv4.ip)
                primary.netmask = str(ipv4.netmask)
                interface_configuration.ipv4_network.addresses.primary = primary
        # instantiate crud service
        crud_service = CRUDService()
        if apply:

            # create netconf connection
            ncp = NetconfServiceProvider(self.device)

            if unconfig:
                crud_service.delete(ncp, interface_configuration)
            else:
                crud_service.create(ncp, interface_configuration)
        else:
            if unconfig:
                return YangConfig(device=self.device,
                                  unconfig=unconfig,
                                  ncp=NetconfServiceProvider,
                                  ydk_obj=interface_configuration,
                                  crud_service=crud_service.delete)
            else:
                return YangConfig(device=self.device,
                                  unconfig=unconfig,
                                  ncp=NetconfServiceProvider,
                                  ydk_obj=interface_configuration,
                                  crud_service=crud_service.create)
Exemple #2
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            assert not kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            vrfs = xr_infra_rsi_cfg.Vrfs()
            if not unconfig:
                vrf = vrfs.Vrf()
                if attributes.value('name'):
                    vrf.vrf_name = attributes.value('name')
                vrf.create = Empty()

                vrfs.vrf.append(vrf)
                #crud_service = CRUDService()
                #ncp = NetconfServiceProvider(self.device)
                #x = crud_service.read(ncp, vrf)
                #abc = YangConfig(device=self.device, ydk_obj=x, ncp=ncp, crud_service=crud_service)
                #print(abc)
                # iosxr: vrf vrf1 / address-family ipv4 unicast (config-vrf-af)
                for key, sub, attributes2 in attributes.mapping_items(
                        'address_family_attr',
                        keys=self.address_families,
                        sort=True):
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     vrf=vrf)

            # instantiate crud service
            crud_service = CRUDService()
            if apply:

                # create netconf connection
                ncp = NetconfServiceProvider(self.device)

                crud_service.create(ncp, vrfs)

                if unconfig:
                    crud_service.delete(ncp, vrfs)
            else:
                if unconfig:
                    return YangConfig(device=self.device,
                                      ydk_obj=vrfs,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.delete)
                else:
                    return YangConfig(device=self.device,
                                      ydk_obj=vrfs,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.create)
Exemple #3
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):

            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            ydk_obj = ned.Native.Router.Ospf()
            ospf_intfs = []
            for sub, attributes2 in attributes.mapping_values(
                    'vrf_attr', sort=VrfSubAttributes._sort_key):
                ospf_intfs.extend(
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     ydk_obj=ydk_obj,
                                     **kwargs))

            # instantiate crud service
            crud_service = CRUDService()
            if apply:

                # create netconf connection
                ncp = NetconfServiceProvider(self.device)

                if unconfig:
                    crud_service.delete(ncp, ydk_obj)
                else:
                    crud_service.create(ncp, ydk_obj)
                    for inter in ospf_intfs:
                        inter.apply()
            else:
                ydks = []

                if unconfig:
                    ydks.append(
                        YangConfig(device=self.device,
                                   ydk_obj=ydk_obj,
                                   ncp=NetconfServiceProvider,
                                   crud_service=crud_service.delete))
                else:
                    ydks.append(
                        YangConfig(device=self.device,
                                   ydk_obj=ydk_obj,
                                   ncp=NetconfServiceProvider,
                                   crud_service=crud_service.create))

                    for inter in ospf_intfs:
                        ydks.append(inter)
                return ydks
Exemple #4
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):

            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            ospf = xr_ipv4_ospf_cfg.Ospf()
            process = ospf.processes.Process()
            id = attributes.value('ospf_name', force=True)
            process.process_name = str(id)
            ospf.processes.process.append(process)
            if not unconfig:
                process.start = Empty()
                # crud_service = CRUDService()
                # ncp = NetconfServiceProvider(self.device)
                # x = crud_service.read(ncp, process)
                # abc = YangConfig(device=self.device, ydk_obj=x, ncp=ncp, crud_service=crud_service)
                # print(abc)
                v = attributes.value('nsr')
                if v == True:
                    process.nsr = "true"
                for sub, attributes2 in attributes.mapping_values(
                        'vrf_attr', sort=VrfSubAttributes._sort_key):
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     process=process,
                                     **kwargs)
            # instantiate crud service
            crud_service = CRUDService()
            if apply:

                # create netconf connection3
                ncp = NetconfServiceProvider(self.device)
                if unconfig:
                    crud_service.delete(ncp, process)
                else:
                    crud_service.create(ncp, process)
            else:
                if unconfig:
                    return YangConfig(device=self.device,
                                      ydk_obj=process,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.delete)
                else:
                    return YangConfig(device=self.device,
                                      ydk_obj=process,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.create)
Exemple #5
0
    def build_config(self,
                     apply=True,
                     attributes=None,
                     unconfig=False,
                     **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder(unconfig=unconfig)
        ydk_obj = ned.Native.Interface.Loopback()
        # name is a mandatory arguments
        keep = string.digits
        ydk_obj.name = int(''.join(i for i in attributes.value('name')
                                   if i in keep))

        if unconfig and attributes.iswildcard:
            pass
        else:
            ipv4 = attributes.value('ipv4')
            if ipv4:
                ydk_obj.ip.address.primary.address = str(ipv4.ip)
                ydk_obj.ip.address.primary.mask = str(ipv4.netmask)

            vrf = attributes.value('vrf')
            if vrf:
                ydk_obj.vrf.forwarding = vrf.name
        # instantiate crud service
        crud_service = CRUDService()
        if apply:

            # create netconf connection
            ncp = NetconfServiceProvider(self.device)

            if unconfig:
                crud_service.delete(ncp, ydk_obj)
            else:
                crud_service.create(ncp, ydk_obj)
        else:
            if unconfig:
                return YangConfig(device=self.device,
                                  unconfig=unconfig,
                                  ncp=NetconfServiceProvider,
                                  ydk_obj=ydk_obj,
                                  crud_service=crud_service.delete)
            else:
                return YangConfig(device=self.device,
                                  unconfig=unconfig,
                                  ncp=NetconfServiceProvider,
                                  ydk_obj=ydk_obj,
                                  crud_service=crud_service.create)
Exemple #6
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            assert not kwargs
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            ydk_obj = ned.Native.Vrf()
            vrf_obj = ydk_obj.Definition()
            ydk_obj.definition.append(vrf_obj)
            if attributes.value('name'):
                vrf_obj.name = attributes.value('name')

            # iosxr: vrf vrf1 / address-family ipv4 unicast (config-vrf-af)
            for key, sub, attributes2 in attributes.mapping_items(
                    'address_family_attr', keys=self.address_families,
                    sort=True):
                sub.build_config(apply=False,
                                 attributes=attributes2,
                                 unconfig=unconfig,
                                 vrf_obj=vrf_obj)

            # instantiate crud service
            crud_service = CRUDService()
            if apply:

                # create netconf connection
                ncp = NetconfServiceProvider(self.device)

                crud_service.create(ncp, ydk_obj)

                if unconfig:
                    crud_service.delete(ncp, ydk_obj)
            else:
                if unconfig:
                    return YangConfig(device=self.device,
                                      ydk_obj=ydk_obj,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.delete)
                else:
                    return YangConfig(device=self.device,
                                      ydk_obj=ydk_obj,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.create)
Exemple #7
0
    def build_config(self,
                     apply=True,
                     attributes=None,
                     unconfig=False,
                     **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder(unconfig=unconfig)
        ydk_obj = ned.Native.Interface.Gigabitethernet()
        keep = string.digits + '//'
        ydk_obj.name = ''.join(i for i in attributes.value('name')
                               if i in keep)

        shutdown = attributes.value('shutdown')
        if shutdown is not None:
            if unconfig:
                # Special case: unconfiguring always applies shutdown
                ydk_obj.shutdown = Empty()
            elif shutdown:
                ydk_obj.shutdown = Empty()
            else:
                ydk_obj.shutdown = DELETE()

        ipv4 = attributes.value('ipv4')
        if ipv4:
            if unconfig:
                ydk_obj.ip.address.primary.address = DELETE()
                ydk_obj.ip.address.primary.mask = DELETE()
            else:
                ydk_obj.ip.address.primary.address = str(ipv4.ip)
                ydk_obj.ip.address.primary.mask = str(ipv4.netmask)

        vrf = attributes.value('vrf')
        if vrf:
            if unconfig:
                ydk_obj.vrf.forwarding = DELETE()
            else:
                ydk_obj.vrf.forwarding = vrf.name

        # instantiate crud service
        crud_service = CRUDService()

        if apply:

            # create netconf connection
            ncp = NetconfServiceProvider(self.device)

            crud_service.create(ncp, ydk_obj)
        else:
            return YangConfig(device=self.device,
                              ydk_obj=ydk_obj,
                              ncp=NetconfServiceProvider,
                              crud_service=crud_service.create)
Exemple #8
0
            def build_config(self,
                             ydk_obj,
                             apply=True,
                             attributes=None,
                             unconfig=False,
                             **kwargs):
                assert not apply
                # instantiate crud service
                crud_service = CRUDService()
                attributes = AttributesHelper(self, attributes)
                configurations = CliConfigBuilder(unconfig=unconfig)

                if unconfig:
                    return YangConfig(device=self.device,
                                      ydk_obj=ydk_obj,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.delete)
                else:
                    return YangConfig(device=self.device,
                                      ydk_obj=ydk_obj,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.create)
Exemple #9
0
    def build_config(self,
                     apply=True,
                     attributes=None,
                     unconfig=False,
                     **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder(unconfig=unconfig)
        interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()
        interface_configuration = interface_configurations.InterfaceConfiguration(
        )
        interface_configuration.active = "act"
        interface_configuration.interface_name = attributes.value('name')
        if unconfig and attributes.iswildcard:
            interface_configuration = DELETE()
        else:
            shutdown = attributes.value('shutdown')
            if shutdown is not None:
                if unconfig:
                    # Special case: unconfiguring always applies shutdown
                    interface_configuration.shutdown = Empty()
                elif shutdown:
                    interface_configuration.shutdown = Empty()
                else:
                    interface_configuration.shutdown = DELETE()

            ipv4 = attributes.value('ipv4')
            primary = interface_configuration.ipv4_network.addresses.Primary()
            if ipv4:
                primary.address = str(ipv4.ip)
                primary.netmask = str(ipv4.netmask)

            vrf = attributes.value('vrf')
            if vrf:
                interface_configuration.vrf = vrf.name

        # instantiate crud service
        crud_service = CRUDService()
        if apply:

            # create netconf connection
            ncp = NetconfServiceProvider(self.device)

            return crud_service.create(ncp, interface_configuration)
        else:
            return YangConfig(device=self.device,
                              unconfig=unconfig,
                              ncp=NetconfServiceProvider,
                              interface_configuration=interface_configuration,
                              crud_service=crud_service.create)
Exemple #10
0
            def build_config(self,
                             apply=True,
                             attributes=None,
                             unconfig=False,
                             **kwargs):

                assert not apply
                crud_service = CRUDService()
                attributes = AttributesHelper(self, attributes)
                configurations = CliConfigBuilder(unconfig=unconfig)
                intf_name = attributes.value('interface_name')

                if intf_name.startswith('Gig'):
                    ydk_obj = ned.Native.Interface.Gigabitethernet()
                elif intf_name.startswith('Ten'):
                    ydk_obj = ned.Native.Interface.Tengigabitethernet()

                # Set the interface name
                keep = {string.digits + '//'}
                ydk_obj.name = ''.join(
                    i for i in attributes.value('interface_name') if i in keep)

                # Standby Object
                standby_obj = ydk_obj.Standby()
                ydk_obj.standby = standby_obj

                # =============
                # leaf: version
                # =============
                # interface <interface_name>
                #   standby version <version>
                if attributes.value('version') == 2:
                    version_obj = ydk_obj.standby.VersionEnum.Y_2
                    standby_obj.version = version_obj
                elif attributes.value('version') == 1:
                    version_obj = ydk_obj.standby.VersionEnum.Y_1
                    standby_obj.version = version_obj

                # =========
                # leaf: bfd
                # =========
                # interface <interface_name>
                #   standby <bfd>
                if attributes.value('bfd'):
                    standby_obj.bfd = Empty()

                # ===========
                # leaf: delay
                # ===========
                # interface <interface_name>
                #   standby delay minimum <minimum_delay>\
                #   reload <reload_delay>
                if attributes.value('minimum_delay') and \
                   attributes.value('reload_delay'):
                    delay_obj = standby_obj.Delay()
                    delay_obj.minimum = int(attributes.value('minimum_delay'))
                    delay_obj.reload = int(attributes.value('reload_delay'))
                    standby_obj.delay = delay_obj
                elif attributes.value('minimum_delay'):
                    delay_obj = standby_obj.Delay()
                    delay_obj.minimum = int(attributes.value('minimum_delay'))
                    standby_obj.delay = delay_obj

                # =================
                # leaf: mac-refresh
                # =================
                # interface <interface_name>
                #   standby mac-refresh <mac_refresh>
                if attributes.value('mac_refresh'):
                    standby_obj.mac_refresh = \
                        int(attributes.value('mac_refresh'))

                # =============
                # leaf: use-bia
                # =============
                # interface <interface_name>
                #   standby use-bia scope interface
                if attributes.value('use_bia'):
                    use_bia_obj = ydk_obj.standby.UseBia()
                    scope_obj = ydk_obj.standby.UseBia.Scope()
                    scope_obj.interface = Empty()
                    use_bia_obj.scope = scope_obj
                    standby_obj.use_bia = use_bia_obj

                # ==================
                # leaf: standby-list
                # ==================
                if attributes.value('group_number') is not None:

                    # ==================
                    # leaf: group_number
                    # ==================
                    standby_list_obj = ydk_obj.standby.StandbyList()
                    standby_list_obj.group_number = \
                        int(attributes.value('group_number'))

                    # ====================
                    # leaf: authentication
                    # ====================
                    if attributes.value('authentication_word'):
                        # interface <interface_name>
                        #   standby <group_number> authentication \
                        #   <authentication_word>
                        authentication_obj = standby_list_obj.Authentication()
                        authentication_obj.word = \
                            attributes.value('authentication_word')
                        standby_list_obj.authentication = authentication_obj

                    elif attributes.value('authentication_text'):
                        # interface <interface_name>
                        #   standby <group_number> authentication text \
                        #   <authentication_text>
                        authentication_obj = standby_list_obj.Authentication()
                        authentication_obj.word = \
                            attributes.value('authentication_text')
                        standby_list_obj.authentication = authentication_obj

                    elif attributes.value('authentication_md5_keychain'):
                        # interface <interface_name>
                        #   standby <group_number> authentication \
                        #   md5 key-chain <authentication_md5_keychain>
                        authentication_obj = standby_list_obj.Authentication()
                        md5_obj = authentication_obj.Md5()
                        md5_obj.key_chain = \
                            attributes.value('authentication_md5_keychain')
                        authentication_obj.md5 = md5_obj
                        standby_list_obj.authentication = authentication_obj

                    elif attributes.value('authentication_md5_keystring'):
                        # interface <interface_name>
                        #   standby <group_number> authentication \
                        #   md5 key-string <authentication_md5_keystring>
                        authentication_obj = standby_list_obj.Authentication()
                        md5_obj = authentication_obj.Md5()
                        key_string_obj = md5_obj.KeyString()
                        key_string_obj.string = \
                            attributes.value('authentication_md5_keystring')
                        md5_obj.key_string = key_string_obj
                        authentication_obj.md5 = md5_obj
                        standby_list_obj.authentication = authentication_obj

                    # ============
                    # leaf: follow
                    # ============
                    # interface <interface_name>
                    #   standby <group_number> follow <follow>
                    if attributes.value('follow'):
                        standby_list_obj.follow = attributes.value('follow')

                    # ========
                    # leaf: ip
                    # ========
                    # interface <interface_name>
                    #   standby <group_number> ip <ip_address>
                    if attributes.value('ip_address'):
                        ip_obj = standby_list_obj.Ip()
                        ip_obj.address = attributes.value('ip_address')
                        standby_list_obj.ip = ip_obj

                    # ==========
                    # leaf: ipv6
                    # ==========
                    # interface <interface_name>
                    #   standby <group_number> ip <ip_address>
                    if attributes.value('ipv6_address') == 'autoconfig':
                        ipv6_obj = standby_list_obj.Ipv6Enum.autoconfig
                        standby_list_obj.ipv6 = ipv6_obj
                    else:
                        standby_list_obj.ipv6 = \
                            attributes.value('ipv6_address')

                    # =================
                    # leaf: mac-address
                    # =================
                    # interface <interface_name>
                    #   standby <group_number> mac-address <mac_address>
                    if attributes.value('mac_address'):
                        standby_list_obj.mac_address = \
                            attributes.value('mac_address')

                    # ==========
                    # leaf: name
                    # ==========
                    # interface <interface_name>
                    #   standby <group_number> name <group_name>
                    if attributes.value('group_name'):
                        standby_list_obj.name = attributes.value('group_name')

                    # =============
                    # leaf: preempt
                    # =============
                    if attributes.value('preempt') and \
                       attributes.value('preempt_minimum_delay') and \
                       attributes.value('preempt_reload_delay') and \
                       attributes.value('preempt_sync_delay'):
                        # interface <interface_name>
                        #   standby <group_number> preempt delay \
                        #   minimum <preempt_minimum_delay> reload \
                        #   <preempt_reload> sync <preempt_sync>
                        preempt_obj = standby_list_obj.Preempt()
                        preempt_obj_delay = preempt_obj.Delay()
                        preempt_obj_delay.minimum = \
                            int(attributes.value('preempt_minimum_delay'))
                        preempt_obj_delay.reload = \
                            int(attributes.value('preempt_reload_delay'))
                        preempt_obj_delay.sync = \
                            int(attributes.value('preempt_sync_delay'))
                        preempt_obj.delay = preempt_obj_delay
                        standby_list_obj.preempt = preempt_obj
                    elif attributes.value('preempt') and \
                         attributes.value('preempt_minimum_delay') and \
                         attributes.value('preempt_reload_delay'):
                        # interface <interface_name>
                        #   standby <group_number> preempt delay \
                        #   minimum <preempt_minimum_delay> \
                        #   reload <preempt_reload>
                        preempt_obj = standby_list_obj.Preempt()
                        preempt_obj_delay = preempt_obj.Delay()
                        preempt_obj_delay.minimum = \
                            int(attributes.value('preempt_minimum_delay'))
                        preempt_obj_delay.reload = \
                            int(attributes.value('preempt_reload_delay'))
                        preempt_obj.delay = preempt_obj_delay
                        standby_list_obj.preempt = preempt_obj
                    elif attributes.value('preempt') and \
                         attributes.value('preempt_minimum_delay'):
                        # interface <interface_name>
                        #   standby <group_number> preempt delay \
                        #   minimum <preempt_minimum_delay>
                        preempt_obj = standby_list_obj.Preempt()
                        preempt_obj_delay = preempt_obj.Delay()
                        preempt_obj_delay.minimum = \
                            int(attributes.value('preempt_minimum_delay'))
                        preempt_obj.delay = preempt_obj_delay
                        standby_list_obj.preempt = preempt_obj
                    elif attributes.value('preempt'):
                        # interface <interface_name>
                        #   standby <group_number> preempt delay
                        preempt_obj = standby_list_obj.Preempt()
                        preempt_obj_delay = preempt_obj.Delay()
                        preempt_obj.delay = preempt_obj_delay
                        standby_list_obj.preempt = preempt_obj

                    # ==============
                    # leaf: priority
                    # ==============
                    # interface <interface_name>
                    #   standby <group_number> priority <priority>
                    if attributes.value('priority'):
                        standby_list_obj.priority = \
                            int(attributes.value('priority'))

                    # ==============
                    # leaf: redirect
                    # ==============
                    # TODO: this is a bug

                    # ============
                    # leaf: timers
                    # ============
                    if attributes.value('hello_interval_seconds') and \
                       attributes.value('holdtime_seconds'):
                        # interface <interface_name>
                        #   standby <group_number> timers \
                        #   <hello_interval_seconds> <holdtime_seconds>
                        timers_obj = standby_list_obj.Timers()
                        hello_interval_obj = timers_obj.HelloInterval()
                        hello_interval_obj.seconds = \
                            int(attributes.value('hello_interval_seconds'))
                        timers_obj.hello_interval = hello_interval_obj
                        hold_time_obj = timers_obj.HoldTime()
                        hold_time_obj.seconds = \
                            attributes.value('holdtime_seconds')
                        timers_obj.hold_time = hold_time_obj
                        standby_list_obj.timers = timers_obj
                    elif attributes.value('hello_interval_msec') and \
                         attributes.value('holdtime_msec'):
                        # interface <interface_name>
                        #   standby <group_number> timers msec \
                        #   <hello_interval_msec> msec <holdtime_msec>
                        timers_obj = standby_list_obj.Timers()
                        hello_interval_obj = timers_obj.HelloInterval()
                        hello_interval_obj.msec = \
                            int(attributes.value('hello_interval_msec'))
                        timers_obj.hello_interval = hello_interval_obj
                        hold_time_obj = timers_obj.HoldTime()
                        hold_time_obj.msec = attributes.value('holdtime_msec')
                        timers_obj.hold_time = hold_time_obj
                        standby_list_obj.timers = timers_obj

                    # ===========
                    # leaf: track
                    # ===========
                    if attributes.value('track_object') and \
                       attributes.value('priority_decrement'):
                        # interface <interface_name>
                        #   standby <group_number> track object <track_object> \
                        #   decrement <priority_decrement>
                        track_obj = standby_list_obj.Track()
                        track_obj.number = attributes.value('track_object')
                        track_obj.decrement = \
                            int(attributes.value('priority_decrement'))
                        standby_list_obj.track.append(track_obj)
                    elif attributes.value('track_object') and \
                         attributes.value('track_shutdown'):
                        # interface <interface_name>
                        #   standby <group_number> track object <track_object> \
                        #   shutdown
                        track_obj = standby_list_obj.Track()
                        track_obj.number = attributes.value('track_object')
                        track_obj.shutdown = Empty()
                        standby_list_obj.track.append(track_obj)

                    # Add standby_list_obj to standby_obj
                    standby_obj.standby_list.append(standby_list_obj)

                if unconfig:
                    return YangConfig(device=self.device,
                                      ydk_obj=ydk_obj,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.delete)
                else:
                    return YangConfig(device=self.device,
                                      ydk_obj=ydk_obj,
                                      ncp=NetconfServiceProvider,
                                      crud_service=crud_service.create)
Exemple #11
0
        def build_config(self,
                         apply=True,
                         attributes=None,
                         unconfig=False,
                         **kwargs):
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)
            # No yang models found for NXOS so it has been built following
            # the IOSXE ned models for now.
            ydk_obj = ned.Native.Vlan()

            vlan_config = []
            for sub, attributes2 in attributes.mapping_values(
                    'access_map_attr',
                    keys=self.vlan_configuration_attr.keys()):
                vlan_config.extend(
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     ydk_obj=ydk_obj,
                                     **kwargs))

            for sub, attributes2 in attributes.mapping_values(
                    'vlan_configuration_attr',
                    keys=self.vlan_configuration_attr.keys()):
                vlan_config.extend(
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     ydk_obj=ydk_obj,
                                     **kwargs))

            for sub, attributes2 in attributes.mapping_values(
                    'interface_attr',
                    keys=self.vlan_configuration_attr.keys()):
                vlan_config.extend(
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig,
                                     ydk_obj=ydk_obj,
                                     **kwargs))

            # iosxe: vlan 1000 (config-vlan)
            id = attributes.value('vlan_id', force=True)

            if id:
                vlan = ydk_obj.VlanList()
                vlan.id = int(id)
                ydk_obj.vlan_list.append(vlan)

            # instantiate crud service
            crud_service = CRUDService()

            if apply:

                # create netconf connection
                ncp = NetconfServiceProvider(self.device)

                if unconfig:
                    crud_service.delete(ncp, ydk_obj)
                else:
                    crud_service.create(ncp, ydk_obj)
            else:
                ydks = []

                if unconfig:
                    ydks.append(
                        YangConfig(device=self.device,
                                   ydk_obj=ydk_obj,
                                   ncp=NetconfServiceProvider,
                                   crud_service=crud_service.delete))
                else:
                    ydks.append(
                        YangConfig(device=self.device,
                                   ydk_obj=ydk_obj,
                                   ncp=NetconfServiceProvider,
                                   crud_service=crud_service.create))

                return ydks
Exemple #12
0
                    def build_config(self,
                                     ydk_obj,
                                     apply=True,
                                     attributes=None,
                                     unconfig=False,
                                     **kwargs):
                        assert not apply
                        if kwargs.get('area_id', None) is not None:
                            setattr(self, 'area_id', kwargs['area_id'])
                        # instantiate crud service
                        crud_service = CRUDService()
                        attributes = AttributesHelper(self, attributes)
                        configurations = CliConfigBuilder(unconfig=unconfig)
                        intf_name = attributes.value('interface_name')
                        if intf_name.startswith('Gig'):
                            ydk_obj_intf = ned.Native.Interface.Gigabitethernet(
                            )
                            keep = string.digits + '//'
                            ydk_obj_intf.name = ''.join(
                                i for i in attributes.value('interface_name')
                                if i in keep)

                            if attributes.value('area_id') is not None:
                                ospf_process = ydk_obj_intf.ip.ospf.ProcessId()
                                ospf_process.id = int(
                                    attributes.value('ospf_name'))
                                ospf_process.area = attributes.value('area_id')
                                ydk_obj_intf.ip.ospf.process_id.append(
                                    ospf_process)

                            if attributes.value(
                                    'area_interface_cost') is not None:
                                ydk_obj_intf.ip.ospf.cost = attributes.value(
                                    'area_interface_cost')

                            return YangConfig(device=self.device,
                                              ydk_obj=ydk_obj_intf,
                                              ncp=NetconfServiceProvider,
                                              crud_service=crud_service.create)

                        elif intf_name.startswith('Loop'):
                            ydk_obj_intf = ned.Native.Interface.Loopback()
                            keep = string.digits
                            ydk_obj_intf.name = int(''.join(
                                i for i in attributes.value('interface_name')
                                if i in keep))
                            # name is a mandatory arguments

                            if attributes.value('area_id') is not None:
                                ospf_process = ydk_obj_intf.ip.ospf.ProcessId()
                                ospf_process.id = int(
                                    attributes.value('ospf_name'))
                                ospf_process.area = attributes.value('area_id')
                                ydk_obj_intf.ip.ospf.process_id.append(
                                    ospf_process)

                            if attributes.value(
                                    'area_interface_cost') is not None:
                                ydk_obj_intf.ip.ospf.cost = attributes.value(
                                    'area_interface_cost')

                            if unconfig:
                                return YangConfig(
                                    device=self.device,
                                    ydk_obj=ydk_obj_intf,
                                    ncp=NetconfServiceProvider,
                                    crud_service=crud_service.delete)
                            else:
                                return YangConfig(
                                    device=self.device,
                                    ydk_obj=ydk_obj_intf,
                                    ncp=NetconfServiceProvider,
                                    crud_service=crud_service.create)
Exemple #13
0
    def build_config(self,
                     apply=True,
                     attributes=None,
                     unconfig=False,
                     **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder(unconfig=unconfig)
        interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()
        # import pdb;pdb.set_trace()
        # crud_service = CRUDService()
        # ncp = NetconfServiceProvider(self.device)
        # x = crud_service.read(ncp, interface_configurations)
        # abc = YangConfig(device=self.device, ydk_obj=x, ncp=ncp, crud_service=crud_service)
        # print(abc)
        interface_configuration = interface_configurations.InterfaceConfiguration(
        )
        interface_configuration.active = "act"
        interface_configuration.interface_name = attributes.value('name')
        shutdown = attributes.value('shutdown')

        if shutdown is not None:
            if unconfig:
                # Special case: unconfiguring always applies shutdown
                interface_configuration.shutdown = Empty()
            elif shutdown:
                interface_configuration.shutdown = Empty()

            else:
                interface_configuration.shutdown = DELETE()

        vrf = attributes.value('vrf')
        if vrf:
            if unconfig:
                interface_configuration.vrf = DELETE()
            else:
                interface_configuration.vrf = vrf.name

        ipv4 = attributes.value('ipv4')
        if ipv4:
            primary = interface_configuration.ipv4_network.addresses.Primary()
            if unconfig:
                primary.address = DELETE()
                primary.netmask = DELETE()
                interface_configuration.ipv4_network.addresses.primary = primary
            else:
                primary.address = str(ipv4.ip)
                primary.netmask = str(ipv4.netmask)
                interface_configuration.ipv4_network.addresses.primary = primary

        # In Cisco-IOS-XR-l2-eth-infra-cfg.yang, augmentation section
        # augment "/a1:interface-configurations/a1:interface-configuration"
        # container ethernet-service is defined
        eth_encap_type1 = attributes.value('eth_encap_type1')
        eth_encap_val1 = attributes.value('eth_encap_val1')
        # eth_encap_type2 = attributes.value('eth_encap_type2')
        eth_encap_val2 = attributes.value('eth_encap_val2')

        if eth_encap_type1:
            interface_configuration.ethernet_service\
                                   .local_traffic_default_encapsulation\
                                   .outer_tag_type = eth_encap_type1

        if eth_encap_val1:
            interface_configuration.ethernet_service\
                                   .local_traffic_default_encapsulation\
                                   .outer_vlan_id = eth_encap_val1

        # if eth_encap_type2:
        #     interface_configuration.encapsulation.encapsulation = \
        #         eth_encap_type2

        if eth_encap_val2:
            interface_configuration.ethernet_service\
                                   .local_traffic_default_encapsulation\
                                   .inner_vlan_id = eth_encap_val2

        # instantiate crud service
        crud_service = CRUDService()

        if apply:

            # create netconf connection
            ncp = NetconfServiceProvider(self.device)

            crud_service.create(ncp, interface_configuration)
        else:
            return YangConfig(device=self.device,
                              ydk_obj=interface_configuration,
                              ncp=NetconfServiceProvider,
                              crud_service=crud_service.create)