Showing results for 
Search instead for 
Did you mean: 
Cisco Employee

How to retrieve the interface configuration

How to retrieve the interface configuration??

I saw the "", the process is just "pass"

def process_interface_configurations(interface_configurations):

    """Process data in interface_configurations object."""


I tried to modified a bit but I got the response "None".

def process_interface_configurations(interface_configurations):

    """Process data in interface_configurations object."""


    print ('interface name: ',int.interface_name)

I believe it should be a list of configuration... but don't know how it should be...

any sample can be reference???

Thanks a lot!!

Cisco Employee

All basic sample apps in the range of 10-19 are boilerplates (templates).  Those boilerplates do no processing and provide no output.  The convention should be described in the README:

ydk-py-samples/samples/basic at master · CiscoDevNet/ydk-py-samples · GitHub

Now, for a sample implementation of processing interface config, here's a very simple function to print the interface names:

def process_interface_configurations(interface_configurations):

    """Process data in interface_configurations object."""

    for interface_configuration in interface_configurations.interface_configuration:


The entire configuration hierarchy is documented at:

The function above produces the following output when the script is run against one of my routers:





Hope that helps!

Million Thanks!! IT works like a charm! I now start understand the idea to learn ydk.

One more question, is there a way to read all configurations under a specific interface??

Sure thing.  Note that the object passed to really acts as a filter.  So, you need to construct an object with an interface with the name you're interested in.  Interface name is the key of the list of interfaces defined in the model:

# create read filter for mgmt interface

interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()

interface_configuration = interface_configurations.InterfaceConfiguration()

interface_configuration.interface_name ="MgmtEth0/RP0/CPU0/0"


# read data from NETCONF device

interface_configurations =, interface_configurations)

Actually, you can be more clever and just instantiate the class that defines an interface.  YDK will do the right thing and build the proper filter with the full hierarchy even though you are reading a more specific object:

# create read filter for mgmt interface

interface_configuration = xr_ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration()

interface_configuration.interface_name ="MgmtEth0/RP0/CPU0/0"

# read data from NETCONF device

interface_configuration =, interface_configuration)

Let's say we just want to print the interface description once read:


Here's a sample output on a mgmt interface with an obvious description:

$ ./ ssh://admin:admin@router



Here's the full app log:

$ ./ ssh://admin:admin@router -v

2016-12-13 14:44:10,148 - ydk.providers.netconf_provider - INFO - NetconfServiceProvider connected to router:None using ssh

2016-12-13 14:44:10,211 - - INFO - READ operation initiated

2016-12-13 14:44:10,213 - ydk.providers._provider_plugin - DEBUG -

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:63dbbab9-2cce-48e8-8437-832206be1989">


    <filter type="subtree">

      <interface-configurations xmlns="">








2016-12-13 14:44:10,277 - ydk.providers._provider_plugin - DEBUG -

<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:63dbbab9-2cce-48e8-8437-832206be1989">


    <interface-configurations xmlns="">




        <description>*** MANAGEMENT INTERFACE ***</description>

        <ipv4-network xmlns="">












2016-12-13 14:44:10,278 - - INFO - READ operation completed


2016-12-13 14:44:10,500 - ydk.providers.netconf_provider - INFO - NetconfServiceProvider disconnected from router using ssh


Hope that helps!

How do you print the whole XML interface in a single print statement?  Similar to what is in the rpc-reply data group?

The codec service decodes and encodes data. The ydk-py-samples repo has numerous sample apps using codec service.


Thank you for pointing me over to codec service.... which I tried but they are not working so well for me.

I've tried the examples:

I've uncommented the print statement in each, ran similar to: (like README example says to) ssh://jb:password@abc.123

And get:

usage: [-h] [-v] error: unrecognized arguments: ssh://jb:password@abc.123

Running the script, as is, gives me simply this output:

<interface-configurations xmlns=""/>

Also, if I'm looking for decode, I'm seeing no examples?

Codec executes local encoding/decoding:

./  # <-- no need for credentials

if you read the description at  you'll see that the basic samples in the 10-19 range are boilerplates (templates).  They contain no configuration.   For interfaces, there are samples from 20 through 36 with useful configuration.  For instance:

ydk-py-samples/ at master · CiscoDevNet/ydk-py-samples · GitHub

and it's XML output:

ydk-py-samples/cd-encode-xr-ifmgr-cfg-36-ydk.xml at master · CiscoDevNet/ydk-py-samples · GitHub

As the help string indicates, the codec sample apps take no argument to connect to a device.  These apps only encode a Python object into XML and print the resulting string.  Hope this clarifies. 

It is helpful, but I was hoping to print a router's interface XML information via my own print command, not something local.

It would be like ...

1. set the provider variable with router info, username, password

2. set interface filter

3. then print like:   print( <????>(provider, interface_configurations))


this would print out the complete router's interface, or whatever I've may have filtered on... like a specific interface-name.

If you're looking at an XML-centric use case, it may be that an approach other than the YDK is what you're looking for. For example, you might want to use the ncclient library directly. You can see samples of how to use ncclient here:

You can see sample filters to use with the script at:

These are just standard netconf subtree filters that can be used with get/get_config from ncclient, as shown in the script



Thank you einarnn and saalvare for your patience, responses and help!   Einar, I will take a look at that.  I'm not seeing what I need in the ydk, but I know what I'm looking for has to be possible.

The reason I figured there has to be a way to be able to print the entire interface is because every time I run one of the ifmgr tests, I see the whole interface print as standard out from some internal processing.  I was guessing somewhere embedded in the, like, processing, it is outputting all of an interface' XML, it's pulling the whole thing... because I'm seeing it flash on my screen!  It would be nice if that raw XML was a part of the structure (or dictionary? class?  Sorry, I'm not a python expert.) that is returned from that



I believe you can get the interface by using the following or similar XML via netconf session:

<?xml version="1.0" encoding="UTF-8"?>

<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">




               <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">






That should give you an xml configuration which contains information about interfaces.

If you are using ncclient on python, you can make a variable containing the filter part of the xml (highlighted in bold above) and use it on ncclient

Example (assuming my_nc as ncclient instance that is already connected to your router)

my_filter= """


               <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">





result = my_nc.get_config("running", my_filter)

You can then parse result to get the info that you want. Python has a lot of module dealing with xml (minidom, elementree, xmltodict...)

For example, this one will give you an indented XML view of the result

     report = xml.dom.minidom.parseString(result.xml)


I hope that helps.

Hi Vincent. Do you happen to have any current working example using ncclient towards XR device with the filter like in your post? I am not able to find anything working on Internet. And the examples/documentation on the git/ncclient is not quite help for me I would appreciate anything as I am just getting just errors and errors.... Started being little bit frustrated


Hmmmmm I found Einars baby the "ncc" (very valuable resource for ncclient):

Content for Community-Ad

This widget could not be displayed.