def cb_get_elem(self, tctx, kp): icp_calls[K_GET_ELEM] += 1 hostkey = str(kp[-3][0]) ifacekey = str(kp[-6][0]) iface = self.db.get_host_iface(hostkey, ifacekey) if iface is None: dp.data_reply_not_found(tctx) return _confd.CONFD_OK tag = str(kp[0]) if tag == 'name': val = V(iface.name) elif tag == 'ip': val = V(iface.ip, _confd.C_IPV4) elif tag == 'mask': val = V(iface.mask, _confd.C_IPV4) elif tag == 'enabled': val = V(iface.enabled, _confd.C_BOOL) else: return _confd.CONFD_ERR dp.data_reply_value(tctx, val) return _confd.CONFD_OK
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_case(self, tctx, kp, choice): helper = TransformDataHelper(tctx.th) v_user_id = helper.get_user_id_value(kp[-2][0]) if v_user_id is None: dp.data_reply_not_found(tctx) return confd.CONFD_OK v_auth_type = helper.get_auth_type_value(v_user_id) tag = at_enum_to_tags[int(v_auth_type)] dp.data_reply_value( tctx, confd.Value((tag, ns_folders.hash), confd.C_XMLTAG)) return confd.CONFD_OK
def cb_get_elem(self, tctx, kp): hostkey = self.db.get_hostkey(kp) host = self.db.find_host(hostkey) if host is None: dp.data_reply_not_found(tctx) return _confd.CONFD_OK tag = self.db.find_tag(kp) val = None if tag == 'name': val = V(host.name) elif tag == 'domain': val = V(host.domain) elif tag == 'defgw': val = V(host.defgw, V.C_IPV4) else: return _confd.CONFD_ERR dp.data_reply_value(tctx, val) return _confd.CONFD_OK
def cb_get_elem(self, tctx, kp): helper = TransformDataHelper(tctx.th) v_result = None v_username = kp[-2][0] v_user_id = helper.get_user_id_value(v_username) list_tag = kp[2].tag if ns_folders.folders_managed_folder == list_tag: v_folder_id = kp[1][0] v_storage_id = concat_storage_id_value(v_user_id, v_folder_id) else: v_folder_id = None v_storage_id = None leaf_tag = kp[0].tag if ns_folders.folders_username == leaf_tag: # user with specific username actually does exists - as we got # his user_id in the previous step via storage-id retrieval if v_user_id is not None: v_result = v_username elif ns_folders.folders_auth_password == leaf_tag: v_auth_type = helper.get_auth_type_value(v_user_id) if ns_storage.storage_at_password == v_auth_type: v_result = optional_get_elem(maapi_socket, helper.th, kp_auth_password(v_user_id)) elif ns_folders.folders_auth_key == leaf_tag: v_auth_type = helper.get_auth_type_value(v_user_id) if ns_storage.storage_at_key == v_auth_type: v_result = optional_get_elem(maapi_socket, helper.th, kp_auth_key(v_user_id)) elif ns_folders.folders_folder_id == leaf_tag: if (v_storage_id is not None and maapi.exists( maapi_socket, helper.th, kp_storage(v_storage_id))): # existence verified in low level, return value from keypath # - it saves the need to extract storage-id substring again... v_result = v_folder_id else: raise NotImplementedError (dp.data_reply_value(tctx, v_result) if v_result is not None else dp.data_reply_not_found(tctx)) return confd.CONFD_OK
def cb_get_elem(self, tctx, kp): global maapisock log.debug("==> kp=%s" % kp) rv = _confd.CONFD_OK try: maapi.attach(maapisock, maapi_example_ns.ns.hash, tctx) if isinstance( kp[0], _confd.XmlTag ) and kp[0].tag == maapi_example_ns.ns.maapi_example_value: val = maapi.get_elem( maapisock, tctx.th, "%s{%s}/value" % (items_keypath_string, kp[1][0])) dp.data_reply_value(tctx, val) else: dp.data_reply_not_found(tctx) maapi.detach(maapisock, tctx) except Exception as e: log.exception(e) rv = _confd.CONFD_ERR log.debug("<== rv=%d" % rv) return rv
def cb_get_elem(self, tctx, kp): arp = self.arp if arp.need_arp(): arp.collect_arp_data() arpentry = arp.find_entry(kp) if arpentry is None: dp.data_reply_not_found(tctx) return _confd.CONFD_OK tag = arp.find_tag(kp) val = None if tag == 'hwaddr': entryelem = arpentry[tag] if entryelem is None: dp.data_reply_not_found(tctx) return _confd.CONFD_OK val = V(entryelem) elif tag == 'permanent': if arpentry['perm']: val = V(True, V.C_BOOL) else: val = V(False, V.C_BOOL) elif tag == 'published': if arpentry['pub']: val = V(True, V.C_BOOL) else: val = V(False, V.C_BOOL) elif tag == 'ip': entryelem = arpentry[tag] val = V(entryelem, V.C_IPV4) elif tag == 'ifname': entryelem = arpentry['iface'] val = V(entryelem, V.C_STR) else: return _confd.CONFD_ERR dp.data_reply_value(tctx, val) return _confd.CONFD_OK
def cb_get_elem(self, tctx, kp): hcp_calls[K_GET_ELEM] += 1 v_result = None host_key = str(kp[-3][0]) # /hosts/host{name}/... host = self.db.get_host(host_key) if host is not None: tag = str(kp[0]) if tag == 'name': v_result = V(host.name, _confd.C_BUF) elif tag == 'domain': v_result = V(host.domain, _confd.C_BUF) elif tag == 'defgw': v_result = V(host.defgw, _confd.C_IPV4) else: raise NotImplementedError if v_result is not None: dp.data_reply_value(tctx, v_result) else: dp.data_reply_not_found(tctx) return _confd.CONFD_OK
def cb_get_elem(self, tctx, kp): [hostkey, ifacekey] = self.db.get_hostifacekey(kp) iface = self.db.find_iface(hostkey, ifacekey) if iface is None: dp.data_reply_not_found(tctx) return _confd.CONFD_OK tag = self.db.find_iface_tag(kp) val = None if tag == 'name': val = V(iface.name) elif tag == 'ip': val = V(iface.ip, V.C_IPV4) elif tag == 'mask': val = V(iface.mask, V.C_IPV4) elif tag == 'enabled': if iface.enabled: val = V(True, V.C_BOOL) else: val = V(False, V.C_BOOL) else: return _confd.CONFD_ERR dp.data_reply_value(tctx, val) return _confd.CONFD_OK
def cb_get_elem(self, tctx, kp): v_result = None server_name = str(kp[1][0]) if server_name in running_db: leaf_tag = kp[0].tag if ns.smp_name == leaf_tag: v_result = confd.Value(server_name, confd.C_BUF) elif ns.smp_ip == leaf_tag: ip = running_db[server_name][0] v_result = confd.Value(ip, confd.C_IPV4) elif ns.smp_port == leaf_tag: port = int(running_db[server_name][1]) v_result = confd.Value(port, confd.C_UINT16) else: raise NotImplementedError (dp.data_reply_value(tctx, v_result) if v_result is not None else dp.data_reply_not_found(tctx)) return confd.CONFD_OK
def cb_exists_optional(self, tctx, kp): helper = TransformDataHelper(tctx.th) def _check_leaf_exists(keypath): """ Implements existence check for high level leaves. """ leaf_tag = keypath[0].tag if ns_folders.folders_auth_none == leaf_tag: # /folder-user{bob}/auth-none v_user_id = helper.get_user_id_value(keypath[1][0]) v_auth_type = helper.get_auth_type_value(v_user_id) return ns_storage.storage_at_none == v_auth_type else: raise NotImplementedError def _check_entry_exists(keypath): """ Implements existence check for high level leaf-list entries. """ list_tag = keypath[1].tag if ns_folders.folders_content_type == list_tag: # /folder-user{bob}/managed-folder{home}content-type{archive} v_user_id = helper.get_user_id_value(keypath[-2][0]) v_bits_set = optional_get_elem( maapi_socket, helper.th, kp_content_type(v_user_id, keypath[-4][0])) if v_bits_set is not None: bits_set = int(v_bits_set) bit_to_check = ct_enum_to_bits[int(keypath[0][0])] return bool(bits_set & bit_to_check) return False else: raise NotImplementedError query_exists = (_check_leaf_exists(kp) if isinstance( kp[0], confd.XmlTag) else _check_entry_exists(kp)) (dp.data_reply_found(tctx) if query_exists else dp.data_reply_not_found(tctx)) return confd.CONFD_OK