04-19-2018 01:48 AM - edited 03-01-2019 04:08 AM
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.
Solved! Go to Solution.
04-24-2018 12:16 PM
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
04-23-2018 12:58 PM
No, the output from an action is not stored in CDB.
Code (java or python) can invoke an action and use the result though.
04-24-2018 12:16 PM
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
04-25-2018 12:15 AM
Thanks Gregg.
If the action output leafs are not stored in CDB, then are these values are not persistent ?
04-25-2018 07:16 AM
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_) --
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