Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

open() Function (SLAX and XSLT)

Namespaces

SLAX Syntax

XSLT Syntax

Description

Return a connection handle that the script can use to execute remote procedure calls (RPCs) using the jcs:execute() extension function. To execute an RPC on a remote device, the script must establish an SSH session. In order for the script to establish the connection, you must either configure the SSH host key information for the remote device on the local device where you execute the script, or the SSH host key information for the remote device must exist in the known hosts file of the user executing the script.

Note:

Junos OS Evolved supports only password-less login when establishing a local or remote connection using the jcs:open() function. Junos OS Evolved does not support supplying a password as a function argument or using an interactive password as is supported by Junos OS. To effect a local or remote connection, execute this functionality by way of a password-less login or else authentication issues could be encountered.

To redirect the SSH connection to originate from within a specific routing instance, include the routing instance name in the connection parameters. You must configure the routing instance at the [edit routing-instances] hierarchy level. The remote device must be reachable either using the routing table for that routing instance or from one of the interfaces configured under that routing instance.

You can include the session-options parameter to specify the session type to create. You can create a session with the Junos XML protocol server on Junos devices or with the NETCONF server on devices that enable NETCONF service over SSH.

Note:

Python automation scripts can use Junos PyEZ APIs to establish a session and execute RPCs on a local or remote device.

The script uses the jcs:close() function to close the connection handle.

Parameters

passphrase

(Optional) User’s login passphrase. If you do not specify a passphrase and it is required for authentication, the device to which you are connecting should prompt for the password during script execution.

remote-hostname

Domain name or IP address of the remote device. If you open a local connection, do not pass this value. If you specify a session type, this parameter is required.

routing-instance-name

(Optional) Routing instance from which the SSH connection originates.

session-options

(Optional) XML node set that specifies the session protocol and connection parameters. The structure of the node set is:

  • <instance>—(Optional) Routing instance from which the SSH connection originates. This element is identical to <routing-instance>.

  • <method>—(Optional) Session protocol.

    • junoscript—(Default) Establish a session with the Junos XML protocol server on a Junos device.

    • netconf—Establish a session with a NETCONF server over an SSHv2 connection.

    • junos-netconf—Establish a session with a NETCONF server over an SSHv2 connection on a Junos device.

  • <passphrase> or <password>—(Optional) User’s login passphrase. If you do not specify a passphrase and it is required for authentication, the device to which you are connecting should prompt for one during script execution.

  • <port>—(Optional) Server port number for netconf and junos-netconf sessions. For NETCONF sessions, jcs:open() connects to the NETCONF server at the default port 830. If you specify a value for <port>, jcs:open() connects to the given port instead. Specifying a port number has no impact on junoscript sessions, which are always established over SSH port 22.

  • <routing-instance>—(Optional) Routing instance from which the SSH connection originates. This element is identical to <instance>.

  • <username>—(Optional) User’s login name. If you do not specify a username and it is required for the connection, the script uses the local name of the user executing the script.

username

(Optional) User’s login name. If you do not specify a username and it is required for the connection, the script uses the local name of the user executing the script.

Return Value

connection

Connection handle to the remote host.

Usage Examples

The following example shows how to connect to a local device:

The following example shows how to connect to a remote device:

The following example shows how the user, admin, with the passphrase “test123” obtains a connection handle to the remote device, router1:

The following example shows how the user, admin, with the passphrase “test123” creates a junos-netconf session with a device running Junos OS:

Release Information

Function introduced in Junos OS Release 9.3.

Support for NETCONF sessions added in Junos OS Release 11.4.

Support for routing instances added in Junos OS Release 12.2.

Support for Junos OS Evolved added in Junos OS Evolved Release 18.3R1.