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

Direct object access with maapi.cd in Python service callback call - any disadvantages?

rslaski
Spotlight
Spotlight

Hi guys,


Inside Python callback call (ex. post_modification), I've always been using MAAPI read transactions (with maapi.single_read_trans) or sessions (maapi.Session). However I have recently discovered that we can get the same object definition by just calling maapi.cd (root, '/a/fancy/path/to/the/object'), which works basically the same for me.

The question is: are there any disadvantages of this approach of reading object config data? Or any scenarios (RFM?) this might not work well?


thanks,
robert

1 Accepted Solution

Accepted Solutions

vleijon
Cisco Employee
Cisco Employee

First, there is no real disadvantage to doing it like that, and if it works for you, keep at it.

 

But, using maapi.cd doesn’t really save you any work compared to starting a new transaction, because you need a socket and a transaction all the same. I am not entirely sure of what your code looks like, but if we look at a standard pre-modification method from the manual:

@Service.pre_modification
    def cb_pre_modification(self, tctx, op, kp, root, proplist):
        pass

Then that root object is a maagic.Node object, and already contains a transaction and everything. I think that what most people do in python is just use that root object and navigate using maagic.

 

In the end it is mostly a matter of style, and which APIs feel more comfortable to you. I just wanted to point out that the root object contains multitudes. 

View solution in original post

1 Reply 1

vleijon
Cisco Employee
Cisco Employee

First, there is no real disadvantage to doing it like that, and if it works for you, keep at it.

 

But, using maapi.cd doesn’t really save you any work compared to starting a new transaction, because you need a socket and a transaction all the same. I am not entirely sure of what your code looks like, but if we look at a standard pre-modification method from the manual:

@Service.pre_modification
    def cb_pre_modification(self, tctx, op, kp, root, proplist):
        pass

Then that root object is a maagic.Node object, and already contains a transaction and everything. I think that what most people do in python is just use that root object and navigate using maagic.

 

In the end it is mostly a matter of style, and which APIs feel more comfortable to you. I just wanted to point out that the root object contains multitudes.