cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2153
Views
0
Helpful
6
Replies

Operational data python code

mhemmatp
Cisco Employee
Cisco Employee

Hello all,

 

I have a simple yang model which represents a netconf device. I created a new netconf NED. Then, I am trying to perform the basic NETCONF operations. I could perfom most of the operations except reading the operational data (config false container).

Any help is appreciated to perform this operation.

 

Kind Regards,

 

1 Accepted Solution

Accepted Solutions

It is enough to add config false to make it operational, and as long as the yang models are in the NED you do build it should work.


Actually, there is an example distributed with nso, if you look at the example examples.ncs/getting-started/developing-with-ncs/0-router-network and run through that you get an nso with 3 netconf devices. 

 

In the ncs_cli for that example you can do:

admin@ncs> show devices device ex0 live-status sys dns 
ADDRESS   
----------
10.2.3.4

[ok][2019-03-21 18:00:07]

The following is an example python script that works with that example:

import ncs.maapi as maapi
import ncs.maagic as maagic

with maapi.single_read_trans('admin', 'test') as t:
root = maagic.get_root(t)
dev = root.devices.device['ex0']
for server in dev.live_status.sys.dns.server:
print 'DNS server: {}'.format(server.address)

You can just run that from the shell and it'll print all the dns servers in the operational data.

View solution in original post

6 Replies 6

vleijon
Cisco Employee
Cisco Employee

Can you give a little bit more information on what commands you are trying, what happens and what you see in the trace files?

Firstly, thank you very much for your reply. Actually, I am going to connect NSO to a host machine with ubuntu. Host is running a netopeer2-server (i.e., NETCONF server). It has a yang model which describes my device. My yang model has two containers, one for keeping configuration and one for state data.

 

container host-conf {

   leaf test {

      type uint32;

   }

}

container host-stat {

   config false;

   leaf stat {

      type uint32;

   }

}

 

I created a NED package as a netconf device to introduce my device to NSO. Then, running the ncs. I can use the following python code to read the configuration (i.e., host-conf). Also, I can modify the configuration.

 

import ncs;

with ncs.maapi.single_read_trans('admin','python') as trans:

root=ncs.maagic.get_root(trans)

device=root.devices.device['host']

device.config['hst:host-conf'].test

 

But I can not see where is my state data (i.e., host-stat). I mean in the last line (after device.) I am looking for my operational data which is missing. My question is how can I read it?

 

 

I hope I could explain my problem.

 

Thank you in advance,

Kind Regards,

 

 

The easiest way is probably to test this out in the ncs_cli first. Anyhow, under config you have the configuration, operational data turns up under live-status. So in python that'd be starting from device.live_status. 

Thanks. Could you please provide me an example of live_status. In the cli I used the following:

 

devices device host live-status-protocol

 

It turns no entries found. Actually, I have doubts about yang model as well. Does adding config false is enough to say this is operational data in the yang model  or I need to add more hints?

 

 

Kind Regards,

 

 

 

 

 

 

 

It is enough to add config false to make it operational, and as long as the yang models are in the NED you do build it should work.


Actually, there is an example distributed with nso, if you look at the example examples.ncs/getting-started/developing-with-ncs/0-router-network and run through that you get an nso with 3 netconf devices. 

 

In the ncs_cli for that example you can do:

admin@ncs> show devices device ex0 live-status sys dns 
ADDRESS   
----------
10.2.3.4

[ok][2019-03-21 18:00:07]

The following is an example python script that works with that example:

import ncs.maapi as maapi
import ncs.maagic as maagic

with maapi.single_read_trans('admin', 'test') as t:
root = maagic.get_root(t)
dev = root.devices.device['ex0']
for server in dev.live_status.sys.dns.server:
print 'DNS server: {}'.format(server.address)

You can just run that from the shell and it'll print all the dns servers in the operational data.

Thanks. It works perfectly.