cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
254
Views
15
Helpful
4
Replies
Highlighted
Beginner

How can I open transaction and keep information about user who is triggering the action/service on NSO

Hello,

Usually when I open a transaction with maapi on NSO, I use the below user 'admin', but I need to open transaction and keep information for each user (instead of 'admin') who is triggering the action/service, how can I do it ?

with ncs.maapi.Maapi() as m:

      with ncs.maapi.Session(m, 'admin', 'python'):

 

 

4 REPLIES 4
Highlighted
Cisco Employee

From an action:

with ncs.maapi.Maapi() as m:
   with m.start_write_trans(usid=uinfo.usid) as trans:

Highlighted

@hniska 

And how to insert uinfo below in service creation ?

def cb_create(self, tctx, root, service, proplist):

Highlighted

@nso20 The Transaction comes by default for a Service. If you explicitly want to store an username details then you can achieve from the following way. 

1. get the mappi object from the service

2. get `uinfo` from mappi

3. `uinfo.username` contains the transaction username.

 

my_mappi = ncs.maagic.get_maapi(service)
uinfo = my_mappi.get_user_session(my_mappi.get_my_user_session_id())
print(uinfo.username)

By default username is admin, You can add more as @hniska mentioned.

Highlighted
Cisco Employee

Hi, what is it that you want to do? The service create() automatically gives you a transaction already and the FASTMAP code runs without any access check.

 

From the help: This allows administrators to grant indirect but controlled access to user to execute device configuration changes on devices that they are not allowed to configure directly. The leaf /nacm/enforce-nacm-on-services has been introduced to allow NSO administrators to control this behavior: they can now enforce NACM rules even on changes done by services. Refer to the "NACM Rules and Services" section in the AAA chapter of the Administration Guide for details.