def cb_command(self, uinfo, path, argv):
        global maapisock_commit
        log.debug("==> path %s argv=%r" % (path, argv))
        rv = _confd.CONFD_OK
        if len(argv) not in [1, 2, 3, 5]:
            rv = _confd.CONFD_ERR
            log.fatal("Wrong number of arguments %i, expected 1,2,3,5" %
                      len(argv))
        else:
            try:
                maapi.attach2(maapisock_commit, maapi_example_ns.ns.hash,
                              uinfo.usid, uinfo.actx_thandle)
                if len(argv) == 1:
                    self.perform_maapi_candidate_confirmed_commit(uinfo.usid)
                elif len(argv) == 2:
                    if argv[1] == "status":
                        self.perform_maapi_commit_status(uinfo.usid)
                    elif argv[1] == "abort":
                        # abort ongoing confirmed commit - without ID
                        self.perform_maapi_commit_abort(uinfo.usid)
                    elif argv[1] == "confirm":
                        # confirm ongoing confirmed commit - without ID
                        self.confirm_maapi_candidate_commit(uinfo.usid)
                    else:
                        log.fatal("Unexpected parameter argv[1]=%s", argv[1])
                        rv = _confd.CONFD_ERR
                elif len(argv) == 3:
                    if argv[1] == "abort":
                        # abort ongoing confirmed commit - with ID
                        self.perform_maapi_commit_abort(uinfo.usid, argv[2])
                    elif argv[1] == "confirm":
                        # confirm ongoing confirmed commit - with ID
                        self.confirm_maapi_candidate_commit(
                            uinfo.usid, argv[2])
                    elif argv[1] == "timeout":
                        # start new commit without id and with timeout
                        self.perform_maapi_candidate_confirmed_commit(
                            uinfo.usid, timeout=argv[2])
                    elif argv[1] == "persist":
                        # start new commit with id and without timeout
                        self.perform_maapi_candidate_confirmed_commit(
                            uinfo.usid, id=argv[2])
                        pass
                    else:
                        log.fatal("Unexpected parameter argv[1]=%s", argv[1])
                        rv = _confd.CONFD_ERR
                elif len(argv) == 5:
                    # start new commit with id and timeout
                    self.perform_maapi_candidate_confirmed_commit(
                        uinfo.usid, id=argv[2], timeout=argv[4])
                else:
                    log.fatal("Unexpected len(argv)=%d value", len(argv))
                    rv = _confd.CONFD_ERR

                maapi.detach2(maapisock_commit, uinfo.actx_thandle)
            except Exception as e:
                log.exception(e)
                rv = _confd.CONFD_ERR
        log.debug("<== rv=%d" % rv)
        return rv
    def cb_command(self, uinfo, path, argv):
        global maapisock
        log.debug("==> path %s argv=%r" % (path, argv))
        rv = _confd.CONFD_OK
        try:
            maapi.attach2(maapisock, maapi_example_ns.ns.hash, uinfo.usid,
                          uinfo.actx_thandle)
            mc = maapi.init_cursor(maapisock, uinfo.actx_thandle,
                                   start_log_keypath_string)
            count = 0
            keys = maapi.get_next(mc)
            while keys:
                if (maapi.exists(
                        maapisock, uinfo.actx_thandle,
                        "%s{%s}" % (start_log_keypath_string, str(keys[0])))):
                    count += 1
                log.debug("Value element count=%d" % count)
                keys = maapi.get_next(mc)
            maapi.destroy_cursor(mc)
            maapi.detach2(maapisock, uinfo.actx_thandle)
            log.debug("count=%i" % count)
            maapi.cli_write(maapisock, uinfo.usid,
                            "\nApplication startup count %d\n" % count)
        except Exception as e:
            maapi.cli_write(maapisock, uinfo.usid,
                            "Cannot determine application startup count")
            log.exception(e)
            rv = _confd.CONFD_ERR

        log.debug("<== rv=%d" % rv)
        return rv
    def cb_command(self, uinfo, path, argv):
        global maapisock
        log.debug("==> path %s argv=%r" % (path, argv))
        rv = _confd.CONFD_OK
        if len(argv) != 2:
            rv = _confd.CONFD_ERR
            log.fatal("Wrong number of arguments %i, expected 2" % len(argv))
        else:
            log.debug("value to search for is argv[1]=%s" % argv[1])
            try:
                maapi.attach2(maapisock, maapi_example_ns.ns.hash, uinfo.usid,
                              uinfo.actx_thandle)
                qstr = "%s[value < %s]" % (items_keypath_string, argv[1])
                log.debug("qstr=%s" % qstr)
                qh = maapi.query_start(maapisock, uinfo.actx_thandle, qstr,
                                       None, 0, 1, _confd.QUERY_TAG_VALUE,
                                       ["name"], [])
                log.debug("qh=%d" % qh)
                qr = maapi.query_result(maapisock, qh)
                log.debug("qr=%r" % qr)

                while qr.nresults > 0:
                    log.debug("qr.nresults=%i qr.offset=%i" %
                              (qr.nresults, qr.offset))
                    for i in xrange(qr.nresults):
                        for j in xrange(qr.nelements):
                            tag = _confd.hash2str(qr[i][j].tag)
                            val = qr[i][j].v
                            log.debug("tag=%s val=%s" % (tag, val))
                            maapi.cli_write(maapisock, uinfo.usid,
                                            "\nItem %s\n" % val)
                    maapi.query_free_result(qr)
                    qr = maapi.query_result(maapisock, qh)
                maapi.query_stop(maapisock, qh)
                maapi.detach2(maapisock, uinfo.actx_thandle)
            except Exception as e:
                log.exception(e)
                rv = _confd.CONFD_ERR
        log.debug("<== rv=%d" % rv)
        return rv
 def cb_command(self, uinfo, path, argv):
     global maapisock
     log.debug("==> path %s argv=%r" % (path, argv))
     rv = _confd.CONFD_OK
     if len(argv) != 2:
         rv = _confd.CONFD_ERR
         log.fatal("Wrong number of arguments %i, expected 2" % len(argv))
     else:
         log.debug("value to search for is argv[1]=%s" % argv[1])
         try:
             maapi.attach2(maapisock, maapi_example_ns.ns.hash, uinfo.usid,
                           uinfo.actx_thandle)
             qstr = "%s[value = %s]/name" % (items_keypath_string, argv[1])
             log.debug("qstr=%s" % qstr)
             maapi.xpath_eval(maapisock, uinfo.actx_thandle, qstr,
                              xpath_eval_iter_usid(uinfo.usid), None, "")
             maapi.detach2(maapisock, uinfo.actx_thandle)
         except Exception as e:
             log.exception(e)
             rv = _confd.CONFD_ERR
     log.debug("<== rv=%d" % rv)
     return rv
Exemple #5
0
    def iter_me(self):
        """
        tailf:action iter_me handling
        """
        print("::: iter_me :::")
        sys.stdout.flush()
        params = self.params
        uinfo = self.uinfo
        # params[0] is mode
        id_value = str(params[0].v)
        path_value = str(params[1].v)
        tid_value = int(params[2].v)

        s = connect_maapi()
        maapi.attach2(s, 0, 0, tid_value)

        iterator = DiffIterator()
        maapi.diff_iterate(s, tid_value, iterator, 0)

        maapi.detach2(s, tid_value)

        result = []
        dp.action_reply_values(uinfo, result)