02-18-2020 11:50 AM
I'm beating my head against a wall here trying to pivot from either erlang or java examples to python.
What I'm in despirate need of is a _working_ example of something akin to the tailf:cli-completion-actionpoint if-complete but in Python. The goal being tab completion of interface names from within services for a given device.
Can anyone provide anything? The only hit I'm finding is from @mohamkh7 located here. However, it doesn't load for me.
Solved! Go to Solution.
02-19-2020 07:46 AM
I got it working and not as difficult as i originally thought!
Yang model:
module network-link { namespace "http://example.com/network-link"; prefix network-link; import tailf-common { prefix tailf; } import tailf-ncs { prefix ncs; } description "Bla bla..."; revision 2016-01-01 { description "Initial revision."; } augment /ncs:services { container network-link { list connectivity { // This represents a physical link between two ports key cid; leaf cid { tailf:info "A unique circuit identifier for a link"; type string; } uses ncs:service-data; list endpoint { key "device interface"; leaf device { type leafref { path "/ncs:devices/ncs:device/ncs:name"; } } leaf interface { type string; tailf:cli-completion-actionpoint if-action; } } } } } // augment /ncs:services { }
Python file with simple logging:
import _ncs import ncs from ncs.dp import Action class ActionCallbacks(Action): @Action.action def cb_action(self, uinfo, name, kp, input, output, trans): self.log.info("ActionCallback: ", "cb_action") def cb_completion(self, uinfo, cli_style, token, completion_char, kp, cmdpath, cmdparam_id, simpleType, extra): self.log.info("ActionCallback: ", "cb_completion({},{},{},{},{},{},{},{},{})".format( uinfo, cli_style, token, completion_char, kp, cmdpath, cmdparam_id, simpleType, extra)) if_list = [(0, 'ge-0/1', None), (0, 'fe-0/0', None), (0, 'ge-0/2', None)] _ncs.dp.action_reply_completion(uinfo, if_list) class IfComplete(ncs.application.Application): def setup(self): self.log.info('--- if_complete.IFComplete setup') self.register_action('if-action', ActionCallbacks) def teardown(self): self.log.info("-- if_complete.IfComplete teardown")
Output:
admin@ncs(config)# services network-link connectivity 1 endpoint reflector-0 ? Possible completions: fe-0/0 ge-0/1 ge-0/2
02-19-2020 07:46 AM
I got it working and not as difficult as i originally thought!
Yang model:
module network-link { namespace "http://example.com/network-link"; prefix network-link; import tailf-common { prefix tailf; } import tailf-ncs { prefix ncs; } description "Bla bla..."; revision 2016-01-01 { description "Initial revision."; } augment /ncs:services { container network-link { list connectivity { // This represents a physical link between two ports key cid; leaf cid { tailf:info "A unique circuit identifier for a link"; type string; } uses ncs:service-data; list endpoint { key "device interface"; leaf device { type leafref { path "/ncs:devices/ncs:device/ncs:name"; } } leaf interface { type string; tailf:cli-completion-actionpoint if-action; } } } } } // augment /ncs:services { }
Python file with simple logging:
import _ncs import ncs from ncs.dp import Action class ActionCallbacks(Action): @Action.action def cb_action(self, uinfo, name, kp, input, output, trans): self.log.info("ActionCallback: ", "cb_action") def cb_completion(self, uinfo, cli_style, token, completion_char, kp, cmdpath, cmdparam_id, simpleType, extra): self.log.info("ActionCallback: ", "cb_completion({},{},{},{},{},{},{},{},{})".format( uinfo, cli_style, token, completion_char, kp, cmdpath, cmdparam_id, simpleType, extra)) if_list = [(0, 'ge-0/1', None), (0, 'fe-0/0', None), (0, 'ge-0/2', None)] _ncs.dp.action_reply_completion(uinfo, if_list) class IfComplete(ncs.application.Application): def setup(self): self.log.info('--- if_complete.IFComplete setup') self.register_action('if-action', ActionCallbacks) def teardown(self): self.log.info("-- if_complete.IfComplete teardown")
Output:
admin@ncs(config)# services network-link connectivity 1 endpoint reflector-0 ? Possible completions: fe-0/0 ge-0/1 ge-0/2
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