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 perform_maapi_commit_status(self, usid): """ Print to CLI status info if there is ongoing confirmed commit. NOTE: maapi_confirmed_commit_in_progress return usid of ongoing commit (ConfD User Guide says 1) :param usid: session id for maapi_cli_write :return CONFD_OK or confd error value """ global maapisock_commit log.debug("usid=%d", usid) stat = maapi.confirmed_commit_in_progress(maapisock_commit) log.debug("stat=%d", stat) if stat != 0: maapi.cli_write(maapisock_commit, usid, "Ongoing commit in progress!\n") maapi.cli_write(maapisock_commit, usid, "Session id: %d\n" % stat) else: maapi.cli_write(maapisock_commit, usid, "No ongoing commit in progress!\n")
def perform_maapi_candidate_confirmed_commit(self, usid, id=None, timeout=None): """ Start confirmed commit. :param usid: session id for maapi_cli_write :param id: persist id for the commit :param timeout: timeout for the commit (default is used when None) :return CONFD_OK or confd error value """ global maapisock_commit log.debug("usid=%d, id=%r, timeout=%r" % (usid, id, timeout)) maapi.candidate_confirmed_commit_persistent( maapisock_commit, self.timeout_to_int(timeout), id, None) maapi.cli_write(maapisock_commit, usid, "Confirmed commit started!\n") if id is not None: maapi.cli_write(maapisock_commit, usid, "Persist: %s\n" % id) if timeout is not None: maapi.cli_write(maapisock_commit, usid, "Timeout: %s\n" % timeout)
def perform_maapi_commit_abort(self, usid, id=None): """ Abort ongoig commit operation :param usid: session id for maapi_cli_write :param id: persist id for the commit :return CONFD_OK or confd error value """ log.debug("usid=%d, id=%r" % (usid, id)) try: maapi.candidate_abort_commit_persistent(maapisock_commit, id) maapi.cli_write(maapisock_commit, usid, "Confirmed commit aborted!\n") if id is not None: maapi.cli_write(maapisock_commit, usid, "Persist id: %s\n" % id) except Exception as e: maapi.cli_write(maapisock_commit, usid, "Commit not aborted! (Is persist id correct?)\n") log.warn("Failed to abort commit! usid=%d, id=%r" % (usid, id)) log.exception(e) raise e
def confirm_maapi_candidate_commit(self, usid, id=None): """ Copy candidate to running. Optionally use persist id of ongoing commit operation. :param usid: session id for maapi_cli_write :param id: persist id or None """ log.debug("usid=%d, id=%r" % (usid, id)) try: maapi.candidate_commit_persistent(maapisock_commit, id) maapi.cli_write(maapisock_commit, usid, "Commit successfully confirmed!\n") if id is not None: maapi.cli_write(maapisock_commit, usid, "Persist id: %s\n" % id) except Exception as e: maapi.cli_write( maapisock_commit, usid, "Commit not confirmed! (Is persist id correct?)\n") log.warn("Failed to confirm commit! usid=%i, id=%r" % (usid, id)) log.exception(e) raise e
def xpath_eval_iter(kp, val): log.debug("==> kp=%s val=%s" % (kp, val)) rv = _confd.ITER_CONTINUE maapi.cli_write(maapisock, usid, "\nItem %s\n" % val) log.debug("<== rv=%d" % rv) return rv