cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2010
Views
7
Helpful
3
Replies

Python Data Provider Example

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

3 Replies 3

frjansso
Cisco Employee
Cisco Employee

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)

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

Yes, that's the way I'd do it!

Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?