Automation

 View Only
last person joined: 4 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Automation to pull interface and Interface description to CSV

    Posted 11-17-2022 19:37
    Hello, 

    Im new to Juniper scripting. 

    I am wanting to generate a script to pull all of the interfaces and their configured descriptions into a CSV file. 

    What would be the method for going about this? 
    I was able to get dev.facts however that doesnt show any interface information. 

    Thanks!

    ------------------------------
    BRADLEY RADOMSKI
    ------------------------------


  • 2.  RE: Automation to pull interface and Interface description to CSV

     
    Posted 01-10-2023 09:54
    To pull the interface name and description for only those interfaces that have a description, then you can leverage the command "show interfaces descriptions".    Via the CLI you can see that this would produce output something along the lines of the following example:

    show interfaces descriptions
    Interface       Admin Link Description
    fab0            up    up   fab0 interface description
    fab1            up    up   fab1 interface description
    lo0             up    up   loopback description
    lo0.0           up    up   loopback logical unit 0 description​

    What you really want however is the RPC associated with this particular command, again from the CLI you can use the "| display xml rpc" argument to identify the RPC associated with this particular command, as shown below.

    show interfaces descriptions | display xml rpc
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X46/junos">
        <rpc>
            <get-interface-information>
                    <descriptions/>
            </get-interface-information>
        </rpc>
        <cli>
            <banner>{secondary:node0}</banner>
        </cli>
    </rpc-reply>


    This informs you that the RPC get-interface-information with the argument descriptions is used to return this data in a suitable format that can then be converted to CSV.

    So with the RPC known, you can then make a call via PyEz to obtain this data, note that the rpc name that contains "-" have to be converted to "_" instead. e.g. get_interface_information and not get-interface-information

    rsp = dev.rpc.get_interface_information(descriptions=True)


    Some information about the above approach can be found at the following URL:  https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/task/junos-pyez-rpcs-executing.html

    Regards.



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