cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1368
Views
15
Helpful
4
Replies

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

nso20
Level 1
Level 1

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

hniska
Cisco Employee
Cisco Employee

From an action:

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

@hniska 

And how to insert uinfo below in service creation ?

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

@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.

hniska
Cisco Employee
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.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: