Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation
 

Related Documentation

 

Using Device Object Methods to Execute RPCs and Operational Commands

The NETCONF Java toolkit Device object has methods to request information from and perform operational tasks on remote devices. When appropriate, the methods are overloaded to take a number of different formats.

Executing RPCs

To execute a remote procedure call (RPC), call the executeRPC() method on the Device object. The executeRPC() method is overloaded to accept a String object, a net.juniper.netconf.XML object, or an org.w3c.dom.Document object as the argument. The RPC is processed by the NETCONF server, which returns the RPC reply as an XML object.

The method syntax is:

public XML executeRPC (String rpcContent)
public XML executeRPC (net.juniper.netconf.XML rpc)
public XML executeRPC (org.w3c.dom.Document rpcDoc)

The following code snippet executes the Junos XML API get-chassis-inventory RPC using a string argument. The get-chassis-inventory RPC is equivalent to the show chassis hardware operational mode command in the Junos OS command-line interface (CLI).

Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
try {
    XML rpc_reply = device.executeRPC("get-chassis-inventory");
    System.out.println(rpc_reply.toString());
}
catch (Exception e) {
    System.out.println("exception: " + e.getMessage());
    // additional processing for exception
}
device.close();

Executing Operational Mode Commands

To execute an operational mode command to request information from or perform operational tasks on a device running Junos OS, call the runCliCommand() method on the Device object. The runCliCommand() method sends a Junos OS operational mode command to the NETCONF server on the remote device. The argument is a string representing the operational mode command that you would enter in the Junos OS CLI. The RPC is processed by the NETCONF server, which returns the RPC reply. Starting with Junos OS Release 11.4, the return string is the same ASCII-formatted output that you see in the Junos OS CLI. For devices running earlier versions of Junos OS, the return string contains Junos XML tag elements.

The method syntax is:

public String runCLICommand (String command)

The following code snippet sends the CLI operational mode command show chassis hardware to the NETCONF server on a device running Junos OS:

Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
try {
        cli_reply = device.runCliCommand("show chassis hardware");
        System.out.println(cli_reply);        
    }
catch (Exception e) {
    System.out.println("exception: " + e.getMessage());
    // additional processing for exception
}
device.close();
 

Related Documentation

 

Published: 2012-11-05

 

Related Documentation

 

Published: 2012-11-05