cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
292
Views
5
Helpful
6
Replies

What is the proplist argument ?

Hi, I am new in NSO and I want to develop my own services using python.

I want to ask what is the proplist argument in the cb_create(self, tctx, root, service, proplist) function ?

1 ACCEPTED SOLUTION

Accepted Solutions

Okay, the first thing you need to know is that you don’t need to know this: The proplist is an advanced feature and while you are learning you can just ignore it. I am sure there are people who have written services for years without using it.

But, it is just storage for your service, in python it is essentially a dictionary that you can use.

As an example: Say that you need to generate a secret password for a vpn tunnel that you are setting up: You want it to be random but you don’t want it to change all the time.

What you do is that you generate a random key the first time you run the service, and store it in the proplist, then every time you run the service after that you can read it from the proplist and reuse the same key every time.

View solution in original post

6 REPLIES 6
vleijon
Cisco Employee

The proplist, sometimes called the “opaque” is a persistent way of storing information between invocations to the callback. The create callback can return the proplist (an array of tuples) and will get it sent back on the next invocation.

Thank you vleijon for your reply. Could you please explain to me more with some easy words ?

Okay, the first thing you need to know is that you don’t need to know this: The proplist is an advanced feature and while you are learning you can just ignore it. I am sure there are people who have written services for years without using it.

But, it is just storage for your service, in python it is essentially a dictionary that you can use.

As an example: Say that you need to generate a secret password for a vpn tunnel that you are setting up: You want it to be random but you don’t want it to change all the time.

What you do is that you generate a random key the first time you run the service, and store it in the proplist, then every time you run the service after that you can read it from the proplist and reuse the same key every time.

View solution in original post

So there were a few things that weren't immediately obvious to about proplists that I figured I'd share.

- proplists do get persisted across commits. If you restart NSO, upgrade your code, etc, you'll still get that proplist back when you make a change or do a re-deploy of your service. No other service will have access to these.

- Like you'd expect, a modified proplist doesn't get stored if the commit isn't successful (or if it's a dry-run)

- Probably not like you'd expect, proplists don't seem to show up in the config tree

- Each tuple in the list must have exactly 2 items and they must be strings. No integers, no objects, no complex types. So more like: `[ (str, str), ... ]`

 

- proplists can be converted to/from dictionaries pretty easily in Python.

 

props = dict(proplist)

... do stuff ...
proplist = [ (str(k), str(v)) for k, v in props.items() ] return proplist

You accept a few limitations while doing it this way. Namely that a proplist can have multiple entries for the same "key". IE: `[ ("message", "hello"), ("message", "goodbye"), ("other_attribute", "something_else), ... ]`.

 

 

You also give up the notion of ordering to the proplist, which isn't likely a big deal. If worse comes to worse, you can always "json.dumps()" and "json.loads()" to stash data.

 

- These values cannot be read/modified by other services and cannot be read/modified by the CLI user that I know of.

 

If there is a way to view `proplist` data for debugging purposes, I'm interested.

These are great additions, thanks.

Proplists do turn up in the config tree they are just hidden under a hide-group called fastmap-private, see tailf-ncs-services.yang, to make sure people don’t go around modifying them. Any API user _can_ modify them by modifying the database directly. This is obviously not recommended.

Hopefully this helps, otherwise I can add more details later.

That's helpful. Thanks!