Workflows

If you have not yet installed the cookbook plugin on your Pulp installation, please follow our User Setup. These documents will assume you have the environment installed and ready to go.

The REST API examples here use httpie to perform the requests. The httpie commands below assume that the user executing the commands has a .netrc file in the home directory. The .netrc should have the following configuration:

machine localhost
login admin
password admin

If you configured the admin user with a different password, adjust the configuration accordingly. If you prefer to specify the username and password with each request, please see httpie documentation on how to do that.

To make these workflows copy/pastable, we make use of environment variables. The first variable to set is the hostname and port:

$ export BASE_ADDR=http://<hostname>:24817

This documentation makes use of the jq tool to parse the json received from requests, in order to get the unique urls generated when objects are created. To follow this documentation as-is please install the jq library/binary with:

$ sudo dnf install jq

Scripting

The workflows use bash functions that wait for the completion of a Pulp task if necessary. These are defined in docs/_scripts/base.sh:

: "${BASE_ADDR:=http://localhost}"
: "${CONTENT_ADDR:=http://localhost}"

# Poll a Pulp task until it is finished.
wait_until_task_finished() {
    local task_url=$1
    while true
    do
        local response=$(http --pretty format "$task_url")
        local state=$(jq -r .state <<< "${response}")
        case ${state} in
            failed|canceled)
                cat <<< "${response}" >&2
                echo "Task in final state: ${state}" >&2
                break
                ;;
            completed)
                cat <<< "${response}"
                break
                ;;
            *)
                echo "Waiting for task completion. Task:" >&2
                cat <<< "${response}" >&2
                sleep 1
                ;;
        esac
    done
}

pulp_http() {
    local response=$(http --pretty format "$@")
    local task_url=$(jq -r '.task' <<< "$response")
    if [[ "$task_url" == "null" ]]; then
        cat <<< "$response"
    else
        wait_until_task_finished "$BASE_ADDR$task_url"
    fi
}

To execute the examples given in the workflows (and to develop own workflows), source base.sh first:

source docs/_script/base.sh