Learn to program with the network
Get Started with the Cisco DNA Learning Track
From basic coding skills to using controller and devices level APIs, the Cisco DNA learning track walks you through getting started with network-powered apps.
See Learning Track
-->
Network Programmability for Application Developers
Learn about network programmability from the perspective of an Application Developer. Contains information about basic networking concepts in addition to interfaces like RESTCONF.
See Learning Track

IOS XE is Open and Programmable

Embedded into a Cisco DNA network are industry standard, open APIs from organizations such as the IETF and OpenConfig. In this demo, you will learn how to leverage the OpenConfig interfaces to do some configuration on a IOS XE device.

Python

                        
#!/usr/bin/env python
'''
Demo: Retrieve the list of interfaces and details from a router based
on the Open Config YANG Data Model.
'''

from ncclient import manager
import xml.dom.minidom

#  Import device details: HOST, PORT, USER, PASS
from credentials import *

# Get the full list of Interfaces based on the Open Config model
netconf_filter = '''
                             
''' print("\nGetting the Configuration of the Interface\n") # Connect to the device with NETCONF with manager.connect(host=HOST, port=PORT, username=USER, password=PASS, hostkey_verify=False, device_params={'name': 'default'}, allow_agent=False, look_for_keys=False) as m: # Send a <get> RPC to the device - config and state # response = m.get(netconf_filter) # Send a <get-config> RPC to the device response = m.get_config('running', netconf_filter) print("Returned NETCONF Data.\n") # Print out the raw returned XML print(xml.dom.minidom.parseString(response.xml).toprettyxml()) print("\n")

Response

                                <?xml version="1.0" ?>
<rpc-reply message-id="urn:uuid:5bae2174-9095-4458-a7a4-d8242ca00a48" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
	<data>
		<interfaces xmlns="http://openconfig.net/yang/interfaces">
			<interface>
				<name xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">GigabitEthernet3</name>
				<config>
					<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
					<name>GigabitEthernet3</name>
					<enabled>false</enabled>
				</config>
				<ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
					<config>
						<auto-negotiate>true</auto-negotiate>
					</config>
				</ethernet>
				<routed-vlan xmlns="http://openconfig.net/yang/vlan">
					<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
						<config>
							<enabled>false</enabled>
						</config>
					</ipv6>
				</routed-vlan>
			</interface>
		</interfaces>
	</data>
</rpc-reply>

                                
                            

Python

                        
#!/usr/bin/env python
'''
Demo: Retrieve the list of interfaces and details from a router based
on the Open Config YANG Data Model.
'''

from ncclient import manager
import xml.dom.minidom

#  Import device details: HOST, PORT, USER, PASS
from credentials import *

# Configure a Network Interface based on the Open Config Model
netconf_config = '''
<config>
 <interfaces xmlns="http://openconfig.net/yang/interfaces">
    <interface>
        <name>GigabitEthernet3</name>
               
<routed-vlan xmlns="http://openconfig.net/yang/vlan"> <ipv4 xmlns="http://openconfig.net/yang/interfaces/ip"> <addresses> <address> <ip>172.16.13.1</ip> <config> <ip>172.16.13.1</ip> <prefix-length>24</prefix-length> </config> </address> </addresses> </ipv4> </routed-vlan> </interface> </interface> </config> ''' print("\nSetting the Configuration of the Interface:") print(" Interface Name: GigabitEthernet 3") print(" Description: External Web Services - Secure") print(" Enabled: true") print(" IPv4 Address: 172.16.13.1/24") print("") # Connect to the device with NETCONF with manager.connect(host=HOST, port=PORT, username=USER, password=PASS, hostkey_verify=False, device_params={'name': 'default'}, allow_agent=False, look_for_keys=False) as m: # Send a <edit-config> RPC to the device response = m.edit_config(netconf_config, target='running') print("Returned NETCONF Message. \n") # Print out the raw returned XML print(xml.dom.minidom.parseString(response.xml).toprettyxml()) print("\n")

Response

                                <?xml version="1.0" ?>
<rpc-reply message-id="urn:uuid:d4232818-762e-4432-a58d-4c5c70a4cb15" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
	<ok/>
</rpc-reply>
                                
                            

Python

                        
#!/usr/bin/env python
'''
Demo: Retrieve the list of interfaces and details from a router based
on the Open Config YANG Data Model.
'''

from ncclient import manager
import xml.dom.minidom

#  Import device details: HOST, PORT, USER, PASS
from credentials import *

# Get the full list of Interfaces based on the Open Config model
netconf_filter = '''
                             
''' print("\nGetting the Configuration of the Interface\n") # Connect to the device with NETCONF with manager.connect(host=HOST, port=PORT, username=USER, password=PASS, hostkey_verify=False, device_params={'name': 'default'}, allow_agent=False, look_for_keys=False) as m: # Send a <get> RPC to the device - config and state # response = m.get(netconf_filter) # Send a <get-config> RPC to the device response = m.get_config('running', netconf_filter) print("Returned NETCONF Data.\n") # Print out the raw returned XML print(xml.dom.minidom.parseString(response.xml).toprettyxml()) print("\n")

Response

                                <?xml version="1.0" ?>
<rpc-reply message-id="urn:uuid:5bae2174-9095-4458-a7a4-d8242ca00a48" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
	<data>
		<interfaces xmlns="http://openconfig.net/yang/interfaces">
			<interface>
				<name xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">GigabitEthernet3</name>
				<config>
					<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
					<name>GigabitEthernet3</name>
					<enabled>true</enabled>
				</config>
				<ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
					<config>
						<auto-negotiate>true</auto-negotiate>
					</config>
				</ethernet>
				<routed-vlan xmlns="http://openconfig.net/yang/vlan">
					<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
						<config>
							<enabled>false</enabled>
						</config>
					</ipv6>
				</routed-vlan>
			</interface>
		</interfaces>
	</data>
</rpc-reply>

                                
                            
Want to learn more?
Download The Code View the Learning Lab

Access Cisco Innovation through APIs

Cisco networks include many innovative technologies that are made available through native YANG models and interfaces such as NETCONF and RESTconf. In this demo, you can learn to programmatically add a new virtual network with the "Cisco-IOS-XE" data models for VRF, BGP and interfaces.

Python

                        
#!/usr/bin/env python
'''
Demo: Retrieve the details of a standard VRF Configuration
using the Cisco IOS XE Data Models
'''

from ncclient import manager
import xml.dom.minidom

#  Import device details: HOST, PORT, USER, PASS
from credentials import *

# Get the full list of Interfaces based on the Open Config model
netconf_filter = 
print("\nGetting the Configuration from the router.\n") # Connect to the device with NETCONF with manager.connect(host=HOST, port=PORT, username=USER, password=PASS, hostkey_verify=False, device_params={'name': 'default'}, allow_agent=False, look_for_keys=False) as m: # Send a <get> RPC to the device - config and state # response = m.get(netconf_filter) # Send a <get-config> RPC to the device response = m.get_config('running', netconf_filter) print("Returned NETCONF Data.\n") # Print out the raw returned XML print(xml.dom.minidom.parseString(response.xml).toprettyxml()) print("\n"))

Response

                                <?xml version="1.0" ?>
<rpc-reply message-id="urn:uuid:fa4fae2c-5eda-4e17-823c-e7cacaaa9c40" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
	<data>
		<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
			<router>
				<bgp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-bgp">
					<id>200</id>
					<bgp>
						<log-neighbor-changes/>
					</bgp>
					<address-family>
						<no-vrf>
							<ipv4>
								<af-name>unicast</af-name>
							</ipv4>
						</no-vrf>
					</address-family>
				</bgp>
			</router>
		</native>
	</data>
</rpc-reply>

                                
                            

Python

                        
#!/usr/bin/env python
'''
Demo: Configure a new standard VRF Configuration
using the Cisco IOS XE Data Models
'''

from ncclient import manager
import xml.dom.minidom

#  Import device details: HOST, PORT, USER, PASS
from credentials import *

# Configure a
netconf_config = '''
<config>
    <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
        <ip>
            <vrf>
                <name></name>
                <rd>65000:3</rd>
                <route-target>
                    <direction>export</direction>
                    <target>65000:3</target>
                </route-target>
                <route-target>
                    <direction>import</direction>
                    <target>65000:3</target>
                </route-target>
            </vrf>
        </ip>
        <interface>
            <GigabitEthernet>
                <name>2.3</name>
                <encapsulation>
                    <dot1Q>
                        <vlan-id>13</vlan-id>
                    </dot1Q>
                </encapsulation>
                <ip>
<address> <primary> <address>192.168.13.2</address> <mask>255.255.255.252</mask> </primary> </address> </ip> </GigabitEthernet> <Loopback> <name>13</name> <ip> <vrf> <forwarding> <word></word> </forwarding> </vrf> <address> <primary> <address>192.168.120.3</address> <mask>255.255.255.255</mask> </primary> </address> </ip> </Loopback> </interface> <router> <bgp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-bgp"> <id>200</id> <neighbor> <id>192.168.13.1</id> <remote-as>100</remote-as> </neighbor> <address-family> <with-vrf> <ipv4> <af-name>unicast</af-name> <vrf> <name></name> <neighbor> <id>192.168.13.1</id> <remote-as>100</remote-as> <activate/> </neighbor> <redistribute> <connected/> </redistribute> </vrf> </ipv4> </with-vrf> </address-family> </bgp> </router> </native> </config> ''' print("\nAdding a new VRF Configuration:") print(" Peering Interface: GigabitEthernet2.3") print(" IP: 192.168.13.2") print(" BGP Neighbor: 192.168.13.1") print("") # Connect to the device with NETCONF with manager.connect(host=HOST, port=PORT, username=USER, password=PASS, hostkey_verify=False, device_params={'name': 'default'}, allow_agent=False, look_for_keys=False) as m: # Send a <edit-config> RPC to the device response = m.edit_config(netconf_config, target='running') print("Returned NETCONF Message. \n") # Print out the raw returned XML print(xml.dom.minidom.parseString(response.xml).toprettyxml()) print("\n")

Response

                                <?xml version="1.0" ?>
<rpc-reply message-id="urn:uuid:d4232818-762e-4432-a58d-4c5c70a4cb15" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
	<ok/>
</rpc-reply>
                                
                            

Python

                        
#!/usr/bin/env python
'''
Demo: Retrieve the details of a standard VRF Configuration
using the Cisco IOS XE Data Models
'''

from ncclient import manager
import xml.dom.minidom

#  Import device details: HOST, PORT, USER, PASS
from credentials import *

# Get the full list of Interfaces based on the Open Config model
netconf_filter = 
print("\nGetting the Configuration from the router.\n") # Connect to the device with NETCONF with manager.connect(host=HOST, port=PORT, username=USER, password=PASS, hostkey_verify=False, device_params={'name': 'default'}, allow_agent=False, look_for_keys=False) as m: # Send a <get> RPC to the device - config and state # response = m.get(netconf_filter) # Send a <get-config> RPC to the device response = m.get_config('running', netconf_filter) print("Returned NETCONF Data.\n") # Print out the raw returned XML print(xml.dom.minidom.parseString(response.xml).toprettyxml()) print("\n"))

Response

                                <?xml version="1.0" ?>
<rpc-reply message-id="urn:uuid:db8d516a-9e39-4ca3-a273-7f077856302e" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
	<data>
		<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
			<ip>
				<vrf>
					<name>VRF-DEMO3</name>
					<rd>65000:3</rd>
					<route-target>
						<direction>export</direction>
						<target>65000:3</target>
					</route-target>
					<route-target>
						<direction>import</direction>
						<target>65000:3</target>
					</route-target>
				</vrf>
			</ip>
			<interface>
				<GigabitEthernet>
					<name xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">2.3</name>
					<encapsulation>
						<dot1Q>
							<vlan-id>13</vlan-id>
						</dot1Q>
					</encapsulation>
					<ip>
						<vrf>
							<forwarding>
								<word>VRF-DEMO3</word>
							</forwarding>
						</vrf>
						<address>
							<primary>
								<address>192.168.13.2</address>
								<mask>255.255.255.252</mask>
							</primary>
						</address>
					</ip>
				</GigabitEthernet>
				<Loopback>
					<name>13</name>
					<ip>
						<vrf>
							<forwarding>
								<word>VRF-DEMO3</word>
							</forwarding>
						</vrf>
						<address>
							<primary>
								<address>192.168.120.3</address>
								<mask>255.255.255.255</mask>
							</primary>
						</address>
					</ip>
				</Loopback>
			</interface>
			<router>
				<bgp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-bgp">
					<id>200</id>
					<bgp>
						<log-neighbor-changes/>
					</bgp>
					<neighbor>
						<id>192.168.13.1</id>
						<remote-as>100</remote-as>
					</neighbor>
					<address-family>
						<with-vrf>
							<ipv4>
								<af-name>unicast</af-name>
								<vrf>
									<name>VRF-DEMO3</name>
									<neighbor>
										<id>192.168.13.1</id>
										<remote-as>100</remote-as>
										<activate/>
									</neighbor>
									<redistribute>
										<connected/>
									</redistribute>
								</vrf>
							</ipv4>
						</with-vrf>
						<no-vrf>
							<ipv4>
								<af-name>unicast</af-name>
								<neighbor>
									<id>192.168.13.1</id>
									<activate/>
								</neighbor>
							</ipv4>
						</no-vrf>
					</address-family>
				</bgp>
			</router>
		</native>
	</data>
</rpc-reply>

                                
                            
Want to learn more?
Download The Code View the Learning Lab

The Network Joins the Discussion with ChatOps

See how application developers can leverage the power of the network by building applications and integrating them with network technologies such as Embedded Event Manager (EEM). Build applications that react in realtime to network events and analytics data.

Changing the Description of the Management Interface
It is important to monitor for changes to configurations, and be alerted as soon as possible should a critical configuration be changed. In this demo we will change the description of the Management Interface of an IOS XE device, which will then send an alert to the Network Operations team via a Cisco Webex Teams
Config

Python

                        
#!/usr/bin/env python
'''
Demo: Trigger a notification about config change.
'''

from ncclient import manager
import xml.dom.minidom

#  Import device details: HOST, PORT, USER, PASS
from credentials import *
from random import randint

# Get a random integer to use
rint = randint(1,100)

# Configure a Network Interface based on the Open Config Model
netconf_config = '''
<config>
 <interfaces xmlns="http://openconfig.net/yang/interfaces">
    <interface>
        <name>GigabitEthernet1</name>
       
</interface> </interface> </config> '''.format(rint) print("\nChanging the Description of the Management Interface") print("") # Connect to the device with NETCONF with manager.connect(host=HOST, port=PORT, username=USER, password=PASS, hostkey_verify=False, device_params={'name': 'default'}, allow_agent=False, look_for_keys=False) as m: # Send a <edit-config> RPC to the device response = m.edit_config(netconf_config, target='running') print("Returned NETCONF Message. \n") # Print out the raw returned XML print(xml.dom.minidom.parseString(response.xml).toprettyxml()) print("\n")

Network Operations with Cisco Webex Teams

Want to learn more?
Download The Code View the Learning Lab
Other Resources IOS XE https://developer.cisco.com/site/ios-xe _blank Open and programmable operating system optimized for the next generation of enterprise campus and wide area networks. Automate with Python https://developer.cisco.com/site/python _blank Sample code, SDKs, and toolkits to help you get started with programming the network in Python. Network Plug and Play https://developer.cisco.com/site/network-plug-n-play A simple, integrated offering for enterprise network customers to ease new branch or campus device rollouts or for provisioning updates to an existing network. Software Defined Access https://developer.cisco.com/site/ios-xe/ _blank SD-Access provides an open, software-driven platform that integrates virtualization, automation, analytics, and cloud, into a unified architecture from the edge to the cloud. Cisco DNA https://developer.cisco.com/site/ios-xe/ _blank Cisco DNA is an open, software-driven approach that creates a single network automation and analytics throughout your organization. NETCONF https://developer.cisco.com/site/network-plug-n-play/ _blank Imagine all of your routers and switches using the same data models and protocols across the network. Cisco is embracing NETCONF/RESTCONF and YANG models, the new industry standard device interfaces and data models, to make the automation and configuration process simpler. IOS XE Programmability Sandbox The "IOS XE Programmability" Sandbox provides an environment where developers and network engineers can explore the programmability options available within IOS XE. VIEW ALL https://developer.cisco.com/docs/ios-xe/#!sandboxes _blank /img/ios-xe-csr-reserve-rec.png IOS XE on CSR Recommended Code https://devnetsandbox.cisco.com/RM/Diagram/Index/cae403c2-27af-4c7d-b1e1-99b7d42f1504?diagramType=Topology _blank IOS XE on CSR Recommended Code The IOS XE version 16.9.3 on CSR Recommended Code Sandbox offers developers access to an IOS XE device running the current recommended IOS XE code release available on cisco.com (currently 16.9.3). NOTE: the code release provided in this sandbox is updated as the recommended code version from the BU changes. (approximately every 12 months) Reserve now https://devnetsandbox.cisco.com/RM/Diagram/Index/cae403c2-27af-4c7d-b1e1-99b7d42f1504?diagramType=Topology _blank button btn-primary btn-lg-wider

Join DevNet

DevNet helps you get your questions answered so you can keep your project moving.