コード例 #1
0
async def pre_migrate_lazycatalog(content_type):
    """
    A coroutine to pre-migrate Pulp 2 Lazy Catalog Entries (LCE) for a specific content type.

    There is no [quick] way to identify whether the LCE were changed or not in Pulp 2. So every
    time all LCE for the specified type are pre-migrated, nothing is skipped.

    Args:
        content_type: A content type for which LCE should be pre-migrated
    """
    batch_size = 10000
    pulp2lazycatalog = []

    # delete previous pre-migration results since it might be outdated
    Pulp2LazyCatalog.objects.filter(
        pulp2_content_type_id=content_type).delete()

    mongo_lce_qs = LazyCatalogEntry.objects(unit_type_id=content_type)
    total_lce = mongo_lce_qs.count()
    for i, lce in enumerate(mongo_lce_qs.batch_size(batch_size)):
        item = Pulp2LazyCatalog(pulp2_importer_id=lce.importer_id,
                                pulp2_unit_id=lce.unit_id,
                                pulp2_content_type_id=lce.unit_type_id,
                                pulp2_storage_path=lce.path,
                                pulp2_url=lce.url,
                                pulp2_revision=lce.revision)
        pulp2lazycatalog.append(item)

        save_batch = (i and not (i + 1) % batch_size or i == total_lce - 1)
        if save_batch:
            Pulp2LazyCatalog.objects.bulk_create(pulp2lazycatalog,
                                                 ignore_conflicts=True)
            pulp2lazycatalog = []
コード例 #2
0
def pre_migrate_lazycatalog(content_type):
    """
    A coroutine to pre-migrate Pulp 2 Lazy Catalog Entries (LCE) for a specific content type.

    There is no [quick] way to identify whether the LCE were changed or not in Pulp 2. So every
    time all LCE for the specified type are pre-migrated, nothing is skipped.

    Args:
        content_type: A content type for which LCE should be pre-migrated
    """
    batch_size = 5000
    pulp2lazycatalog = []

    mongo_lce_qs = LazyCatalogEntry.objects(unit_type_id=content_type)
    for lce in mongo_lce_qs.batch_size(batch_size).as_pymongo().no_cache():
        item = Pulp2LazyCatalog(pulp2_importer_id=lce['importer_id'],
                                pulp2_unit_id=lce['unit_id'],
                                pulp2_content_type_id=lce['unit_type_id'],
                                pulp2_storage_path=lce['path'],
                                pulp2_url=lce['url'],
                                pulp2_revision=lce['revision'],
                                is_migrated=False)
        pulp2lazycatalog.append(item)

        if len(pulp2lazycatalog) >= batch_size:
            Pulp2LazyCatalog.objects.bulk_create(pulp2lazycatalog, ignore_conflicts=True)
            pulp2lazycatalog.clear()
    else:
        Pulp2LazyCatalog.objects.bulk_create(pulp2lazycatalog, ignore_conflicts=True)