cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1247
Views
10
Helpful
5
Replies

Netconf not getting interface config from CSR1000V

Difan Zhao
Level 5
Level 5

I am playing with the Netconf. I have tried both copying/pasting the XML code and with the python ncclient library. Here is my code for getting the entire router config. 

--- XML ---

<?xml version="1.0" encoding="UTF-8" ?>
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <get-config>
        <source>
            <running/>
        </source>
    </get-config>
</rpc>
]]>]]>

--- python ncclient ---

from ncclient import manager
iosxe_manager = manager.connect(...)
iosxe_config = iosxe_manager.get_config('running')

In the result, I see the Gi1 interface but there is no IP associated with it. It says "DHCP" in it. Any idea why?

<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:7a39cf1f-09d9-45ac-8a6c-58c389fa8088">
    <data>
        <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
          ...
            <interface>
                <GigabitEthernet>
                    <name>1</name>
                    <ip>
                        <address>
                            <dhcp/>
                        </address>
                        <nat xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-nat">
                            <outside/>
                        </nat>
                    </ip>
                    <mop>
                        <enabled>false</enabled>
                        <sysid>false</sysid>
                    </mop>
                    <negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
                        <auto>true</auto>
                    </negotiation>
                </GigabitEthernet>
              ...
            </interface>
            ...
        </native>
        ...
    </data>
</rpc-reply>

I have tried with both 17.2 and 16.12 IOS on the CSR1000v and I am getting the same result..

BTW, is there recommended reading about how to come up with the XML based on the Yang model file, other than reading the RFC? I am curious to know how people comes out with the XML file. 

Thanks!

Difan

 

 

 

1 Accepted Solution

Accepted Solutions

Mike LWF
Level 1
Level 1

Hi Difan,

I'm a beginner myself, but I think what you get is normal and expected.

There are different APIs to work with network devices.  NETCONF is used to read/write configuration.  If you use NETCONF <get-config> to read the configuration, it is the equivalent of router command "show running-config", see below:

interface GigabitEthernet1
 ip address dhcp
 negotiation auto
 no mop enabled
 no mop sysid
end

What you see above is what NETCONF gets.

If your intent is to retrieve the dynamic IP assigned to an interface, you should use REST API instead of NETCONF.  https://www.cisco.com/c/en/us/td/docs/routers/csr1000/software/restapi/restapi/RESTAPIipinterface.html

Hope this helps!

View solution in original post

5 Replies 5

yangorelik
Spotlight
Spotlight

Hello Difan

You use YDK to serialize data model to XML and build RPC, then send it to device using NetconfServiceProvider. When getting response from device you deserialize XML payload back to data model.

Yan Gorelik
YDK Solutions

Hi Yan, thanks for the information. I will do some research about the YDK. I am still wondering how you write the XML based on the Yang model file. Could you point me to some instructions? Thanks.

Hi Difan

I suggest you to look at YDK documentation (ydk.cisco.com) and analyze some samples on GitHub (https://github.com/CiscoDevNet/ydk-py-samples/tree/master/samples/basic/codec/models/openconfig ).

Yan Gorelik
YDK Solutions

Mike LWF
Level 1
Level 1

Hi Difan,

I'm a beginner myself, but I think what you get is normal and expected.

There are different APIs to work with network devices.  NETCONF is used to read/write configuration.  If you use NETCONF <get-config> to read the configuration, it is the equivalent of router command "show running-config", see below:

interface GigabitEthernet1
 ip address dhcp
 negotiation auto
 no mop enabled
 no mop sysid
end

What you see above is what NETCONF gets.

If your intent is to retrieve the dynamic IP assigned to an interface, you should use REST API instead of NETCONF.  https://www.cisco.com/c/en/us/td/docs/routers/csr1000/software/restapi/restapi/RESTAPIipinterface.html

Hope this helps!

Mike LWF
Level 1
Level 1

It looks like NETCONF can also get the dynamic IP assigned to an interface.  We just need to use a different YANG model.  I tried "Cisco-IOS-XE-interfaces-oper.yang" and it worked.  Not sure if there are any standard YANGs that can do the same.  Here's the code from YANG Explorer:

import lxml.etree as ET
from argparse import ArgumentParser
from ncclient import manager
from ncclient.operations import RPCError

payload = """
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <interfaces xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-interfaces-oper">
    <interface>
      <ipv4/>
      <ipv4-subnet-mask/>
    </interface>
  </interfaces>
</filter>
"""

if __name__ == '__main__':

    parser = ArgumentParser(description='Usage:')

    # script arguments
    parser.add_argument('-a', '--host', type=str, required=True,
                        help="Device IP address or Hostname")
    parser.add_argument('-u', '--username', type=str, required=True,
                        help="Device Username (netconf agent username)")
    parser.add_argument('-p', '--password', type=str, required=True,
                        help="Device Password (netconf agent password)")
    parser.add_argument('--port', type=int, default=830,
                        help="Netconf agent port")
    args = parser.parse_args()

    # connect to netconf agent
    with manager.connect(host=args.host,
                         port=args.port,
                         username=args.username,
                         password=args.password,
                         timeout=90,
                         hostkey_verify=False,
                         device_params={'name': 'csr'}) as m:

        # execute netconf operation
        try:
            response = m.get(payload).xml
            data = ET.fromstring(response)
        except RPCError as e:
            data = e._raw

        # beautify output
        print(ET.tostring(data, pretty_print=True))

Here's the output:

<rpc-reply message-id="urn:uuid:cc48e512-deb2-41dc-9fa5-deb8e5d41276" 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://cisco.com/ns/yang/Cisco-IOS-XE-interfaces-oper">
      <interface>
        <ipv4>192.168.28.132</ipv4>
        <ipv4-subnet-mask>255.255.255.0</ipv4-subnet-mask>
      </interface>
    </interfaces>
  </data>
</rpc-reply>
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: