Automation

 View Only
last person joined: 5 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Script failing to pull interface details via RPC for IRB interfaces on Juniper QFX

    Posted 12-02-2022 10:19
    Hello All,

    If someone could help point me in the right direction, would be amazing.

    I created a script to pull interface information for the irb interfaces that are active on our QFXs.
    I tried the using a custom table and view to pull the information and produce the output similar to 
    show interfaces irb terse (without the IP details)

    >show interfaces irb terse
    Interface                 Admin          Link     Proto              Local Remote
    irb                                    up                 up
    irb.x                                up                 up         inet                x.x.x.x/x
                                                                                                            x.x.x.x/x
    irb.x                                up                 up         inet                x.x.x.x/x

    For my test I was mainly interested in the information below.

    interface description
    interface name
    Interface admin status
    Interface oper status

    On running the script, I get the following output

    Interface description
    irb.xxx
    None
    None
    Interface description
    irb.xxx
    None
    None
    .
    .
    .
    .
    .

    I can get the interface status from the main irb instance, but I want to get the operational and admin status information from all the sub interfaces.
    There is a pre-configured table and view for the ethernet ports, but that will not work for the irbs interfaces.


    Any suggestions?

    Very new to scripting so I can expect I've mixed up a few things.

    Thanks 

    R

    ---------------------
    SCRIPT
    -------------------

    from jnpr.junos import Device
    from jnpr.junos.factory.factory_loader import FactoryLoader
    import yaml
    from jnpr.junos.op.xcvr import XcvrTable

    yml = """
    ---
    IrbPortTable:
    rpc: get-interface-information
    args:
    interface_name: '[irb]*'
    args_key: interface_name
    item: physical-interface/logical-interface
    view: IrbPortView

    IrbPortView:
    groups:
    flags: if-device-flags
    fields:
    oper: logical-interface/oper-status
    admin: logical-interface/admin-status
    description: description
    fields_flags:
    running: { ifdf-running: flag }
    present: { ifdf-present: flag }





    interfaceInformation:
    rpc: get-interface-information


    """

    globals().update(FactoryLoader().load(yaml.load(yml, Loader=yaml.FullLoader)))

    with Device(host='device', port='22', user='uname',passwd='password') as dev:
    Irb = IrbPortTable(dev)
    Irb.get()
    for item in Irb:
    print (item.name)
    print (item.oper)
    print (item.admin)
    print (item.description)

    ------------------------------

    I have tried this script on two different models of qfx's and get the same output 

    Model: qfx5120
    Junos: 20.2R3.9

    Model: qfx5100
    Junos: 14.1X53-D30.3


  • 2.  RE: Script failing to pull interface details via RPC for IRB interfaces on Juniper QFX

    Posted 01-02-2023 12:55
    Hi RoninDN,

    I think the anwer that you are looking for is documented here:

    https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/topic-map/junos-pyez-program-configuration-retrieving.html

    Thanks,
    Adrian.

    ------------------------------
    Teodor Adrian Soroceanu
    ------------------------------



  • 3.  RE: Script failing to pull interface details via RPC for IRB interfaces on Juniper QFX

     
    Posted 01-16-2023 11:38
    Edited by asharp 01-16-2023 12:45
    Hi,

    This was an interesting one.   So the RPC get-interface-information, doesn't actually return oper/admin status for logical interfaces.  Unlike "show interfaces terse" which does return the oper/admin status for logical interfaces.

    Change your RPC  args to include terse:true and you should see data.  Also, your context within the device hierarchy  XML is .../physical-interface/logical-interface.   So you need to remove logical-interface from the following entries, else you'd be trying to get .../physical-interface/logical-interface/logical-interface... which will not work.

    oper: logical-interface/oper-status
    admin: logical-interface/admin-status

    The following should work now.

    from jnpr.junos import Device
    from jnpr.junos.factory.factory_loader import FactoryLoader
    import yaml
    
    yml = """
    ---
    IrbPortTable:
        rpc: get-interface-information
        args:
            terse: True
            interface_name: 'irb*'
        args_key: interface_name
        item: physical-interface/logical-interface
        view: IrbPortView
    
    IrbPortView:
        groups:
            flags: if-device-flags
        fields:
            oper: oper-status
            admin: admin-status
            description: description
            fields_flags:
                running: { ifdf-running: flag }
                present: { ifdf-present: flag }
    
    """
    
    globals().update(FactoryLoader().load(yaml.load(yml, Loader=yaml.FullLoader)))
    
    with Device(host='device', port='22', user='myuser',passwd='mypasswd') as dev:
        Irb = IrbPortTable(dev)
        Irb.get()
        for item in Irb:
            print (item.name)
            print (item.oper)
            print (item.admin)
            print (item.description)


    Regards.

    ------------------------------
    Andy Sharp
    ------------------------------