02-27-2020 04:41 AM
Hi,
Can someone give me an example of a service with a post_modification in python?
In particular I want to know two things:
The reason I need this is because I have a service with this particular behavior:
Since this command is defined in the NED as an action, I cant do it naturally. Also, I need to make a distinction between create and delete operations.
With that in mind, my idea is to make a post_modification that check the operation and send an empty string in case of delete, or defined parameter in case of create.
Solved! Go to Solution.
02-27-2020 05:02 AM
For the first part:
To get the service object which is available for the create callback:
service = ncs.maagic.cd(root, kp)
For the operation, something like that:
if op == _ncs.dp.NCS_SERVICE_CREATE:
I don't think I fully understand the use case however and whether this is the way to go.
02-27-2020 05:02 AM
For the first part:
To get the service object which is available for the create callback:
service = ncs.maagic.cd(root, kp)
For the operation, something like that:
if op == _ncs.dp.NCS_SERVICE_CREATE:
I don't think I fully understand the use case however and whether this is the way to go.
02-27-2020 05:37 AM
Thanks,
Using "service = ncs.maagic.cd(root, kp)" works, but for some reason I cant get te correct operation code.
Regardless of the opration I always get the code "op=1", but NCS_SERVICE_CREATE=0 and NCS_SERVICE_DELETE=2.
Any idea of what is happening?
02-27-2020 05:56 AM - edited 02-27-2020 05:57 AM
It should be an update operation then...
NCS_SERVICE_CREATE = 0,
NCS_SERVICE_UPDATE = 1,
NCS_SERVICE_DELETE = 2
best regards
02-27-2020 06:54 AM - edited 02-27-2020 06:55 AM
The problem is that I always get the code 1, and I need to differentiate between the operations.
This is part of my python post_mod:
self.log.info('op: ', op)
And when I do:
admin@ncs(config)# no services ...
I get this in the log:
- op: 1
Same when I create a service or update one.
02-27-2020 02:44 PM
I've just tested here and it worked fine...
Creating a new service and then commit...
<INFO> 27-Feb-2020::19:37:38.749 vpnuser ncs-dp-55125-vpnuser:main-1-th-2343: - Service create(service=/ncs:services/vpnuser:vpnuser{test123})
<INFO> 27-Feb-2020::19:37:38.780 vpnuser ncs-dp-55125-vpnuser:main-1-th-2343: - op = 0
Modifying a service attribute and commit...
<INFO> 27-Feb-2020::19:38:22.612 vpnuser ncs-dp-55125-vpnuser:main-1-th-2389: - Service create(service=/ncs:services/vpnuser:vpnuser{test123})
<INFO> 27-Feb-2020::19:38:22.623 vpnuser ncs-dp-55125-vpnuser:main-1-th-2389: - op = 1
Deleting the service vpnuser{test123}:
<INFO> 27-Feb-2020::19:43:29.423 vpnuser ncs-dp-55125-vpnuser:main-2-th-2411: - op = 2
The code was:
@Service.post_modification
def cb_post_modification(self, tctx, op, kp, root, proplist):
# self.log.info('Service premod(service=', kp, ')')
self.log.info('op = ', op)
It seems to be working as expected...
This test was done with NSO 5.1.0.1
Best regards
02-28-2020 04:16 AM
I tested with a dummy services in 4.7 and works too. I think I know what the problem is.
My service has the following structure in Yang:
list serviceA { key "code"; ncs:servicepoint "serviceA"; uses ncs:service-data; leaf code { type string; } ... list listB { key "id"; leaf id { type uint16; } ... } }
When I create, delete or update elements in listB, for NSO those are updates of servicesA. Thats why I always get the code "op=1".
I will have to modify my service.
Thanks for the help.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide