How to use pulpcore-manager since Satellite 6.10

Updated

Invocation of pulpcore-manager on Satellite

To invoke its shell, run:

sudo -u pulp PULP_SETTINGS='/etc/pulp/settings.py' DJANGO_SETTINGS_MODULE='pulpcore.app.settings' pulpcore-manager shell

To execute a Python script, just redirect input to the shell - here we also redirect output to an output file:

sudo -u pulp PULP_SETTINGS='/etc/pulp/settings.py' DJANGO_SETTINGS_MODULE='pulpcore.app.settings' pulpcore-manager shell < content_counts.py > content_counts.txt

Examples of usage

In all below examples:

  • check carefully indentation that defines blocks of code for a loop or if-branch.
  • the same applies to empty lines (also at the end of a code example) which define end of such a block

Find repomd.xml for a given repository

  • knowing distribution base path:
from pulp_rpm.app.models.repository import RpmDistribution, RpmPublication

RpmDistribution.objects.get(base_path='MyOrg/ProductionLE/CV_RHEL8/content/dist/rhel8/8/x86_64/appstream/os').publication.published_metadata.get(relative_path__contains='repomd.xml').contentartifact_set.first().artifact.file.path

Output should be a filepath like '/var/lib/pulp/media/artifact/72/95c3de6cc2df887c39d8ad74d9a4b57960332981222e308af5c76d3ad57e83' with the required metadata content

  • knowing repository uuid and version:
from pulp_rpm.app.models.repository import RpmDistribution, RpmPublication
from pulpcore.app.models.repository import RepositoryVersion

RepositoryVersion.objects.get(repository='88835194-54a7-4af4-a062-6f572edeec0b', number=1, complete=True).publication_set.first().published_metadata.get(relative_path__contains='updateinfo').contentartifact_set.first().artifact.file.path

(there should be a way to provide repo name but tat is pending now)

Find all metadata artifacts for a given repository

from pulp_rpm.app.models.repository import RpmDistribution, RpmPublication

for pm in RpmDistribution.objects.get(base_path='RedHat/Library/cv_rhel8_appstream/content/dist/rhel8/8/x86_64/appstream/os').publication.published_metadata.all():
    print("%s   %s" % (pm.relative_path, pm.contentartifact_set.first().artifact.file.path))


Find all repomd.xml files for any yum repository

In example below, we filter the repositories to those publishing under /content/dist/rhel8/8/x86_64/appstream/os path - so any RHEL8 Appstream repository, in either Content View:

from pulp_rpm.app.models.repository import RpmDistribution, RpmPublication
from pulpcore.app.models.repository import RepositoryVersion

for rpmd in RpmDistribution.objects.filter(base_path__contains='/content/dist/rhel8/8/x86_64/appstream/os').all():
    pub = rpmd.publication
    print("%s %s %s %s" % \
        (pub.published_metadata.get(relative_path__contains='repomd.xml').contentartifact_set.first().artifact.file.path, rpmd.base_path, pub.repository_version, pub.repository.rpm_rpmrepository.last_sync_details))


Find (counts of) orphaned content and artifacts

Print counts of orphaned content and artifacts:

from pulpcore.app.models.content import Artifact, Content
from pulpcore.app.models.publication import PublishedMetadata
 
# Orphaned Content
print(f"\nNum Orphaned Content : {Content.objects.filter(version_memberships__isnull=True).exclude(pulp_type=PublishedMetadata.get_pulp_type()).count()}")
 
# Orphaned Artifacts
print(f"Num Orphaned Artifacts : {Artifact.objects.filter(content_memberships__isnull=True).count()}")

To list individual orphans:

for oc in Content.objects.filter(version_memberships__isnull=True).exclude(pulp_type=PublishedMetadata.get_pulp_type()).all():
  print(oc)

for oa in Artifact.objects.filter(content_memberships__isnull=True).all():
  print(f"artifact {oa} stored in file {oa.file.path}")

To inspect details of an orphaned Content, check its type first (e.g. for pulp_type=rpm.advisory, check oc.rpm_updaterecord details).

Orphans lists since Sat6.11

from pulpcore.app.models.content import Content
minutes_since_touched = 1

Content.objects.orphaned(minutes_since_touched).all()
Artifact.objects.orphaned(minutes_since_touched).all()

Bigger scripts utilizing pulpcore-manager

For more KB articles/solutions related to Red Hat Satellite 6.x Pulp 3.0 Issues, please refer to the Consolidated Troubleshooting Article for Red Hat Satellite 6.x Pulp 3.0-related Issues

SBR
Product(s)
Category
Components
Article Type