NETCONF Session Configuration
The yangcli-pro program can be configured to associate a name with a set of session parameters to start a NETCONF session with a server. These named sessions are saved in a configuration file. Use the --autosessions to suppress automatic loading of this file. The default is to load this file at start-up and save it upon exit.
By default, the sessions configuration is saved in
$HOME/.yumapro/yangcli_pro_sessions.conf
. To override this file, set
--autosessions=false and use the sessions-cfg command to load
a specific sessions configuration file.
The start-session command is used to start a named session:
> start-session session-A
... startup screen ...
session-A>
Saving Sessions
To save a session, the text configuration file can be edited or the session-cfg 'save' command can be used.
> connect user=andy server=myserver password=mypassword
... startup screen ...
andy@myserver> session-cfg save session-A
Saved current session as 'session-A'
andy@myserver>
Session use-event-handler
The configured event-handler does not actually cause any event scripts to be invoked because there has to be a session-cfg mapping. The session-cfg has parameter ‘use-event-handler’ to do the mapping.
leaf-list use-event-handler {
type nt:NcxIdentifier;
description
"Name of an event-handler to use within this session.
When notification delivery for this session is started
the event handler will be installed. A warning will be
printed if no event-handler with this name is found.";
}
The event-handler has to be mapped to the session-cfg:
session-A> session-cfg use-event-handler=handler-ses-change
session-A> session-cfg use-event-handler=handler-ses-end
session-A> session-cfg use-event-handler=handler-ses-start
session-A>
session-A> sessions-cfg full
Saved sessions source: '~/.yumapro/.yangcli_pro_sessions.conf'
Session 'session-A':
user: username
password: password:
server: 192.168.0.11
connected: true
port: 830
protocols: netconf1.1
public-key: $HOME/.ssh/id_rsa.pub
private-key: $HOME/.ssh/id_rsa
ssl-fallback-ok: true
ssl-certificate:
ssl-key:
ssl-trust-store:
transport: netconf-ssh
Event Handler 'handler-ses-change'
module-name=ietf-netconf-notifications
event-name=netconf-config-change
shell-script=ses-change.sh
Event Handler 'handler-ses-start'
module-name=ietf-netconf-notifications
event-name=netconf-session-start
shell-script=ses-start.sh
Event Handler 'handler-ses-end'
module-name=ietf-netconf-notifications
event-name=netconf-session-end
shell-script=ses-end.sh
Multiple Sessions
Multiple sessions can be active at once, however only one command at a time can be sent. This will be improved in a future release. Just use the start-session command to start a different session. Only one instance of each named session can be active at the same time.
> start-session session-A
... startup screen ...
session-A> start-session session-B
... startup screen ...
session-B>
Note that when a session is started, the active session is set to that session.
Changing the Active Session
To change the active session and issue commands to a different server, use the session 'set-current' command. This command will cause all subsequent remote commands to be sent to the server associated with the named session.
session-A> session set-current session-B
session-B>
Since the “set-current” parameter is the default parameter, this command can be simplified:
session-A> session session-B
session-B>
To switch to the default session, use the session name “default”. If the default session is connected, then the user and host name will be shown. If not, a simple '>' prompt will be shown instead.
session-A> session default
andy@myserver>
Saving the Configured Sessions
The session configuration can be saved or loaded at run-time, even if the --autosessions=true parameter is used (the default). The sessions-cfg command is used to load and save this file.
session-A> sessions-cfg save
Saved 2 sessions OK to '~/.yumapro/yangcli_pro_sessions.conf'
session-A>
To save the sessions to a different file, simply provide the filespec in the sessions-cfg 'save' command:
session-A> sessions-cfg save mysessions.conf
Saved 2 sessions OK to 'mysessions.conf'
session-A>
Loading Additional Configured Sessions
Additional sessions can be added to the configuration in memory with the sessions-cfg 'load' command. The named sessions in the file cannot conflict with names already in use or the duplicate session will be skipped.
session-A> sessions-cfg load sessions.conf
Loaded 3 sessions OK from 'sessions.conf'
session-A>
Displaying the Configured Sessions
The sessions that are available can be displayed with the sessions-cfg 'show' command. The --brief and --full extensions are available for this command.
session-A> sessions-cfg show
Saved sessions source: 'mysessions.conf'
Session 'session-A':
user: andy
server: localhost
connected: true
Session 'session-B':
user: andy
server: eval.yumaworks.com
connected: false
Displaying Sessions
Displaying the Active Session
To see information about the active session, use the session-cfg command:
session-A> session-cfg
Session 'session-A':
user: andy
server: localhost
connected: true
Session 'session-B':
user: andy
server: eval.yumaworks.com
connected: false
Displaying a Specific Session
To see information about a specific session, use the session-cfg 'show' command:
session-A> session-cfg show session-B
Session 'session-B':
user: andy
server: eval.yumaworks.com
connected: false
session-A>
Terminating a Named Session
The stop-session command is used to terminate a specific session. The <close-session> operation will be sent on the specified session and the connection gracefully terminated.
session-A> stop-session session-B
session-A>
The active session can also be terminated although no new session will be selected automatically:
session-A> stop-session session-A
>
Saved Session Configuration File Format
The saved sessions are stored in a YumaPro configuration file.
The file contents must conform to the following YANG container definition:
container saved-sessions {
ncx:abstract;
description
"Represents all the saved sessions in
the ~/.yumapro/yangcli_pro_sessions file.
Use the 'sessions' command to access this file.
Edit by hand only if you follow this YANG definition.";
list session {
description
"The list of sessions to use during this test-suite.";
key name;
leaf name {
type nt:NcxName;
description
"The name of the saved session.
The 'session save' command will use the
string <user>@<server-address> as the default.";
}
leaf-list use-event-handler {
type nt:NcxIdentifier;
description
"Name of an event-handler to use within this session.
When notification delivery for this session is started
the event handler will be installed. A warning will be
printed if no event-handler with this name is found.";
}
leaf device {
type nt:NcxDeviceName;
mandatory true;
description
"Device name of the NETCONF server target.";
}
leaf userid {
type nt:NcxName;
mandatory true;
description
"User Id of the NETCONF user.";
}
leaf user {
type nt:NcxName;
mandatory true;
description
"The user name of the session.";
}
choice pass {
mandatory true;
leaf password {
type string;
ncx:password;
description
"User password to use for NETCONF sessions.
If none, then user will be prompted before connecting.";
}
leaf no-password { type empty; }
}
uses ywapp:SshKeyParms;
uses ywapp:SslKeyParms;
leaf server {
type inet:host;
mandatory true;
description
"IP address or DNS name of the NETCONF server target.";
}
leaf ncport {
type uint16 {
range "1..max";
}
default 830;
description
"NETCONF port number to use. If not present, then
port 830, followed by port 22, will be tried.";
}
uses EntryPointParm;
uses ncxapp:ProtocolsParm;
leaf transport {
description
"Identifies the transport protocol that should be used.";
type ywt:transport-type;
default ssh;
}
container start-commands {
ywx:cli-text-block;
description
"An optional block of yangcli commands to run
after the session is successfully started.";
}
uses VarsContainer;
uses CommentParm;
}
Session Configuration File Example
The following example file shows a valid session configuration file:
saved-sessions {
session session-A {
user andy
password mypassword
public-key $HOME/.ssh/id_rsa.pub
private-key $HOME/.ssh/id_rsa
server localhost
ncport 830
protocols "netconf1.0 netconf1.1"
}
session session-B {
user andy
password mypassword
public-key $HOME/.ssh/id_rsa.pub
private-key $HOME/.ssh/id_rsa
server localhost
ncport 830
protocols "netconf1.0 netconf1.1"
}
session A {
user andy2
password newpassword
public-key $HOME/.ssh/id_rsa.pub
private-key $HOME/.ssh/id_rsa
server localhost
ncport 830
protocols "netconf1.0 netconf1.1"
}
}