10-18-2017 05:29 PM - edited 03-01-2019 04:01 AM
Does anyone have example of a working data provider package leveraging python for an example? The Docs directory has a Java exmaple, but curious if anyone has a walk through or package example in python they could share.
Interested in this capability for external services like ServiceNow, or an IPAM system.
Thanks,
Brandon
10-19-2017 05:38 PM
Really a toy example, but might send you off in the right direction. Please change confd for ncs in the imports.
YANG:
container interface {
list GigabitEthernet {
key "name";
leaf name {
type string;
}
leaf shutdown {
type empty;
}
container stats {
config false;
tailf:callpoint "stats";
leaf sent {
type uint32;
}
leaf received {
type uint32;
}
}
import logging
import random
from confd.experimental import DataCallbacks
from _confd.dp import register_data_cb
class Handler(object):
def __init__(self, log):
self.log = log
def get_object(self, tctx, kp, args):
recv = random.randint(0, 10000)
sent = random.randint(0, 10000)
return {
'stats': {
'received': recv,
'sent': sent
}
}
def get_next(self, tctx, kp, args, next):
self.log.info('get_next: ' + str(kp))
return None
def count(self):
self.log.info('count: ')
print('count')
return 0
def start(daemon):
log = logging.getLogger(__name__)
dp = DataCallbacks(log)
dp.register('/config:interface/config:GigabitEthernet', Handler(log))
register_data_cb(daemon.ctx(), 'stats', dp)
10-20-2017 03:37 PM
Thanks Fredrik!
Apologies for my ignorance, how would I structure this as a package inside NSO?
For example to beign would I leverage:
ncs-make-package --service-skeleton python test_dp --component-class NAME (default main.Main)
then remove the service references in YANG?
I'll experiment and try! But wanted to double check.
Thanks again,
Brandon
10-23-2017 09:19 AM
Yes, that's the way I'd do it!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide