cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1731
Views
10
Helpful
2
Replies

Kicker Variables

tsiemers1
Spotlight
Spotlight

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

 

 

 

1 Accepted Solution

Accepted Solutions

gmuloche
Cisco Employee
Cisco Employee

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 

View solution in original post

2 Replies 2

gmuloche
Cisco Employee
Cisco Employee

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 

This is exactly what I was after. Thanks for help.

Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?