Junos Automation (Scripting)
Reply
Trusted Contributor
Luca
Posts: 314
Registered: ‎06-11-2009
0

API - XML program

Hi

I need to test some XML commands and their responses on an srx650. Is there a program available that will let me execute XML commands via an API?
Recognized Expert
Mattia
Posts: 198
Registered: ‎03-17-2010
0

Re: API - XML program

Hi Luca, you can install the Junoscript perl client on a unix server; the documentation reference is here: http://www.juniper.net/support/products/junoscript/
If you want to see the XML version of the output of operational and configuration commands, use the "| display xml" command.
Hope it helps,
Mattia
.................................................................................
JNCIP-ENT, JNCIP-SEC, JNCIS-SP
(If this post helped you, please mark it as an "Accepted Solution"; kudos are also appreciated!)


Trusted Contributor
roy_lee
Posts: 28
Registered: ‎06-11-2008
0

Re: API - XML program


Mattia wrote:

If you want to see the XML version of the output of operational and configuration commands, use the "| display xml" command.


Adding to Mattia's comment...you (Luca) may take a look at this Junos XML overview page

http://www.juniper.net/techpubs/en_US/junos/topics/concept/junos-script-automation-junos-os-xml-over...

 

thanks,

roy

Contributor
ed_gpc
Posts: 193
Registered: ‎09-21-2010
0

Re: API - XML program

I am currently working on a .net application for NETCONF for us windows folks :smileyhappy:

 

Any particular feature your looking for?

Juniper Employee
PhilShafer
Posts: 19
Registered: ‎09-29-2009
0

Re: API - XML program

The easiest way to experiment with the XML API is by using the CLI.

 

To find the RPC for any command use the "| display xml rpc" pipe and to see the resulting XML output, use the " | display xml" pipe:

 

phil@test> show ospf neighbor 10.5.10.2 detail 
Address          Interface              State     ID               Pri  Dead
10.5.10.2        fe-0/0/1.0             Full      10.254.254.103   128    34
  Area 0.0.0.0, opt 0x42, DR 10.5.10.2, BDR 10.5.10.1
  Up 13w3d 03:35:32, adjacent 13w3d 03:35:13

phil@test> show ospf neighbor 10.5.10.2 detail | display xml rpc 
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.4I0/junos">
    <rpc>
        <get-ospf-neighbor-information>
                <detail/>
                <neighbor>10.5.10.2</neighbor>
        </get-ospf-neighbor-information>
    </rpc>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

phil@test> show ospf neighbor 10.5.10.2 detail | display xml        
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.4I0/junos">
    <ospf-neighbor-information xmlns="http://xml.juniper.net/junos/11.4I0/junos-routing">
        <ospf-neighbor>
            <neighbor-address>10.5.10.2</neighbor-address>
            <interface-name>fe-0/0/1.0</interface-name>
            <ospf-neighbor-state>Full</ospf-neighbor-state>
            <neighbor-id>10.254.254.103</neighbor-id>
            <neighbor-priority>128</neighbor-priority>
            <activity-timer>33</activity-timer>
            <ospf-area>0.0.0.0</ospf-area>
            <options>0x42</options>
            <dr-address>10.5.10.2</dr-address>
            <bdr-address>10.5.10.1</bdr-address>
            <neighbor-up-time junos:seconds="8134542">
                13w3d 03:35:42
            </neighbor-up-time>
            <neighbor-adjacency-time junos:seconds="8134523">
                13w3d 03:35:23
            </neighbor-adjacency-time>
        </ospf-neighbor>
    </ospf-neighbor-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

phil@test> 

 

Then you can make a script to perform the RPC as needed for testing:

 

version 1.0;

ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

match / {
    <op-script-results> {
        var $rpc = <get-ospf-neighbor-information> {
            <detail>;
            <neighbor> "10.5.10.2";
        }
        var $res = jcs:invoke($rpc);
        <output> $res/ospf-neighbor/neighbor-address _ " is in state "
            _ $res/ospf-neighbor/ospf-neighbor-state;
    }
}

 

 

Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.