def _get_qos_conf_scheme(self, context, qos):
        root_class = {'rate': qos.rate, 'ceil': qos.rate, 'subclasses': [],
                      'prio': 0}
        if qos.burst:
            root_class['burst'] = qos.burst
        if qos.cburst:
            root_class['cburst'] = qos.cburst

        scheme = {}
        effective_queues = {}
        for queue in qos.queues:
            if queue.attached_filters or queue.id == qos.default_queue_id:
                _queue = queue
                while _queue is not None:
                    try:
                        self.allocate_tc_class_for_queue(context, _queue)
                    except ext_qos.AllocateTCClassFailure:
                        LOG.warn("Failed to allocate tc class for queue %s.",
                                 _queue.id)
                        # Don't apply any qos scheme for this qos because the
                        # number of queues exceeds Linux's support(65535).
                        # However, this should RARELY happen.
                        return None
                    if _queue.id not in effective_queues:
                        effective_queues[_queue.id] = _queue
                        _queue = _queue.parent_queue
                    else:
                        # Current queue and its ancestors are all recorded.
                        _queue = None

        for queue in effective_queues.values():
            scheme[queue.tc_class] = self._make_qos_queue_dict_for_agent(queue)
            if queue.parent_queue is None:
                root_class['subclasses'].append(queue.tc_class)

        # Add root class
        scheme[1] = root_class
        return scheme