Cli completion point, any way to do this without the c file approach

Hi,

I am trying to implement capi cli completion from confd.cli file. In the manual I see that a C file implements the completion point. I am not sure how i could do this without the C file. In out code base everything is done via subscriptions in python files.

Any pointers will be appreciated.

Thanks,

If you have Python API (requires ConfD Premium), you can use also Python to implement CLI completion callback (like in C).

Example from Python API

 class ActionCallbacks(object):

        def cb_init(self, uinfo):
            pass

        def cb_abort(self, uinfo):
            pass

        def cb_action(self, uinfo, name, kp, params):
            pass

        def cb_command(self, uinfo, path, argv):
            pass

        def cb_completion(self, uinfo, cli_style, token, completion_char,
                          kp, cmdpath, cmdparam_id, simpleType, extra):
            pass

    acb = ActionCallbacks()
    dp.register_action_cbs(dx, 'actionpoint-1', acb)

One needs to implement cb_completion.

1 Like

Hi,

I am just a little confused on how the callback will work.

my confd.cli is as follows:

    <param>
      <info>source network interface</info>
      <help>specify a source network interface</help>
      <name>interface</name>
      <flag>-i</flag>
      <optional></optional>
      <type>
        <simpleType namespace="" name="string">
          <info>Interface name</info>
        </simpleType>
      </type>
      <callback>
        <capi>
          <completionpoint>ifs-complete</completionpoint>
        </capi>
      </callback>
    </param>

In the class you have specified, is the class an action provider?

Also,

dp.register_action_cbs(dx, ‘actionpoint-1’, acb) => what is dx, do I need to define it.

what object is dp ?, do I need to define a class as an action provider and call register_action_cbs from it?

You need to look at Python API documentation (found in src/confd/pyapi/doc/confd)

E.g.:

register_action_cbs(...)
    register_action_cbs(dx, actionpoint, acb) -> None
     
    This function registers up to five callback functions, two of which will
    be called in sequence when an action is invoked.
     
    Keyword arguments:
    dx -- a daemon context acquired through a call to init_daemon()
    actionpoint -- the name of the action point
    vcb -- the callback instance (see below)
     
    The acb argument should be an instance of a class with callback methods.
    E.g.:
     
        class ActionCallbacks(object):
            def cb_init(self, uinfo):
                pass
     
            def cb_abort(self, uinfo):
                pass
     
            def cb_action(self, uinfo, name, kp, params):
                pass
     
            def cb_command(self, uinfo, path, argv):
                pass
     
            def cb_completion(self, uinfo, cli_style, token, completion_char,
                              kp, cmdpath, cmdparam_id, simpleType, extra):
                pass
     
        acb = ActionCallbacks()
        dp.register_action_cbs(dx, 'actionpoint-1', acb)
     
    Notes about some of the callbacks:
     
    cb_action()
        The params argument is a list of _lib.TagValue instances.
     
    cb_command()
        The argv argument is a list of strings.

Thanks !! Is your documentation available to download anywhere specifically examples using confd premium.

Python documentation and examples are available only for ConfD premium and are part of ConfD packages
(e.g. confd-6.5.2.doc.tar.gz - /doc/api/python , confd-6.5.2.examples.tar.gz - /examples.confd/intro/python).

Thanks.

I am trying it out. But I am unable to put a question mark after my cli which should show the capi options.

<cmd name="traceroute">
  <info>Trace route to destination</info>
  <help>Trace route to destination</help>
  <callback>
    <exec>
      <osCommand>traceroute</osCommand>
      <options>
        <interrupt>ctrlc</interrupt>
      </options>
    </exec>
  </callback>
  <params>
    <param>
      <info>source network interface</info>
      <help>specify a source network interface</help>
      <name>interface</name>
      <flag>-i</flag>
      <optional></optional>
      <type>
        <simpleType namespace="" name="string">
          <info>Interface name</info>
        </simpleType>
      </type>
      <callback>
        <capi>
          <completionpoint>ifs-complete</completionpoint>
        </capi>
      </callback>
    </param>

cant put ? infront of interface to show options
nfvis# traceroute interface

Its not even hitting backend, is there something wrong in my capi definition in confd.cli

I have also tried moving the capi block to modifications, still see the same effect.

Not sure what is the problem. Can you check if completionpoint callback is correctly registered? (using confd --status). If yes, are there any hints in confd.log or devel.log?