def create_qos(self, context, qos):
        """ Create a qos and its default queue. """
        qos = qos['qos']
        default_queue = self._extract_default_queue_from_qos_param(qos)

        if qos['rate'] < default_queue['rate']:
            raise ext_qos.QosRateTooSmall(id=None, rate=qos['rate'])
        qos_target = self._check_qos_target(
            context, qos['target_type'], qos['target_id'], qos['direction'])

        tenant_id = self._get_tenant_id_for_create(context, qos)
        qos_id = qos.get('id', uuidutils.generate_uuid())
        default_queue_id = uuidutils.generate_uuid()

        with context.session.begin(subtransactions=True):
            qos_db = Qos(
                id=qos_id, tenant_id=tenant_id,
                name=qos['name'], description=qos['description'],
                direction=qos['direction'],
                port_id=qos_target['port_id'],
                router_id=qos_target['router_id'],
                rate=qos['rate'], burst=qos['burst'], cburst=qos['cburst'],
                default_queue_id=default_queue_id)
            qos_queue_db = QosQueue(
                id=default_queue_id, tenant_id=tenant_id,
                qos_id=qos_id, parent_id=None, prio=7,
                rate=default_queue['rate'], ceil=default_queue['ceil'],
                burst=default_queue['burst'], cburst=default_queue['cburst'])
            context.session.add(qos_db)
            context.session.add(qos_queue_db)

        return self._make_qos_dict(qos_db)