Upload Content

Content can be added to a repository not only by synchronizing from a remote source but also by uploading.

Bulk Upload

Upload artifacts

Using pulp-cli commands :

#!/usr/bin/env bash

# Get an RPM package
if [[ -n "$1" ]]; then
  export REMOTE_FILE="$1"
else
  export REMOTE_FILE="https://fixtures.pulpproject.org/rpm-signed/squirrel-0.1-1.noarch.rpm"
fi
curl -O "${REMOTE_FILE}"
PKG="$(basename ${REMOTE_FILE})"
export PKG

# Upload it as an Artifact
echo "Upload an RPM package."
ARTIFACT_HREF=$(pulp artifact upload --file "${PKG}" | jq -r '.pulp_href')
ARTIFACT_SHA256=$(pulp show --href "${ARTIFACT_HREF}" | jq -r '.sha256')
export ARTIFACT_HREF
export ARTIFACT_SHA256

echo "Inspecting artifact."
pulp show --href "${ARTIFACT_HREF}"

Using httpie to talk directly to the REST API :

#!/usr/bin/env bash

# Get an RPM package
if [[ -n "$1" ]]; then
  export REMOTE_FILE="$1"
else
  export REMOTE_FILE="https://fixtures.pulpproject.org/rpm-signed/squirrel-0.1-1.noarch.rpm"
fi
curl -O "$REMOTE_FILE"
PKG="$(basename $REMOTE_FILE)"
export PKG

# Upload it as an Artifact
echo "Upload an RPM package."
ARTIFACT_HREF=$(http --form POST "$BASE_ADDR"/pulp/api/v3/artifacts/ \
    file@./"$PKG" | jq -r '.pulp_href')
export ARTIFACT_HREF

echo "Inspecting artifact."
http "$BASE_ADDR""$ARTIFACT_HREF"

Artifact GET response:

{
    "file": "artifact/49/921db74808725e9228f6e8f4c25c65d81ba2382d5b97f26814b9fd80977402",
    "md5": "0c9013e04fa09f48d1996b3fb4c11724",
    "pulp_created": "2019-11-27T13:48:15.394730Z",
    "pulp_href": "/pulp/api/v3/artifacts/c3440ebb-99bc-44a0-915c-ee06cc5d4001/",
    "sha1": "183a50aa0d25fdd0faa6642e4a82ff8870f96656",
    "sha224": "9b199695812ff2fab161aaa7873920b12c743b8b32f37be926bce649",
    "sha256": "49921db74808725e9228f6e8f4c25c65d81ba2382d5b97f26814b9fd80977402",
    "sha384": "59b3d541c495abee3d0295ae87aadfb9fd20280757fd2373160120d8690435c23ae48aed4f60d8cf0713f9c4876f7ffa",
    "sha512": "eaf47a730d2397e1b58d813914b0bad2b61aa90e5fa0b58101e98654f84d3a30826c2b67f0de96c5690b2bbf5bf847fa5b9f0cfdb970d52b94b56a94d68ca7c2",
    "size": 2473
}

Create content from artifacts

Using pulp-cli commands :

#!/usr/bin/env bash

# Create RPM package from an artifact
echo "Create RPM content from artifact."
PACKAGE_HREF=$(pulp rpm content create \
               --sha256 "${ARTIFACT_SHA256}" \
               | jq -r '.pulp_href')
export PACKAGE_HREF

echo "Inspecting Package."
pulp show --href "${PACKAGE_HREF}"

Using httpie to talk directly to the REST API :

#!/usr/bin/env bash

# Create RPM package from an artifact
echo "Create RPM content from artifact."
TASK_URL=$(http POST "$BASE_ADDR"/pulp/api/v3/content/rpm/packages/ \
    artifact="$ARTIFACT_HREF" | jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new package (RPM content)
echo "Set PACKAGE_HREF from finished task."
PACKAGE_HREF=$(http "$BASE_ADDR""$TASK_URL"| jq -r '.created_resources | first')
export PACKAGE_HREF

echo "Inspecting Package."
http "$BASE_ADDR""$PACKAGE_HREF"

Package GET response (after task complete):

{
    "arch": "noarch",
    "artifact": "/pulp/api/v3/artifacts/c3440ebb-99bc-44a0-915c-ee06cc5d4001/",
    "changelogs": [],
    "checksum_type": "sha256",
    "conflicts": [],
    "description": "A dummy package of fox",
    "enhances": [],
    "epoch": "0",
    "files": [
        [
            "",
            "/tmp/",
            "fox.txt"
        ]
    ],
    "is_modular": false,
    "location_base": "",
    "location_href": "fox-1.1-2.noarch.rpm",
    "name": "fox",
    "obsoletes": [],
    "pkgId": "49921db74808725e9228f6e8f4c25c65d81ba2382d5b97f26814b9fd80977402",
    "provides": [
        [
            "fox",
            "EQ",
            "0",
            "1.1",
            "2",
            false
        ]
    ],
    "pulp_created": "2019-11-27T13:48:16.462655Z",
    "pulp_href": "/pulp/api/v3/content/rpm/packages/9ee09de7-5fff-4805-8b30-9ab95493317d/",
    "recommends": [],
    "release": "2",
    "requires": [],
    "rpm_buildhost": "smqe-ws15",
    "rpm_group": "Internet/Applications",
    "rpm_header_end": 2329,
    "rpm_header_start": 928,
    "rpm_license": "GPLv2",
    "rpm_packager": "",
    "rpm_sourcerpm": "fox-1.1-2.src.rpm",
    "rpm_vendor": "",
    "size_archive": 292,
    "size_installed": 42,
    "size_package": 2473,
    "suggests": [],
    "summary": "A dummy package of fox",
    "supplements": [],
    "time_build": 1331831360,
    "time_file": 1574862495,
    "url": "http://tstrachota.fedorapeople.org",
    "version": "1.1"
}

Add content to repository foo

Note

It is recommended to omit the relative_path and have Pulp generate a common pool location. This will be /repo/Packages/s/squirrel-0.1-1.noarch.rpm as shown below.

When specifying a relative_path, make sure to add the exact name of the package including its name, version, release and arch as in squirrel-0.1-1.noarch.rpm. It is composed of the name-version-release.arch.rpm.

relative_path="squirrel-0.1-1.noarch.rpm"

Using pulp-cli commands :

#!/usr/bin/env bash

# Add created RPM content to repository
echo "Add created RPM Package to repository."
TASK_HREF=$(pulp rpm repository content modify \
            --repository "${REPO_NAME}" \
            --add-content "[{\"pulp_href\": \"${PACKAGE_HREF}\"}]" \
            2>&1 >/dev/null | awk '{print $4}')

# After the task is complete, it gives us a new repository version
echo "Set REPOVERSION_HREF from finished task."
REPOVERSION_HREF=$(pulp show --href "${TASK_HREF}" \
                   | jq -r '.created_resources | first')

echo "Inspecting RepositoryVersion."
pulp show --href "${REPOVERSION_HREF}"

Using httpie to talk directly to the REST API :

#!/usr/bin/env bash

# Add created RPM content to repository
echo "Add created RPM Package to repository."
TASK_URL=$(http POST "$BASE_ADDR""$REPO_HREF"'modify/' \
    add_content_units:="[\"$PACKAGE_HREF\"]" | jq -r '.task')
export TASK_URL

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new repository version
echo "Set REPOVERSION_HREF from finished task."
REPOVERSION_HREF_WITH_PKG=$(http "$BASE_ADDR""$TASK_URL" | jq -r '.created_resources | first')
export REPOVERSION_HREF_WITH_PKG

echo "Inspecting RepositoryVersion."
http "$BASE_ADDR""$REPOVERSION_HREF_WITH_PKG"

Repository Version GET response (after task complete):

{
    "base_version": null,
    "content_summary": {
        "added": {
            "rpm.package": {
                "count": 1,
                "href": "/pulp/api/v3/content/rpm/packages/?repository_version_added=/pulp/api/v3/repositories/rpm/rpm/805de89c-1b1d-432c-993e-3eb9a3fedd22/versions/1/"
            }
        },
        "present": {
            "rpm.package": {
                "count": 1,
                "href": "/pulp/api/v3/content/rpm/packages/?repository_version=/pulp/api/v3/repositories/rpm/rpm/805de89c-1b1d-432c-993e-3eb9a3fedd22/versions/1/"
            }
        },
        "removed": {}
    },
    "number": 1,
    "pulp_created": "2019-11-27T13:48:18.326333Z",
    "pulp_href": "/pulp/api/v3/repositories/rpm/rpm/805de89c-1b1d-432c-993e-3eb9a3fedd22/versions/1/"
}

One-shot Upload

Advisory upload

Advisory upload requires a file or an artifact containing advisory information in the JSON format. Repository is an optional argument to create new repository version with uploaded advisory.

Using pulp-cli commands :

#!/usr/bin/env bash

# Get advisory
echo '{
    "updated": "2014-09-28 00:00:00",
    "issued": "2014-09-24 00:00:00",
    "id": "RHSA-XXXX:XXXX"
}' > advisory.json
export ADVISORY="advisory.json"

# Upload advisory
echo "Upload advisory in JSON format."
TASK_URL=$(http --form POST "${BASE_ADDR}"/pulp/api/v3/content/rpm/advisories/ \
    file@./"${ADVISORY}" repository="${REPO_HREF}" | jq -r '.task')
export TASK_URL

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished "${BASE_ADDR}""${TASK_URL}"

# After the task is complete, it gives us a new repository version
echo "Set ADVISORY_HREF from finished task."
ADVISORY_HREF=$(http "${BASE_ADDR}""${TASK_URL}" \
                | jq -r '.created_resources | .[] | match(".*advisories.*") | .string')
export ADVISORY_HREF

echo "Inspecting advisory."
pulp show --href "${ADVISORY_HREF}"

Using httpie to talk directly to the REST API :

#!/usr/bin/env bash

# Get advisory
echo '{
    "updated": "2014-09-28 00:00:00",
    "issued": "2014-09-24 00:00:00",
    "id": "RHSA-XXXX:XXXX"
}' > advisory.json
export ADVISORY="advisory.json"

# Upload advisory
echo "Upload advisory in JSON format."
TASK_URL=$(http --form POST "$BASE_ADDR"/pulp/api/v3/content/rpm/advisories/ \
    file@./"$ADVISORY" repository="$REPO_HREF" | jq -r '.task')
export TASK_URL

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished "$BASE_ADDR""$TASK_URL"

# After the task is complete, it gives us a new repository version
echo "Set ADVISORY_HREF from finished task."
ADVISORY_HREF=$(http "$BASE_ADDR""$TASK_URL" \
    | jq -r '.created_resources | .[] | match(".*advisories.*") | .string')
export ADVISORY_HREF

echo "Inspecting advisory."
http "$BASE_ADDR""$ADVISORY_HREF"

Advisory GET response (after task complete):

{
    "artifact": "/pulp/api/v3/artifacts/b4e3a95c-eb82-410e-8f90-aba59d573058/",
    "description": "",
    "fromstr": "nobody@redhat.com",
    "id": "RHSA-XXXX:XXXX",
    "issued_date": "2014-09-24 00:00:00",
    "pkglist": [],
    "pulp_created": "2019-11-27T13:48:20.364919Z",
    "pulp_href": "/pulp/api/v3/content/rpm/advisories/51169df4-f7c6-46df-953c-1714e5dd5869/",
    "pushcount": "",
    "reboot_suggested": false,
    "references": [],
    "release": "",
    "rights": "",
    "severity": "",
    "solution": "",
    "status": "",
    "summary": "",
    "title": "",
    "type": "",
    "updated_date": "",
    "version": ""
}