#!/usr/bin/env python3 """ gNMI gRPC Configuration Script =============================== Enables gRPC dial-in telemetry on all 9 IOS-XR routers so that Telegraf (or any gNMI collector) can subscribe to streaming telemetry data. What this script applies per router: - gRPC server on port 57400 with TLS disabled - YANG model: Cisco-IOS-XR-man-ems-cfg Router targets: CORE-01 (10.100.0.100) CORE-02 (10.100.0.200) R9K-01 (10.100.0.1) through R9K-07 (10.100.0.7) """ from ncclient import manager import sys GRPC_NS = 'http://cisco.com/ns/yang/Cisco-IOS-XR-man-ems-cfg' ROUTERS = [ ('10.100.0.100', 'CORE-01'), ('10.100.0.200', 'CORE-02'), ('10.100.0.1', 'R9K-01'), ('10.100.0.2', 'R9K-02'), ('10.100.0.3', 'R9K-03'), ('10.100.0.4', 'R9K-04'), ('10.100.0.5', 'R9K-05'), ('10.100.0.6', 'R9K-06'), ('10.100.0.7', 'R9K-07'), ] GRPC_CONFIG_XML = """ 57400 """ def configure_router(mgmt_ip, label): """Apply gRPC configuration via NETCONF edit-config + commit.""" print(f"\n{'─'*60}") print(f" Configuring {label} ({mgmt_ip})") print(f"{'─'*60}") print(f" Applying: gRPC port=57400 no-tls") try: with manager.connect( host=mgmt_ip, port=830, username='webui', password='cisco', hostkey_verify=False, device_params={'name': 'iosxr'}, timeout=20, ) as m: print(" → Applying gRPC configuration...") m.edit_config(target='candidate', config=GRPC_CONFIG_XML) print(" → Committing...") m.commit() print(f" ✓ {label} done.") return True except Exception as e: print(f" ✗ ERROR on {label}: {e}") return False def verify_router(mgmt_ip, label): """Re-read running config to confirm the grpc block is present.""" try: with manager.connect( host=mgmt_ip, port=830, username='webui', password='cisco', hostkey_verify=False, device_params={'name': 'iosxr'}, timeout=10 ) as m: filt_grpc = """ """ r_grpc = m.get_config(source='running', filter=filt_grpc) has_grpc = '57400' in str(r_grpc) has_notls = '