cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1452
Views
5
Helpful
4
Replies

Running show commands through Northbound Netconf API

ogenstad
Level 1
Level 1

I'm converting some Lux tests and instead using Pytest which connects to NSO through Netconf with ncclient. I think it works quite nicely, as it's both easier to write and validate the tests and they also run a lot faster.

 

I am a bit stuck on the reconcile part, in one part I want to convert the show commands which have been used previously. I.e., something like this:

 

show devices device lab-router-1 config ios:interface Loopback 0

or

show devices device lab-router-1 config ios:interface Loopback 0 | display set (or xml or whatever)

 

I'm not quite sure how to format the XML payload to send something like this to NSO. For the reconcile action I just use `<action xmlns="http://tail-f.com/ns/netconf/actions/1.0"><data>` and then point to the action I want to use.

 

How would I execute one of the show commands above or any show command for that matter?

1 Accepted Solution

Accepted Solutions

hniska
Cisco Employee
Cisco Employee

 

You can find some ncclient examples here if you havent already seen them 

 

https://github.com/ncclient/ncclient/blob/master/examples/

 

example three shows you how to fetch config

 

https://github.com/ncclient/ncclient/blob/master/examples/nc03.py

 

To get config you can just pass in the xpath to the data you want.

View solution in original post

4 Replies 4

hniska
Cisco Employee
Cisco Employee

Something like

 

curl -X GET -i -u admin:admin \
--header "Accept: application/yang-data+json" \
http://localhost:8080/restconf/data/devices/device=c0/config/\
tailf-ned-cisco-ios:router/bgp

 

or 

 

curl -X GET -i -u admin:admin \
--header "Accept: application/yang-data+xml" \
http://localhost:8080/restconf/data/devices/device=c0/config/\
tailf-ned-cisco-ios:router/bgp

hniska
Cisco Employee
Cisco Employee
Ah sorry, netconf :)

hniska
Cisco Employee
Cisco Employee

 

You can find some ncclient examples here if you havent already seen them 

 

https://github.com/ncclient/ncclient/blob/master/examples/

 

example three shows you how to fetch config

 

https://github.com/ncclient/ncclient/blob/master/examples/nc03.py

 

To get config you can just pass in the xpath to the data you want.

Thanks!

 

It's so apparent when you see how you should do it. I was looking around to trigger a show command when I could grab the actual config instead.

 

I'm happy now but I have a small follow up. When I get the configuration I see a reference counter and backpointer for the lines that have been configured by a service, but not if I've directly configured the device. Is it possible to remove that part? If not I'll just do it in code. For some kinds of tests it will probably be better to have that than to not have it. 

 

Configured through a service:
netconf-console -u admin -p admin --host 127.0.0.1 --port 2022 --get-config -x "/devices/device[name='ios-pe0']/config/interface/Port-channel[name='10']

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <data>
    <devices xmlns="http://tail-f.com/ns/ncs">
      <device>
        <name>ios-pe0</name>
        <config>
          <interface xmlns="urn:ios">
            <Port-channel refcounter="1" backpointer="[ /base:rfs-services/interface-rfs:interface-rfs[interface-rfs:device='ios-pe0'][interface-rfs:interface='LAG'][interface-rfs:id='10'] ]">
              <name>10</name>
              <description refcounter="1">HEJ</description>
            </Port-channel>
          </interface>
        </config>
      </device>
    </devices>
  </data>
</rpc-reply>


Configured directly against the device:
netconf-console -u admin -p admin --host 127.0.0.1 --port 2022 --get-config -x "/devices/device[name='ios-pe0']/config/interface/Port-channel[name='11']"

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <data>
    <devices xmlns="http://tail-f.com/ns/ncs">
      <device>
        <name>ios-pe0</name>
        <config>
          <interface xmlns="urn:ios">
            <Port-channel>
              <name>11</name>
              <description>Directly configured</description>
            </Port-channel>
          </interface>
        </config>
      </device>
    </devices>
  </data>
</rpc-reply>