NETCONF /YANG with a 9800 Part 4: A Simple Python Program To Update Tags on the 9800

So we have seen how to get information from the 9800 via NETCONF/ YANG now lets look at how we update config on the 9800.

For this we are going to focus on adding the mapping of an access point to its tags. Normally to do this via the CLI we would use these commands

9800WLC(config)#ap <Ethernet MAC Address>
9800WLC(config-ap-tag)#policy-tag <Policy Tag Name>
9800WLC(config-ap-tag)#rf-tag <RF Tag Name>
9800WLC(config-ap-tag)#site-tag <Site Tag Name>

First we need to find which model the tags are under, for this we use the Advanced NETCONF Explorer, I used the Search nodes feature on the word tags and found them.

I then opened the NETCONF Console and instead of selecting “GET” I selected <edit-config> (Merge)

What the text shows is all the calls to update config on the 9800. worth noting that the <!– and -> are being used to comment out the fields we going to need to delete this later on. Take a copy of the test to use later on

Ok lets setup our Python program, I”m making the assumption that all dependancies are installed already. Will call this one

So we going to import the dependancies and setup the Netconf connection as before

    author:     Haydn Andrews 
    date:       13/07/2020  

    modification history:
    what    when            who     why
    v1.0    13/07/2020      HA      Initial version

#Import Dependencies
from ncclient import manager
from jinja2 import Template

# NETCONF Connection Manager
m = manager.connect(host='', port=830, username='admin',
                    password='P@ssword1', device_params={'name': 'csr'})

We now going to build a Jinja template so we can use variables for future use cases. For this we going to create a file called “updateap.xml” and put the following into it

	<ap-cfg-data xmlns="">
			<ap-tag xmlns="">
			<ap-mac xmlns="">{{ MAC_ADDRESS}}</ap-mac>
			<policy-tag xmlns="">{{ POLICY_TAG }}</policy-tag>
			<site-tag xmlns="">{{ SITE_TAG }}</site-tag>
			<rf-tag xmlns="">{{ RF_TAG }}</rf-tag>

So what we can see we have taken all the config between the <config> and </config> as well as the <config></config> tags

We have also updated the Jinja variables.

We now add the following to the Python Program to utilise this template and update an AP to tag mappings

MACAddress = '88:1d:fc:41:5d:dd'

# Render Jinja Template, we going to update add a static mapping for an AP to its Tags
tags_template = Template(open('updateap.xml').read())
tags_rendered = tags_template.render(
        MAC_ADDRESS= MACAddress,
        POLICY_TAG= 'test2',
        SITE_TAG= 'test2',
        RF_TAG= 'test2'

# Execute the netconf update to the device
result = m.edit_config(target='running', config=tags_rendered)

Before we run the program lets take a look at how the Static AP Tags are currently setup:

Now we run the script


After the execution of the program, you should see and “ok” RPC reply from the 9800 indicating that it completed successfully.

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:53868425-922e-4d1b-be4a-e7dafa02691a">
   <ok />

Then if we look back at the 9800 Tags we can see

So now we can get data and edit data from the 9800 via NETCONF / YANG. My next challenge will be how do I delete something from the 9800 if and when I work that out I’ll do another post on this topic.

I have uploaded all these Python Programs to my Github account

2 thoughts on “NETCONF /YANG with a 9800 Part 4: A Simple Python Program To Update Tags on the 9800

  1. Hello Haydn,

    First of all, thanks for the great posts around netconf and the 9800!

    One question, do you have to set the xmlns part every time? You are already in the ap-cfg-data model where you set the reference, so do you need to repeat that?

    Best regards,



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s