Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Netconf client CLI tool and interactive console

Project description

A console application for interacting with NETCONF servers built on top of ncclient.

Requirements and installation

This application runs both in Python 2 and Python 3 environments. The only package required for running this application is ncclient; if this is installed, all other necessary packages are installed as dependencies. This means that if you can (successfully) run something like pip install ncclient on the target platform, all requirements should be met.

If you cannot, there still is a chance you can run it if the target platform supports at least packages six and lxml, which are commonly present; and if it contains paramiko or at least cryptography, you will be able to use SSH (without them you can only use plain and nonstandard TCP transport). The missing piece, ncclient, can be cloned and compiled to a “Python Wheel” - you can do this on any computer and copy the resulting .whl file to the target platform, it should work there. Pretty much the same holds for paramiko. You may also want to create a wheel for the application itself by running python bdist_wheel.

Installing and running the application

If you can and want to install the application and all necessary libraries, just run python install. Otherwise prepare all necessary .whl files and the script netconf-console to the target platform. If they are in the same directory, nothing else is needed, otherwise you may need to add the wheel files to PYTHONPATH before running the script.

Once installed or copied, you can just run the script with appropriate options - see below.

Command-line mode

The application can be run in two different modes: command-line mode and interactive (console) mode. The command-line mode allows you to request several RPC operations in one shell command. The command line would contain the operation command options (--get, --lock, etc.) in the desired order, all common options (such as --host, --port etc.) as well as command options (--db, --style); the command options are all used for the commands that accept them, so for example no two commands can address different datastores.

An example of such command line:

# netconf-console --db candidate --lock --edit-config=fragment1.xml \
--rpc=commit-confirmed.xml --unlock --sleep 5 --rpc=confirm.xml

Interactive mode

The interactive mode is started by --interactive (or -i). During an interactive session the user issues commands, one per line, with required arguments or options. The options are isolated now, so it is possible to have two commands in one session accessing different datastores. The interactive console provides limited support for tab-completion of commands, options, and their arguments.

The previous example can look like this:

# netconf-console -i
netconf> lock
netconf> edit-config fragment1.xml --db candidate
netconf> rpc commit-confirmed.xml
netconf> unlock
netconf> get-config
netconf> rpc confirm.xml

Note: some commands (rpc, edit-config and others) may accept data from standard input in the command-line mode; this does not work in the interactive mode.

Some capabilities of the interactive mode can be used in command-line mode too using --expr pseudo-command: the argument is a command (including options) as if it was added in the interactive mode, such as

# netconf-console --expr 'get-config --db candidate' 'get-config'


A command may accept an argument and a number of options. In command-line mode, all option values are shared (see above); conversely, in interactive mode the option needs to be provided for every command where its desired value differs from the default. If a command does not accept given option, it is a syntax error to provide it in interactive mode (in command-line mode such situations are ignored).

Send just the initial hello message and display the reply. Does not accept any arguments or options.
Send get RPC. Accepts options outputStyle, with-defaults, xpath. As an alternative to xpath, get accepts path as an argument.
Send get-config RPC. Accepts the same set of options as get plus db.
Send edit-config with single leaf assignment. Requires the assignment in the form <path>=<value> as an argument, accepts db, test, and operation. The path may contain (or actually needs to contain, in case it descends into a list instance) simple predicates in the form node[key1=value1][key2=value2]....
Sends edit-config with a single node to be deleted. The node is determined by the path provided as an argument, see set for the path format. Accepts db, test, and del-operation options.
Sends edit-config with a single node to be created. The node is determined by the path provided as an argument, see set for the path format.
Send kill-session RPC. Requires session identifier as an argument, accepts no options.
Send discard-changes RPC. Accepts no arguments or options.
Send lock RPC towards the datastore indicated by db option.
Send unlock RPC, counterpart of lock.
Send commit request. Accepts optional confirmed as an argument and option timeout.
Send validate RPC. Accepts one argument, which can be either the literal candidate (to validate the contents of the candidate datastore) or a filename pointing to a file with full configuration to be validated; defaults to -, standard input.
Send copy-config RPC with running datastore as the source and startup datastore as target. Accepts no arguments or options.
Send copy-config RPC. Accepts a filename for the source configuration as a argument (defaults to -), and the db option for the target datastore.
Send edit-config RPC. Accepts the same set of arguments and options as copy-config.
Send get-schema RPC. Requires schema identifier as an argument.
Send create-subscription RPC. Requires notification stream identifier as an argument. The notifications received from the server are displayed on standard output while the session is active - i.e. makes sense either in an interactive mode or in command-line mode with the command sleep.
If none of the commands above is sufficient, a custom RPC can be send using this command. Accepts a filename (or - as default) as an argument; the file contents is sent to the server enveloped in the rpc element.
Do nothing, just sleep for given number of seconds provided as an argument.

As a backward-compatibility option, it is possible to provide a filename (or - for standard input) containing all messages that are supposed to be sent to the server, separated by the NETCONF transport v1.0 message separator. This option cannot be used with any other command. Note that RPC message-id is not preserved.


There are two sets of options: global options and command options. Global options affect overall behavior of the tool and can be provided in the shell command line (i.e. not to individual commands in the interactive mode). Command options affect individual commands and in interactive mode they need to be provided per command.

Global options

Display a usage message and exit.
Hostname or IP address of the NETCONF server.
Port number of the NETCONF server.
Username for the authentication on the server (defaults to admin).
Password for the authentication on the server (defaults to admin). If the option is provided without a value, the password is read from the terminal.
File containing the user’s private key.
Print all received replies in the original form. The option accepts one argument, name of file where the text should be stored; defaults to standard output.
Use plain TCP for the communication with the server (without this option SSH is used).
Do not actually send any RPCs, just display them to standard output.

Local options

As written above, local (or command) options are meaningful only for certain command.

Affects the format of the displayed RPC reply. By default, the reply is pretty-printed, but otherwise kept as is. The option accepts plain (do no pretty-printing) and noaaa (remove the aaa subtree from the reply from get or get-config requests).
Target datastore for some of the RPC operations. Defaults to running.
Timeout in seconds for confirmed commit.
Set default values handling. Accepted values are explicit, trim, report-all, report-all-tagged.
Set the XPath filter for get or subscribe requests.
Set a namespace prefix list; useful in case xpath option uses namespace prefixes.
Test-option value. Accepted values are test-only, test-then-set and set.
Value of the attribute nc:operation. Useful with the set operation, can be merge (the default), replace, create.
Value of the attribute nc:operation when used with the delete operation, can be remove (the default) or delete.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for netconf-console, version 2.3.0
Filename, size File type Python version Upload date Hashes
Filename, size netconf_console-2.3.0-py2.py3-none-any.whl (18.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size netconf-console-2.3.0.tar.gz (31.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page