def cb_get_elem(self, tctx, kp): # get the row index ~ process id ptr = re.search(r'\{(.*)\}', str(kp)) [key] = ptr.group(1).split() index = int(key) # find it in our artificial cache entry = None for proc in self._procData: if proc.pid == index: entry = proc if entry is None: dp.data_reply_not_found(tctx) return _confd.OK # get the requested element tag # note that tag can be obtained also via numeric value from keypath, # not only as a string like we do here... ptr = re.search(r'\}/(.*)', str(kp)) [tag] = ptr.group(1).split() if tag == ns.model_pid_: val = _confd.Value(entry.pid, _confd.C_UINT32) elif tag == ns.model_cpu_: val = _confd.Value(entry.cpu, _confd.C_UINT32) else: print("Unsupported leaf tag requested! ({0})".format(tag)) return _confd.ERR dp.data_reply_value(tctx, val) return _confd.OK
def cb_get_next(self, tctx, kp, next): if next == -1: # first call ix = 0 else: ix = next if ix < len(self._procData): keys = [_confd.Value(self._procData[ix].pid, _confd.C_UINT32)] dp.data_reply_next_key(tctx, keys, ix + 1) else: # last element dp.data_reply_next_key(tctx, None, 0) return _confd.CONFD_OK
def make_tag_value(ns_hash, tag, value): """ Wrapper to create a _confd.TagValue """ return _confd.TagValue(_confd.XmlTag(ns_hash, tag), _confd.Value(value))