Supported Platforms
Related Documentation
NETCONF Java Toolkit Class: NetconfSession
A net.juniper.netconf.NetconfSession object represents the NETCONF session between the configuration management server and the device on which the NETCONF server resides.
By default, a NETCONF session is created when you create a new instance of Device and connect to a NETCONF server, so you do not need to explicitly create a NetconfSession object. You can perform the NETCONF operations directly from the Device object by calling the associated methods.
However, there might be times when you need multiple NETCONF sessions on the same SSHv2 connection. To create multiple sessions, call the createNetconfSession() method on the Device object as shown in the following example:
Device device = new Device("10.10.1.1", "admin", "PaSsWoRd", null); device.connect(); NetconfSession second_session = device.createNetconfSession();
Once you create an additional NETCONF session, you call the NETCONF operation methods for the new NetconfSession object in the same way as you call them for the Device object.
The Device and NetconfSession classes contain many identical methods, which perform NETCONF operations such as executing remote procedure calls (RPCs) and performing configuration changes. When you call a method on the Device object, it acts on the default NETCONF session. When you call a method on any additional NetconfSession object, it acts on that NETCONF session.
Example: Creating Multiple NETCONF Sessions
In the following example, the code snippet creates a new Device object. When the connect() method is called, the program connects to the remote device and establishes a default NETCONF session. The program creates a second NetconfSession object, second_session. Calling device.getSessionID() returns the session ID of the default NETCONF session, and calling second_session.getSessionID() returns the session ID of the second NETCONF session.
// Create a device object and a default NETCONF session Device device = new Device("10.10.1.34", "admin", "PaSsWoRd", null); device.connect(); // Create an additional NETCONF session NetconfSession second_session = device.createNetconfSession(); // There are two independent NETCONF sessions String default_session_id = device.getSessionID(); String second_session_id = second_session.getSessionID();