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

Pass uinfo to subscription class

tsiemers1
Spotlight
Spotlight

Looking over the api for ncs.experimental Subscriber, what is the correct way to pass the uinfo?

The subscriber is registered to the path /test_sub/request/device

In the code for the subscriber, I would like to pass the uinfo.username to run a single_write_trans as that user.

 

 

class TestSubscriber(Subscriber):
    def init(self):
        self.register('/test_sub/request/device')

    def pre_iterate(self):
        return []

    def iterate(self, kp, op, oldval, newval, state):
        if op is ncs.MOP_VALUE_SET:
            self.log.info('Request: %s' % (str(kp[1:])))
            state.append((newval, str(kp[1:])))
        return ncs.ITER_RECURSE

    def post_iterate(self, state):
        for request in state:
            self.write_result(test_function(self.log, request[0]), request[1])

    def should_post_iterate(self, state):
        return state != []

    def write_result(self, result, kp):
        with maapi.single_write_trans('nsouser', 'system', db=ncs.OPERATIONAL) as th:
            root = maagic.get_root(m)
            maagic.cd(root, str(kp)).result = result
            th.apply()

I would like to instead use something similar to the following in the write_result 

 

 

def write_result(self, result, kp, uinfo): 
with maapi.single_write_trans(uinfo.username, 'system', db=ncs.OPERATIONAL) as th:
root = maagic.get_root(m) maagic.cd(root, str(kp)).result = result th.apply()

Similar to how it works in the action class:

 

 

class DeviceOpsStatus(Action):
    @Action.action
    def cb_action(self, uinfo, name, kp, input, output):
        self.log.info('ACTION: ', )
self.uinfo = uinfo with ncs.maapi.Maapi() as m: with ncs.maapi.Session(m, self.uinfo.username, 'system'): with m.start_write_trans(ncs.RUNNING) as t: root = ncs.maagic.get_root(t)

Do I need to pass this from the action to the subscriber? I don't see anything in the python api docs for the Subscriber class to pass uinfo.

 

0 Replies 0