02-13-2020 10:58 AM
Getting started with using kickers to run an action after a service has been created. How do you set one of the leaves from the service as a variable in the kicker?
Yang:
module postmod_test { namespace "http://example.com/postmod_test"; prefix postmod_test; import ietf-inet-types { prefix inet; } import tailf-common { prefix tailf; } import tailf-ncs { prefix ncs; } import tailf-kicker { prefix kicker; } description "Bla bla..."; revision 2016-01-01 { description "Initial revision."; } list postmod_test { description "This is an RFS skeleton service"; key name; leaf name { tailf:info "Unique service id"; tailf:cli-allow-range; type string; } uses ncs:service-data; ncs:servicepoint postmod_test-servicepoint; leaf vlan { type uint16; } container actions { tailf:action vlanCleaner { tailf:actionpoint CleanUpIpam; input { uses kicker:action-input-params; } output { } } } } }
Python
# -*- mode: python; python-indent: 4 -*- import ncs from ncs.application import Service from ncs.dp import Action # ------------------------ # SERVICE CALLBACK EXAMPLE # ------------------------ class ServiceCallbacks(Service): @Service.create def cb_create(self, tctx, root, service, proplist): self.log.info('Service create(service=', service._path, ')') # --------------- # ACTIONS EXAMPLE # --------------- class CleanUpIpam(Action): @Action.action def cb_action(self, uinfo, name, kp, input, output, trans): self.log.info('action name: ', name) self.log.info('KICKER HAS BEEN KICKED') self.log.info(f'Action input: kicker-id: {input.kicker_id}, path: {input.path}, tid: {input.tid}') self.log.info(dir(input)) # --------------------------------------------- # COMPONENT THREAD THAT WILL BE STARTED BY NCS. # --------------------------------------------- class Main(ncs.application.Application): def setup(self): self.log.info('Main RUNNING') self.register_service('postmod_test-servicepoint', ServiceCallbacks) self.register_action('CleanUpIpam', CleanUpIpam) def teardown(self): self.log.info('Main FINISHED')
Kicker
kickers data-kicker test3 monitor /postmod_test:postmod_test kick-node postmod_test:actions action-name vlanCleaner
What I would like is to send the value of vlan into the kicker.
So from the service using the leaf vlan:
leaf vlan { type uint16; }
Create a kicker like so:
kickers data-kicker test3 monitor /postmod_test:postmod_test kick-node postmod_test:actions action-name vlanCleaner variable VLAN value /vlan
Is this possible with a data-kicker? I see the example in the guide using $PATH but not sure how that relates to a service leaf.
Thanks
Solved! Go to Solution.
02-25-2020 01:04 AM
Hello,
essentially because your action is defined in the service itself the following would work:
class MyAction(Action): @Action.action def cb_action(self, uinfo, name, kp, input, output, trans): self.log.info('action name: ', name) self.log.info('KICKER HAS BEEN KICKED') self.log.info(f'Action input: kicker-id: {input.kicker_id}, path: {input.path}, tid: {input.tid}') self.log.info(kp) # get the actions container kicked_node = ncs.maagic.get_node(trans, kp) # get the VLAN self.log.info(f"Vlan for this service is: {kicked_node._parent.vlan}")
CLI:
admin@ncs(config-blah-test4)# test test4 vlan 7 admin@ncs(config-blah-test4)# commit | debug kicker 2020-02-25T10:00:49.617 kicker: test at /test:test[blah:name='test4'] changed; invoking 'test-action' Commit complete.
Logs:
<INFO> 25-Feb-2020::09:58:01.109 test ncs-dp-94343-test:main-1-th-171: - Service create(service=/test:test{test4}) <INFO> 25-Feb-2020::09:58:01.130 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - action name: test-action <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - KICKER HAS BEEN KICKED <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - Action input: kicker-id: test, path: /test:test{test4}, tid: 179 <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - /test:test{test4}/actions <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - Vlan for this service is: 7
I don't think you will need the kickers:action-input-params and probably the code can be made a bit nice but it should get you started
regards,
Guillaume
02-25-2020 01:04 AM
Hello,
essentially because your action is defined in the service itself the following would work:
class MyAction(Action): @Action.action def cb_action(self, uinfo, name, kp, input, output, trans): self.log.info('action name: ', name) self.log.info('KICKER HAS BEEN KICKED') self.log.info(f'Action input: kicker-id: {input.kicker_id}, path: {input.path}, tid: {input.tid}') self.log.info(kp) # get the actions container kicked_node = ncs.maagic.get_node(trans, kp) # get the VLAN self.log.info(f"Vlan for this service is: {kicked_node._parent.vlan}")
CLI:
admin@ncs(config-blah-test4)# test test4 vlan 7 admin@ncs(config-blah-test4)# commit | debug kicker 2020-02-25T10:00:49.617 kicker: test at /test:test[blah:name='test4'] changed; invoking 'test-action' Commit complete.
Logs:
<INFO> 25-Feb-2020::09:58:01.109 test ncs-dp-94343-test:main-1-th-171: - Service create(service=/test:test{test4}) <INFO> 25-Feb-2020::09:58:01.130 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - action name: test-action <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - KICKER HAS BEEN KICKED <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - Action input: kicker-id: test, path: /test:test{test4}, tid: 179 <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - /test:test{test4}/actions <INFO> 25-Feb-2020::09:58:01.131 test ncs-dp-94343-test:main-2-usid-49-test-actionpoint: - Vlan for this service is: 7
I don't think you will need the kickers:action-input-params and probably the code can be made a bit nice but it should get you started
regards,
Guillaume
02-25-2020 07:46 PM
This is exactly what I was after. Thanks for 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