open() Function (SLAX and XSLT)
Namespaces
SLAX Syntax
XSLT Syntax
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.
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"; }
<instance>
—(Optional) Routing instance from within which the SSH connection originates. This element is identical to<routing-instance>
.<method>
—(Optional) Session protocol. The protocol is one of three values:junoscript
,netconf
, orjunos-netconf
. If you do not specify a protocol, ajunoscript
session is created by default. A<method>
value ofjunoscript
establishes a session with the Junos XML protocol server on a device running Junos OS. A<method>
value ofnetconf
establishes a session with a NETCONF server over an SSHv2 connection. A<method>
value ofjunos-netconf
establishes a session with a NETCONF server over an SSHv2 connection on a device running Junos OS.<passphrase> or <password>
—(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.<port>
—(Optional) Server port number fornetconf
andjunos-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 onjunoscript
sessions, which are always established over SSH port 22.<routing-instance>
—(Optional) Routing instance from within 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:
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);