cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1477
Views
2
Helpful
4
Replies

does the action output stores in CDB ?

kiran kotari
Cisco Employee
Cisco Employee

In my action output, we string variable of name "message".

Where does this message stored in NSO and How to read it ?

Is it possible to push the action output to NCS CLI any examples please.

1 Accepted Solution

Accepted Solutions

gschudel
Cisco Employee
Cisco Employee

There are several pretty complete examples in the nso_development-guide -- e.g. Ex. 90 through 94 for Python

where you see the "output.xxxx"... this gets displayed at CLI...

As a more complete example, if you build an action with YANG like this


module tryActionexample {

(skip)

  container action {

    tailf:info "Action-example... check sync";


    tailf:action tryActionexample {

      tailf:actionpoint tryActionexample-action;


      input {

        leaf target-device {

          tailf:info "Device to extract config from...";

          mandatory true;

          type leafref {

            path "/ncs:devices/ncs:device/ncs:name";

          }

        }

      } // input....


      output {

        leaf result1 {

          type string;

        }

      }

    }

  } // container action

} // module tryActionexample

and then Python like this:

class tryActionexampleAction(Action):

    """This class implements the an action test - just check-sync."""

   

    @Action.action

    def cb_action(self, uinfo, name, kp, input, output):

        self.log.info('action name: ', name)

        # self.log.info('action input.tickid: ', input.tickid)


        #... READ INPUTS...

        targetDev = input.target_device      #  (leafref)         ::


        #...........................................................................

        # fetch the "check-sync" status for the device...

        # results will be :  "out-of-sync"  "in-sync"  or  "unknown"

        trgcheck = devCheckSync (targetDev, self)

        result1 = '\n------------------------------------'

        result1 += '\n  Target Device: %s  [%s]' %  (targetDev, trgcheck)

        result1 += '\n------------------------------------'

        #

        output.result1 = result1

        #

#-------------------------------------------------------

# ------------------------------------------------------

def devCheckSync (deviceName, self):

    with ncs.maapi.Maapi() as m:

        with ncs.maapi.Session(m, 'admin', 'system'):

            root = ncs.maagic.get_root(m)

            device = root.devices.device[deviceName]

            inorout = device.check_sync()

            return inorout.result

#-------------------------------------------------------

# ---------------------------------------------

# COMPONENT THREAD THAT WILL BE STARTED BY NCS.

# ---------------------------------------------

class Main(ncs.application.Application):

    def setup(self):

        self.log.info('Main RUNNING')

        self.register_action('tryActionexample-action', tryActionexampleAction)


    def teardown(self):

        self.log.info('Main FINISHED')




you'll get an NSO CLI output like this:


admin@ncs% request action tryActionexample target-device c1

result1

------------------------------------

  Target Device: c1  [in-sync]

------------------------------------

[ok][2018-04-24 10:53:31]


[edit]

admin@ncs%



Of course, you have access (internally to python) to "output" (the YANG leaf)... and can add additional leaf's under "output"

It's just a simple example (action is "check-sync") but it illustrates the approach.


cheers

gregg






View solution in original post

4 Replies 4

frjansso
Cisco Employee
Cisco Employee

No, the output from an action is not stored in CDB.

Code (java or python) can invoke an action and use the result though.

gschudel
Cisco Employee
Cisco Employee

There are several pretty complete examples in the nso_development-guide -- e.g. Ex. 90 through 94 for Python

where you see the "output.xxxx"... this gets displayed at CLI...

As a more complete example, if you build an action with YANG like this


module tryActionexample {

(skip)

  container action {

    tailf:info "Action-example... check sync";


    tailf:action tryActionexample {

      tailf:actionpoint tryActionexample-action;


      input {

        leaf target-device {

          tailf:info "Device to extract config from...";

          mandatory true;

          type leafref {

            path "/ncs:devices/ncs:device/ncs:name";

          }

        }

      } // input....


      output {

        leaf result1 {

          type string;

        }

      }

    }

  } // container action

} // module tryActionexample

and then Python like this:

class tryActionexampleAction(Action):

    """This class implements the an action test - just check-sync."""

   

    @Action.action

    def cb_action(self, uinfo, name, kp, input, output):

        self.log.info('action name: ', name)

        # self.log.info('action input.tickid: ', input.tickid)


        #... READ INPUTS...

        targetDev = input.target_device      #  (leafref)         ::


        #...........................................................................

        # fetch the "check-sync" status for the device...

        # results will be :  "out-of-sync"  "in-sync"  or  "unknown"

        trgcheck = devCheckSync (targetDev, self)

        result1 = '\n------------------------------------'

        result1 += '\n  Target Device: %s  [%s]' %  (targetDev, trgcheck)

        result1 += '\n------------------------------------'

        #

        output.result1 = result1

        #

#-------------------------------------------------------

# ------------------------------------------------------

def devCheckSync (deviceName, self):

    with ncs.maapi.Maapi() as m:

        with ncs.maapi.Session(m, 'admin', 'system'):

            root = ncs.maagic.get_root(m)

            device = root.devices.device[deviceName]

            inorout = device.check_sync()

            return inorout.result

#-------------------------------------------------------

# ---------------------------------------------

# COMPONENT THREAD THAT WILL BE STARTED BY NCS.

# ---------------------------------------------

class Main(ncs.application.Application):

    def setup(self):

        self.log.info('Main RUNNING')

        self.register_action('tryActionexample-action', tryActionexampleAction)


    def teardown(self):

        self.log.info('Main FINISHED')




you'll get an NSO CLI output like this:


admin@ncs% request action tryActionexample target-device c1

result1

------------------------------------

  Target Device: c1  [in-sync]

------------------------------------

[ok][2018-04-24 10:53:31]


[edit]

admin@ncs%



Of course, you have access (internally to python) to "output" (the YANG leaf)... and can add additional leaf's under "output"

It's just a simple example (action is "check-sync") but it illustrates the approach.


cheers

gregg






Thanks Gregg.

If the action output leafs are not stored in CDB, then are these values are not persistent ?

Hi Kiran

that's correct - not stored in CDB, not peristent

(i'm not sure how or why one would ever want these to be persistent. this is typically asking a question "what is the state _right now_) --