ncclient is a Python library that facilitates client-side scripting and application development around the NETCONF protocol. It aims to offer an intuitive API that maps XML-encoded NETCONF to Python constructs, making network-management scripts easier. The library is currently at version 0.7.1 and is actively maintained with releases happening periodically based on feature additions and bug fixes.
pip install ncclientVerified import paths — ran on the pinned version, not inferred.
This quickstart connects to a NETCONF-enabled device, retrieves its capabilities, and then fetches a filtered portion of the running configuration. It uses environment variables for connection details for security and flexibility. The `hostkey_verify=False` is used here for simplicity, but should be replaced with proper host key verification in production environments.
Review `manager.connect` parameters and test connectivity thoroughly after upgrading. If encountering issues, ensure parameters are compatible with the chosen transport (`Paramiko` or `ssh-python`).
Upgrade Python to 3.7 or newer. The library's `requires_python` is `>=3.7`.
Decide which SSH transport is preferred. If `ssh-python` is desired, install with `pip install ncclient[libssh]` and ensure `libssh` is installed on the system. Otherwise, `pip install ncclient` will use Paramiko.
Implement proper host key verification in production. This usually involves setting `hostkey_verify=True` and managing `known_hosts` files or providing host keys explicitly.
Review asynchronous code, especially if migrating from older versions. Check official documentation or examples for the correct `async_mode` usage with recent Python versions.
Always specify the correct `device_params` name for the target device vendor (e.g., `{'name': 'junos'}` for Juniper, `{'name': 'nexus'}` for Cisco Nexus, `{'name': 'huawei'}` for Huawei). Refer to documentation for a full list of supported handlers.Introduce a `time.sleep()` delay before `manager.connect()` calls if making rapid, successive connections. Verify the remote NETCONF server is not overloaded or configured with strict rate limits. Ensure SSH parameters are compatible.
Carefully review the XML payload against the device's YANG models and NETCONF capabilities to ensure all mandatory elements, especially `target` and `source` in `copy-config` or `edit-config`, are correctly included and formatted according to the device's expectations.
Ensure all NETCONF-specific elements (e.g., `<rpc>`, `<edit-config>`, `<config>`) are properly prefixed with `nc:` and that the `nc` prefix is bound to the correct NETCONF namespace `xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"` in the root `<rpc>` tag.
Increase the `timeout` parameter during the `manager.connect()` call to allow more time for the capability exchange. Verify network connectivity to the NETCONF server and ensure the server is running and responsive.