open() Function (SLAX and XSLT)
Namespaces
http://xml.juniper.net/junos/commit-scripts/1.0
SLAX Syntax
var $connection = jcs:open(); var $connection = jcs:open(remote-hostname, <username>, <passphrase>, <routing-instance-name>); var $connection = jcs:open(remote-hostname, <session-options>);
XSLT Syntax
<xsl:variable name="connection" select="jcs:open()"/> <xsl:variable name="connection" select="jcs:open(remote-hostname, <username>, <passphrase>, <routing-instance-name>)"/> <xsl:variable name="connection" select="jcs:open(remote-hostname, <session-options>)"/>
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.
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.
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: var $session-options := {
<instance> "routing-instance-name";
<method> ("junoscript" | "netconf" | "junos-netconf");
<passphrase> "passphrase";
<password> "password";
<port> "port-number";
<routing-instance> "routing-instance-name";
<username> "username";
}
|
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:
var $connection = jcs:open();
The following example shows how to connect to a remote device:
var $connection = jcs:open(remote-hostname);
The following example shows how the user, admin, with the passphrase “test123” obtains a connection handle to the remote device, router1:
var $connection = jcs:open("router1", "admin", "test123");The following example shows how the user, admin, with the passphrase “test123” creates a
junos-netconf session with a device running Junos OS:
var $options := {
<method> "junos-netconf";
<username> "admin";
<passphrase> "test123";
}
var $connection = jcs:open("router1", $options);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.