01-18-2023 02:24 PM - edited 01-18-2023 02:27 PM
Hey,
I have a subscriber sitting in a non service PACKAGE that is monitoring ANOTHER_PACKAGE which is a service package with a top list of devices, where their names are the key. Subscriber is registered on /ANOTHER_PACKAGE/devices
I don't want to act on everything that is going on in ANOTHER_PACKAGE; only if device is deleted, or if a particular enum node (/ANOTHER_PACKAGE/devices{rtr}/onboarding/external-systems/rfs-nso-systems) under each device is changed. So I set up a regex filter to catch what I want to act upon. It looks something like this:
def iterate(self, keypath, operation, oldval, newval, state):
"""Filter subscription."""
keypath = str(keypath)
self.log.info(keypath)
if match('/ANOTHER_PACKAGE/devices{.*}/onboarding/external-systems/rfs-nso-systems$', keypath) and operation == ncs.MOP_VALUE_SET:
state.append([operation, keypath])
return ncs.ITER_RECURSE
if match('/ANOTHER_PACKAGE/devices{.*}$', keypath) and operation == ncs.MOP_DELETED:
state.append([operation, keypath])
return ncs.ITER_RECURSE
state = []
return ncs.ITER_RECURSE
When I run it though, NSO does something which I understand where it is coming from and why but not how it passes the regexes. Following is a self.log.info print of a state attribute in post_iterate:
[[4, '/ANOTHER_PACKAGE/devices{rtr}/onboarding/external-systems/rfs-nso-systems'],
[2, '/ANOTHER_PACKAGE/devices{rtr}/onboarding/external-systems/rfs-nso{rfs-58}'],
[2, '/ANOTHER_PACKAGE/devices{rtr}/private/device-list{rfs-58}'],
[2, '/ANOTHER_PACKAGE/devices{rtr}/private/ned-id-list{cisco-nso-nc-5.8:cisco-nso-nc-5.8}'],
[4, '/ANOTHER_PACKAGE/devices{sw}/onboarding/external-systems/rfs-nso-systems'],
[2, '/ANOTHER_PACKAGE/devices{sw}/private/device-list{rfs-58}'],
[2, '/ANOTHER_PACKAGE/devices{sw}/private/ned-id-list{cisco-nso-nc-5.8:cisco-nso-nc-5.8}']]
I checked the regexes, they work as intended.
I tried to put ITER_STOP on the returns, which fixes the issue for one device per transaction but if multiple devices get modified in the same transaction, the second device + n won't get processed by the subscriber.
Creating devices from scratch and deleting them completely works fine. Only if I change that enum on //rfs-nso-systems to a particular value which causes the //rfs-nso leaf-list to be deleted in the process, then I get the above output.
Help
01-19-2023 04:32 AM - edited 01-19-2023 04:38 AM
I ended up ditching regex and did this:
if 'rfs-nso-systems' in keypath:
state.append([operation, keypath])
return ncs.ITER_RECURSE
if keypath.count('/') == 2 and operation == ncs.MOP_DELETED:
state.append([operation, keypath])
return ncs.ITER_RECURSE
state = []
return ncs.ITER_RECURSE
Now it is fine, and faster too, I found out. Looks a bit MacGyverish though.
I don't know how those private keypaths got in, perhaps bug in re or my lack of knowledge regarding the module. It would be interesting to know.
01-19-2023 09:09 AM
Hi, is match part of the re python library or something else? missing your import statement.
01-19-2023 09:22 AM - edited 01-19-2023 09:34 AM
It is re, yes
EDIT: I just realised my initial delete regexe was too lax. The reason I didn't figure it out was because there was a not very obvious typo in the test string I was testing with. :facepalm:
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