def cb_get_next(self, tctx, kp, next):
     global maapisock
     log.debug("==> kp=%s next=%d" % (kp, next))
     rv = _confd.CONFD_OK
     try:
         maapi.attach(maapisock, maapi_example_ns.ns.hash, tctx)
         if next == -1:  # first call
             next = 0
         n = 0
         mc = maapi.init_cursor(maapisock, tctx.th, items_keypath_string)
         keys = maapi.get_next(mc)
         while keys and n != next:
             log.debug("n=%d" % n)
             keys = maapi.get_next(mc)
             n += 1
         if not keys:
             log.debug("No more item entry, element not found.")
             dp.data_reply_next_key(tctx, None, -1)
         else:
             next += 1
             dp.data_reply_next_key(tctx, keys, next)
         maapi.destroy_cursor(mc)
         maapi.detach(maapisock, tctx)
     except Exception as e:
         log.exception(e)
         rv = _confd.CONFD_ERR
     log.debug("<== rv=%d" % rv)
     return rv
Exemple #2
0
    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
Exemple #3
0
    def cb_get_next(self, tctx, kp, next):
        hcp_calls[K_GET_NEXT] += 1

        if next == -1:
            next = 0  # first call - start indexing from 0

        sorted_host_names = sorted(self.db.data.keys())

        if next < len(sorted_host_names):
            curr = sorted_host_names[next]
            key_list = [V(curr, _confd.C_BUF)]  # key of the host is its name
            dp.data_reply_next_key(tctx, key_list, next + 1)
        else:
            dp.data_reply_next_key(tctx, None, 0)
        return _confd.CONFD_OK
Exemple #4
0
    def cb_get_next(self, tctx, kp, next):
        arp = self.arp
        if next == -1:  # first call
            if arp.need_arp():
                arp.collect_arp_data()

        arpentries = arp.arpdata['entries']

        if next < len(arpentries)-1:
            key = [V(next+1, _confd.C_INT64)]
            dp.data_reply_next_key(tctx, key, next+1)
        else:  # last element
            dp.data_reply_next_key(tctx, None, 0)

        return _confd.CONFD_OK
Exemple #5
0
    def cb_get_next(self, tctx, kp, next):
        arp = self.arp
        if next == -1:  # first call
            if arp.need_arp():
                arp.collect_arp_data()
            next = 0

        arpentries = arp.arpdata['entries']
        curr = arpentries[next]

        if next < len(arpentries) - 1:
            key = [V(curr['ip'], V.C_IPV4), V(curr['iface'])]
            dp.data_reply_next_key(tctx, key, next + 1)
        else:  # last element
            dp.data_reply_next_key(tctx, None, 0)

        return _confd.CONFD_OK
Exemple #6
0
    def cb_get_next(self, tctx, kp, next):
        icp_calls[K_GET_NEXT] += 1

        if next == -1:  # First call, index from 0...
            next = 0

        hostname = str(kp[-3][0])
        host = self.db.get_host(hostname)

        key_list = None
        next_next = -1
        if host is not None and next < host.iface_count():
            sorted_iface_names = sorted(host.ifaces.keys())
            key_list = [V(sorted_iface_names[next], _confd.C_BUF)]
            next_next = next + 1

        dp.data_reply_next_key(tctx, key_list, next_next)
        return _confd.CONFD_OK
    def cb_get_next(self, tctx, kp, next):
        list_tag = kp[0].tag
        next_key = None

        if ns.smp_server == list_tag:
            sorted_server_names = sorted(running_db.keys())
            num_servers = len(sorted_server_names)
            index = next - (-1)
            if index < num_servers:
                next_key = confd.Value(sorted_server_names[index], confd.C_BUF)
        else:
            raise NotImplementedError

        if next_key is None:
            dp.data_reply_next_key(tctx, keys=None, next=-1)
        else:
            dp.data_reply_next_key(tctx, keys=[next_key], next=next + 1)
        return confd.CONFD_OK
Exemple #8
0
 def cb_get_next(self, tctx, kp, next):
     global icp_calls_get_next
     icp_calls_get_next += 1
     hostkey = self.db.get_hostkey(kp)
     host = self.db.find_host(hostkey)
     if next == -1:  # First call
         next = 0
     if host is None:
         dp.data_reply_next_key(tctx, None, -1)
         return _confd.CONFD_OK
     if host.ifaces == []:
         dp.data_reply_next_key(tctx, None, -1)
         return _confd.CONFD_OK
     if next < len(host.ifaces):
         iface = host.ifaces[next]
         key = [V(iface.name)]
         dp.data_reply_next_key(tctx, key, next + 1)
     else:
         dp.data_reply_next_key(tctx, None, 0)
     return _confd.CONFD_OK
Exemple #9
0
 def cb_get_next(self, tctx, kp, next):
     global hcp_calls_get_next
     hcp_calls_get_next += 1
     if next == -1 and self.db.list == []:  # First call on empty list
         dp.data_reply_next_key(tctx, None, -1)
         return _confd.CONFD_OK
     elif next == -1:  # First call, nonempty list
         next = 0
     if next < len(self.db.list):
         curr = self.db.list[next]
         key = [V(curr.name)]  # The key of the host is its name
         dp.data_reply_next_key(tctx, key, next + 1)
     else:  # last element
         dp.data_reply_next_key(tctx, None, 0)
     return _confd.CONFD_OK
    def cb_get_next(self, tctx, kp, next):
        helper = TransformDataHelper(tctx.th)

        def _get_next_folder(keypath, next_counter, folder_cursor):
            """ Retrieve next "/folder-user{}/managed-folder{}" record that
                belongs to the user from the "/user-storage/ownership{}".
            """
            v_username = keypath[-2][0]
            v_user_id = helper.get_user_id_value(v_username)

            if -1 == next_counter:
                keys = maapi.find_next(mc=folder_cursor,
                                       type=confd.FIND_NEXT,
                                       inkeys=[v_user_id])
            else:
                keys = maapi.get_next(folder_cursor)

            if keys:
                # second key of the "ownership" list is our storage name
                v_storage_id = keys[1]
                if is_users_storage(v_user_id, v_storage_id):
                    return parse_folder_id_value(v_storage_id)

            return None

        def _get_next_user(user_cursor):
            """ Retrieve next "/folder-user{}" from the "/user-storage/user".
            """
            keys = maapi.get_next(user_cursor)
            if keys:
                v_username = maapi.get_elem(maapi_socket, helper.th,
                                            kp_user(keys[0]) + '/username')
                return v_username
            return None

        def _get_list_cursor(next_counter, path, cursors):
            """ Return MAAPI cursor for iterating the YANG list
                depending on the "next" value and request keypath.
                CDB path string is used as cursor identifier to simplify API.
            """
            if -1 == next_counter:
                if path in cursors:
                    maapi.destroy_cursor(cursors[path])
                cursors[path] = maapi.init_cursor(maapi_socket, helper.th,
                                                  path)
            else:
                if path not in cursors:
                    raise ValueError("Jumping into uninitialized iteration!")
            return cursors[path]

        def _get_next_content_type(keypath, next_counter):
            """ Return next content-type value from the low level bit-field
                "/user-storage/ownership{}/content-type".
            """
            v_user_id = helper.get_user_id_value(keypath[-2][0])
            if v_user_id is None:
                return None
            v_bitmask = optional_get_elem(
                maapi_socket, helper.th,
                kp_content_type(v_user_id, keypath[1][0]))
            if v_bitmask is None:
                return None
            bitmask_int = int(v_bitmask)
            # get all the bits that are set in the low level value
            bits_set = [
                bit for bit in ct_bits_to_enum.keys()
                if bool(bitmask_int & bit)
            ]
            # return N-th bit from the set depending on the "next"
            if next_counter + 1 < len(bits_set):
                mapping_index = bits_set[next_counter + 1]
                return confd.Value(ct_bits_to_enum[mapping_index],
                                   confd.C_ENUM_VALUE)
            else:
                return None

        list_tag = kp[0].tag

        # our transformed model has only one key in any of the lists,
        # thus no array here, only 1 item as a "next_key"
        if ns_folders.folders_folder_user == list_tag:
            cursor = _get_list_cursor(next, USER_PATH, self.get_next_cursors)
            next_key = _get_next_user(cursor)
        elif ns_folders.folders_managed_folder == list_tag:
            cursor = _get_list_cursor(next, OWNER_PATH, self.get_next_cursors)
            next_key = _get_next_folder(kp, next, cursor)
        elif ns_folders.folders_content_type == list_tag:
            next_key = _get_next_content_type(kp, next)
        else:
            raise NotImplementedError

        if next_key is None:
            dp.data_reply_next_key(tctx, keys=None, next=-1)
        else:
            dp.data_reply_next_key(tctx, keys=[next_key], next=next + 1)
        return confd.CONFD_OK