Upload Content

The section shows how to upload content to Pulp. The attached snippets use the utilities httpie and jq. Learn more about them at Workflows.

Upload a file to Pulp (Create an Artifact)

#!/usr/bin/env bash

echo "Creating a dummy file at path FILE_CONTENT to upload."
export FILE_CONTENT=$(head /dev/urandom | tr -dc a-z | head -c10)
echo $FILE_CONTENT > test_upload.txt

echo "Uploading the file to Pulp, creating an artifact, storing ARTIFACT_HREF."
export ARTIFACT_HREF=$(http --form POST $BASE_ADDR/pulp/api/v3/artifacts/ \
    file@./test_upload.txt \
    | jq -r '.pulp_href')

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

Artifact GET Response:

{
    "pulp_created": "2019-05-16T20:07:48.066089Z",
    "pulp_href": "/pulp/api/v3/artifacts/cff8078a-826f-4f7e-930d-422c2f134a07/",
    "file": "artifact/97/144ab16c9aa0e6072d471d6aebe7c21083e21359137e676445bfeb4051ba25",
    "md5": "5148c996f375ed5aab94ef6993df90a0",
    "sha1": "a7bd2bcaf1d68505f3e8b2cfe3505d01b31db306",
    "sha224": "18a167922b68a3fb8f2d9a71fa78f9776f5402dce4b3d97d5cea2559",
    "sha256": "97144ab16c9aa0e6072d471d6aebe7c21083e21359137e676445bfeb4051ba25",
    "sha384": "4cd006bfac7f2e41baa8c411536579b134daeb3ad666310d21463f384a7020360703fc5538b4eca724033498d514e144",
    "sha512": "e1aae6bbc6fd24cf890b82ffa824629518e6e93935935a0b7c008fbd9fa59f08aa32a7d8580b31a65b21caa0f48e737d8e555eaa777912bea5772799f64a2dd4",
    "size": 11
}

Reference (pulpcore): Artifact API Usage

Create file content from an Artifact

#!/usr/bin/env bash

echo 'Create File Content from the artifact and save as environment variable'
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/content/file/files/ \
    relative_path="test_upload.txt" \
    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 content
echo "Set CONTENT_HREF from finished task."
export CONTENT_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')

echo "Inspecting new file content"
http $BASE_ADDR$CONTENT_HREF

Content GET Response:

{
    "artifact": "/pulp/api/v3/artifacts/cff8078a-826f-4f7e-930d-422c2f134a07/",
    "pulp_created": "2019-05-16T20:07:48.929374Z",
    "pulp_href": "/pulp/api/v3/content/file/files/c23def43-44bc-45f4-8a6f-0310285f5339/",
    "md5": "3b4fd267e71a1a8e8746893fcc91e5b5",
    "relative_path": "test_upload.txt",
    "sha1": "6fd76062f3680be44de9ed6a4b80bdce512dd620",
    "sha224": "3b518d0e428c4e5996ec6861960a7640770bc8bbbe16775b1dfc1e81",
    "sha256": "b671500c402128babf4f4e51afc552584df3db501bb1a0bd3ee96dc121228a9c",
    "sha384": "7f90e3b612defd1d85d51c3a0efca932fb1a6cdee4a11dd532edd8302dfe7860d3ce4d50b2ed73d984a83e6c6265e54b",
    "sha512": "91c823e2d547e4073d4c47f73f36122acf60a722100d6e592a68aae0b6ba8ee12cd40dbed75cade7ad1a1f7e197a06ed2ad184da8c0055b5473bcf07aaf7e44c"
}

Reference: File Content API Usage

Create a repository foo

#!/usr/bin/env bash
export REPO_NAME=$(head /dev/urandom | tr -dc a-z | head -c5)

echo "Creating a new repository named $REPO_NAME."
export REPO_HREF=$(http POST $BASE_ADDR/pulp/api/v3/repositories/file/file/ name=$REPO_NAME \
  | jq -r '.pulp_href')

echo "Inspecting repository."
http $BASE_ADDR$REPO_HREF

Repository GET Response:

{
    "pulp_created": "2019-05-16T19:23:55.224096Z",
    "pulp_href": "/pulp/api/v3/repositories/file/file/680f18e7-0513-461f-b067-436b03285e4c/",
    "latest_version_href": null,
    "versions_href": "/pulp/api/v3/repositories/file/file/680f18e7-0513-461f-b067-436b03285e4c/versions/",
    "description": null,
    "name": "foo"
}

Reference (pulpcore): Repository API Usage

Add content to repository foo

#!/usr/bin/env bash

echo "Kick off a task to add content to a repository, storing TASK_URL env variable"
export TASK_URL=$(http POST $BASE_ADDR$REPO_HREF'modify/' \
    add_content_units:="[\"$CONTENT_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

echo "Retrieving REPOVERSION_HREF from task"
export REPOVERSION_HREF=$(http $BASE_ADDR$TASK_URL| jq -r '.created_resources | first')

echo "Inspecting repository version."
http $BASE_ADDR$REPOVERSION_HREF

Repository Version GET Response:

{
    "pulp_created": "2019-05-16T20:07:50.363735Z",
    "pulp_href": "/pulp/api/v3/repositories/file/file/0d908664-e300-4223-869b-fc5d2cef285f/versions/1/",
    "base_version": null,
    "content_summary": {
        "added": {
            "file.file": {
                "count": 1,
                "href": "/pulp/api/v3/content/file/files/?repository_version_added=/pulp/api/v3/repositories/file/file/0d908664-e300-4223-869b-fc5d2cef285f/versions/1/"
            }
        },
        "present": {
            "file.file": {
                "count": 1,
                "href": "/pulp/api/v3/content/file/files/?repository_version=/pulp/api/v3/repositories/file/file/0d908664-e300-4223-869b-fc5d2cef285f/versions/1/"
            }
        },
        "removed": {}
    },
    "number": 1
}

Reference (pulpcore): Repository Version Creation API Usage