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 can be used to
execute remote procedure calls (RPCs) using the jcs:execute()
extension function. To execute an RPC on a remote device, an SSH session must be established. 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 the script will be executed, or the SSH host key information
for the remote device must exist in the known hosts file of the user
executing the script.
Devices running Junos OS Evolved support only password-less
login when establishing a local or remote connection using the jcs:open()
function. They do 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. The routing instance must be configured at the [edit
routing-instances]
hierarchy level, and 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.
Starting in Junos OS Release 11.4, the new parameter, session-options
, supports the
option to create a session either with the Junos XML protocol server
on devices running Junos OS or with the NETCONF server on devices
where NETCONF service over SSH is enabled. Previously, the function
supported only sessions with the Junos XML protocol server on devices
running Junos OS.
Python automation scripts can use Junos PyEZ APIs to establish a session and execute RPCs on a local or remote device.
The connection handle is closed with the jcs:close()
function.
Parameters
passphrase |
(Optional) User’s login passphrase. If you do not specify a passphrase and it is required for authentication, you should be prompted for one during script execution by the device to which you are connecting. |
remote-hostname |
Domain name or IP address of the remote router, switch, or security device. If you are opening 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 within 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, bsmith, with the passphrase “test123” obtains a connection handle to the remote device, fivestar:
var $connection = jcs:open("fivestar", "bsmith", "test123");
The following example shows how the user, bsmith, with
the passphrase “test123” creates a junos-netconf
session with a device running Junos OS:
var $options := { <method> "junos-netconf"; <username> "bsmith"; <passphrase> "test123"; } var $connection = jcs:open("fivestar", $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.