[Contents] [Prev] [Next] [Index] [Report an Error]

Using RPCs and Operational Mode Commands

Most operational mode commands supported in the JUNOS software have XML equivalents known as remote procedure calls (RPCs). All operational mode commands that have XML equivalents are listed in the JUNOS XML API Operational Reference.

Using RPCs

To use an RPC in an automation script, include the RPC in a variable declaration, as shown in the following snippet. This snippet is expanded and fully described in Customizing Output of the show interfaces terse Command.

<xsl:variable name="rpc">
    <get-interface-information/> # JUNOS RPC for the show interfaces command
</xsl:variable>
<xsl:variable name="out" select="jcs:invoke($rpc)"/>
...

Using Operational Mode Commands

Some operational mode commands do not currently have XML equivalents (RPCs). If a command is not listed in the JUNOS XML API Operational Reference, the command does not have an XML equivalent.

Another way to determine whether a command has an XML equivalent is to issue the command with the | display xml piped command:

user@host> operational-mode-command | display xml

If the output of this command contains no more detail than the <output> and <cli> tag elements, the command might not have an XML equivalent. For example, the show host command has no XML equivalent. The only child elements of the <rpc-reply> element are the <output> and <cli> tag elements:

user@host> show host hostname | display xml 

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/7.6R1/junos">
   <output>
       ...
    </output>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

Note: For some commands, if there is no corresponding configuration, the output of the piped | display xml command might contain no information, even though an RPC exists for the command. For example, suppose a router configuration contains no statements at the [edit class-of-service] hierarchy level. If you issue the show services cos statistics forwarding-class | display xml command on this router, the output does not contain the existing <service-cos-forwarding-class-statistics> response tag:


user@host> show services cos statistics forwarding-class | display xml
 <rpc-reply xmlns:junos="http://xml.juniper.net/junos/8.3I0/junos">
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

For this reason, checking the JUNOS XML API Operational Reference is the most reliable method for determining whether a command has an XML equivalent.

You can reference commands that have no XML equivalent. You can do this by including the <command>, <xsl:value-of>, and <output> elements, as shown in the following snippet. This snippet is expanded and fully described in Displaying DNS Hostname Information.

<xsl:variable name="query">
    <command>
        <xsl:value-of select="concat('show host ', $hostname)"/>
    </command>
</xsl:variable>
<xsl:variable name="result" select="jcs:invoke($query)"/>
<xsl:variable name="host" select="$result"/>
<output>
    <xsl:value-of select="concat('Name: ', $host)"/>
</output>
...

[Contents] [Prev] [Next] [Index] [Report an Error]