NETCONF_Containerlab
cat topology.clab.yml
name: netconf-test-lab
topology:
nodes:
router1:
kind: nokia_srlinux
image: ghcr.io/nokia/srlinux:latest
client:
kind: linux
image: alpine:latest
exec:
- apk add --no-cache python3 py3-pip openssh
- pip install ncclient # Python NETCONF library
topology:
nodes:
router1:
kind: nokia_srlinux
image: ghcr.io/nokia/srlinux:latest
client:
kind: linux
image: alpine:latest
exec:
- apk add --no-cache python3 py3-pip openssh
- pip install ncclient # Python NETCONF library
sudo containerlab deploy -t topology.clab.yml
#Verifty
root@digi-oss:/home/labadmin# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac2e75143675 ghcr.io/nokia/srlinux:latest "/tini -- /usr/local…" 4 minutes ago Up 4 minutes clab-netconf-test-lab-router1
071ddc58f82d alpine:latest "/bin/sh" 4 minutes ago Up 4 minutes clab-netconf-test-lab-client
#Login to container
root@digi-oss:/home/labadmin# docker exec -it ac2e75143675 bash
root@router1:/# sr_cli
Loading environment configuration file(s): ['/etc/opt/srlinux/srlinux.rc']
Welcome to the Nokia SR Linux CLI.
--{ running }--[ ]--
A:root@router1# show interface brief
+---------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+
| Port | Admin State | Oper State | Speed | Type | Description |
+=====================+=============================+=============================+=============================+=============================+=============================+
| ethernet-1/1 | disable | down | 25G | | |
| ethernet-1/2 | disable | down | 25G | | |
A:root@router1#quit
other useful command - enter <candidate|running| startup>, info
#get the IP of the container to programmatically connect
root@digi-oss:/home/labadmin# docker inspect ac2e75143675 | grep IPAdd
"SecondaryIPAddresses": null,
"IPAddress": "",
"IPAddress": "172.20.20.6",
Setup python venv
python3 -m venv ~/pyang-venv
source ~/pyang-venv/bin/activate
Copy yang file from device to host-server to test yang browse with pyang
root@digi-oss:/home/labadmin/mohan# docker cp ac2e75143675://opt/srlinux/models/srl_nokia/models/interfaces/srl_nokia-interfaces.yang .
Install pyang for browsing yang-model
(pyang-venv) root@digi-oss:/home/labadmin/mohan# pip install pyang
(pyang-venv) root@digi-oss:/home/labadmin/mohan/test# pyang -f tree srl_nokia-interfaces.yang
module: srl_nokia-interfaces
+--rw interface* [name]
+--rw name srl_nokia-comm:interface-all
+--rw description? srl_nokia-comm:description
+--rw admin-state? srl_nokia-comm:admin-state
+--rw num-physical-channels? uint8 {srl_nokia-feat:num-physical-channels}?
+--rw breakout-mode! {srl_nokia-feat:port-breakout}?
| +--rw num-breakout-ports enumeration
| +--rw breakout-port-speed enumeration
| +--rw num-physical-channels? uint8 {srl_nokia-feat:num-physical-channels-breakout}?
+--rw mtu? uint16
+--rw loopback-mode? loopback-mode-type {not srl_nokia-feat:platform-vsrl}?
+--rw swap-src-dst-mac? boolean {srl_nokia-feat:loopback-mode-facility}?
NETCONF-SCRIPT
(pyang-venv) root@digi-oss:/home/labadmin/mohan/test# pip install ncclient
cat get_capabality.py
from ncclient import manager
with manager.connect(
host="172.20.20.6",
port=830,
username="admin",
password="NokiaSrl1!",
hostkey_verify=False
) as m:
for capability in m.server_capabilities:
print(capability)
#script-1
cat make_interface_up.py
from ncclient import manager
# Configuration XML to enable ethernet-1/1
# Namespace verified for SR Linux 2025/2026
config_data = """
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<interface xmlns="urn:nokia.com:srlinux:chassis:interfaces">
<name>ethernet-1/1</name>
<admin-state>enable</admin-state>
</interface>
</config>
"""
with manager.connect(
host='172.20.20.6',
port=830,
username='admin',
password='NokiaSrl1!',
hostkey_verify=False
) as m:
# 1. Push config to candidate datastore
m.edit_config(target='candidate', config=config_data)
# 2. Commit the changes to make them active in 'running'
m.commit()
print("Interface ethernet-1/1 enabled and committed.")
#script-2
cat int_description.py
from ncclient import manager
#import logging
# This will log the actual XML content to your console
#logging.basicConfig(level=logging.DEBUG)
# Configuration XML to enable ethernet-1/1
# Namespace verified for SR Linux 2025/2026
config_data = """
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<interface xmlns="urn:nokia.com:srlinux:chassis:interfaces">
<name>ethernet-1/1</name>
<description>happy_new_year_2026</description>
</interface>
</config>
"""
with manager.connect(
host='172.20.20.6',
port=830,
username='admin',
password='NokiaSrl1!',
hostkey_verify=False
) as m:
# 1. Push config to candidate datastore
m.edit_config(target='candidate', config=config_data)
# 2. Commit the changes to make them active in 'running'
m.commit()
print("Interface ethernet-1/1 desc added & committed.")
#verify from Device sr_cli
A:root@router1# show interface brief
+---------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+
| Port | Admin State | Oper State | Speed | Type | Description |
+=====================+=============================+=============================+=============================+=============================+=============================+
| ethernet-1/1 | enable | down | 25G | | happy_new_year_2026 |
| ethernet-1/2 | disable | down | 25G | | |
| Operation | ncclient method |
|---|---|
<get> | m.get() |
<get-config> | m.get_config() |
<edit-config> | m.edit_config() |
<lock> | m.lock() |
<unlock> | m.unlock() |
<commit> | m.commit() |
<discard-changes> | m.discard_changes() |
Comments
Post a Comment