← Engineering articles

Practical guide and proposed lab · Model-driven APIs

ncclient get_config Timeout: Should You Filter Before Raising Limits?

Investigate ncclient get_config timeouts with scoped filters, expected-node validation and separate RPC error states. Includes a proposed lab.

A broad configuration response narrowed through a filter — conceptual illustration

What you’ll learn

  • A broad retrieval may collect more data than the task needs.
  • A filter with the wrong namespace can return misleadingly little data.
  • Measure before choosing an RPC deadline.

A NETCONF client connects successfully but waits too long for configuration data. The connection stage and the RPC stage need separate evidence. Before choosing a much larger timeout, determine whether the application needs the entire configuration or one small subtree.

Lab status: This is a proposed exercise, not a completed device test or client case study. Code examples require validation against your image and dependency versions. My documented background is NOC/data center operations, multi-vendor Netmiko workflows and Python/Flask integration.

Offline example checks: October 20, 2026: the added helper/demo block executed with local fixtures, and related negative cases were checked offline. No live device, controller, fabric or service behavior was validated.

What can delay a get_config RPC after connection succeeds?

The requested dataset, device implementation, server load and transport conditions can all affect completion. XML processing on the client is another stage to measure. Do not treat elapsed time as proof of a particular root cause without comparing a smaller known-good request.

Measure authentication/session creation separately from RPC response and local XML parsing. A long response and a missing schema node are different faults. Keep timeouts finite and avoid launching repeated broad reads while diagnosing a busy management plane.

How can a subtree filter reduce the requested configuration?

A namespace-correct filter can reduce both server reply size and client parse work. A wrong namespace may return an empty data tree quickly. Validate the expected hostname or interface node before treating lower elapsed time as an improvement.

Measure the request you actually need
Conceptual diagnostic sequence; no measured outcomes or real device screenshots are shown. Open full-size diagram.

Proposed GNS3/EVE-NG lab: compare broad and scoped reads

Use one supported IOS XE native hostname and fixed concurrency. Record the image, ncclient version and filter XML. A short deliberately invalid filter is an offline/authorized negative case; no benchmark numbers are supplied. Repeat only within the agreed lab load.

Python: time a scoped NETCONF configuration request

The additional function distinguishes RPC timeout, rpc-error, invalid XML and missing expected node. It assumes an already connected, verified ncclient manager. A transport/session exception is deliberately allowed to reach the job boundary because it is not the same as an RPC deadline. Returned hostname text is internal inventory data; restrict its logs.

from time import monotonic

subtree = '''<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
  <hostname/>
</native>'''
session.timeout = 30
started = monotonic()
reply = session.get_config(source='running', filter=('subtree', subtree))
xml = reply.data_xml
print({'elapsed_seconds': round(monotonic() - started, 3),
       'response_bytes': len(xml.encode('utf-8'))})

Worked Python example and input contract

import time
import xml.etree.ElementTree as ET

def read_hostname(session):
    from ncclient.operations.errors import TimeoutExpiredError
    from ncclient.operations.rpc import RPCError
    subtree = '<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"><hostname/></native>'
    session.timeout = 30
    started = time.monotonic()
    try:
        reply = session.get_config(source='running', filter=('subtree', subtree))
        root = ET.fromstring(reply.data_xml)
        node = root.find('.//{http://cisco.com/ns/yang/Cisco-IOS-XE-native}hostname')
        if node is None or not node.text:
            return {'state': 'missing_expected_node'}
        return {'state': 'collected', 'hostname': node.text,
                'rpc_seconds': round(time.monotonic()-started, 3)}
    except TimeoutExpiredError:
        return {'state': 'rpc_timeout'}
    except RPCError as exc:
        return {'state': 'rpc_error', 'error_tag': exc.tag}
    except ET.ParseError:
        return {'state': 'invalid_xml'}

# With an established verified ncclient manager named session:
# result = read_hostname(session)
# No network operation occurs merely by defining this function.

Should you increase the RPC timeout or narrow the query?

If valid scoped reads consistently need more time, adjust a measured finite RPC deadline. If data requirements are narrower than the query, reduce scope first. A service worker also needs a total job deadline; the manager timeout is not a universal bound on DNS, connection and all subsequent work.

What should a configuration collector report to operators?

Keep last successful observation separate from the latest attempt and include filter identity and error stage. Add concurrency limits per device, not just per web user. An API endpoint that spawns unrestricted collectors can overload the same router repeatedly.

How should you verify retrieval reliability?

Run content checks on every measured response, record sample count and report all failures. Compare broad/scoped requests only after both return the required node. A synthetic function test verifies state handling, not server performance.

Explore the network automation troubleshooting collection to connect this issue to adjacent workflows. The Netmiko, NETCONF and RESTCONF comparison helps when you are choosing an interface rather than fixing an existing implementation.

Technical references

Discuss a related technical problem

Is a NETCONF collector slow or unreliable?

Share the platform, filter, approximate response size and sanitized error. I can assess a scoped retrieval and reporting workflow with clear failure handling.

Discuss your project Review Imran Sarwar’s experience

Remote English-language inquiries: USA, UK, Canada, Europe and beyond. UAE-based (UTC+4); working overlap is agreed per project.