Bookmark this page

Guided Exercise: Query the Red Hat Satellite API

Query the Red Hat Satellite REST API by using authenticated curl commands.

Outcomes

  • Use the Red Hat Satellite API to perform common administrative queries.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start api-overview

Instructions

  1. Log in to the satellite system as the student user.

    [student@workstation ~]$ ssh student@satellite
    [student@satellite ~]$
  2. Use the REST API to list the Satellite hostnames.

    [student@satellite ~]$ curl --request GET --user admin:redhat \
    https://satellite.lab.example.com/api/v2/hosts \
    | python3 -m json.tool | grep '"name":'
    ...output omitted...
                "name": "satellite.lab.example.com",
                    "name": "satellite.lab.example.com",
                    "name": "satellite.lab.example.com",
                "name": "servera.lab.example.com",
                        "name": "OperationsServerBase",
                        "name": "Development"
                "name": "serverb.lab.example.com",
                        "name": "FinanceServerBase",
                        "name": "Build"
                "name": "serverc.lab.example.com",
                        "name": "OperationsServerBase",
                        "name": "QA"
                "name": "serverd.lab.example.com",
                        "name": "FinanceServerBase",
                        "name": "Test"
  3. List the name, ID, and other information about the organization. Your output matches the organizations that you created in your classroom environment. Note the id value for the Operations organization.

    [student@satellite ~]$ curl --request GET --user admin:redhat \
    https://satellite.lab.example.com/katello/api/organizations \
    | python3 -m json.tool
    ...output omitted...
        "results": [
            {
                "created_at": "2021-12-03 13:18:50 UTC",
                "description": null,
                "id": 1,
                "label": "Default_Organization",
                "name": "Default Organization",
                "title": "Default Organization",
                "updated_at": "2021-12-03 13:30:32 UTC"
            },
            {
                "created_at": "2022-07-18 09:31:20 UTC",
                "description": "Operations Department",
                "id": 3,
                "label": "Operations",
                "name": "Operations",
                "title": "Operations",
                "updated_at": "2022-07-18 09:31:54 UTC"
            }
        ],
    ...output omitted...
  4. List the lifecycle environments for the Operations organization. Use the ID value for the Operations organization, from the previous command output.

    [student@satellite ~]$ curl --request GET --user admin:redhat \
    https://satellite.lab.example.com/katello/api/organizations/3/environments \
    | python3 -m json.tool
    ...output omitted...
                "name": "Development",
                "organization": {
                    "id": 3,
                    "label": "Operations",
                    "name": "Operations"
                },
    ...output omitted...
                "name": "Library",
                "organization": {
                    "id": 3,
                    "label": "Operations",
                    "name": "Operations"
                },
    ...output omitted...
                "name": "Production",
                "organization": {
                    "id": 3,
                    "label": "Operations",
                    "name": "Operations"
                },
    ...output omitted...
                "name": "QA",
                "organization": {
                    "id": 3,
                    "label": "Operations",
                    "name": "Operations"
                },
    ...output omitted...
  5. Create a Training organization with Global product training as the description.

    1. Create a /home/student/create-training-organization.json data file that contains the organization parameters.

      [student@satellite ~]$ cat /home/student/create-training-organization.json
      {"name":"Training", "description":"Global product training"}
    2. Create the Training organization by submitting the parameter file as a POST request. Note the id and library_id values for the Training organization.

      [student@satellite ~]$ curl --header "Content-Type:application/json" \
      --request POST --user admin:redhat \
      --data @create-training-organization.json \
      https://satellite.lab.example.com/katello/api/organizations \
      | python3 -m json.tool
      ...output omitted...
          "created_at": "2022-07-18 10:13:35 UTC",
          "default_content_view_id": 4,
          "description": "Global product training",
          "domains": [],
          "environments": [],
          "hostgroups": [],
          "hosts_count": 0,
          "id": 5,
          "label": "Training",
          "library_id": 6,
          "locations": [],
          "media": [],
          "name": "Training",
      ...output omitted...
  6. Create the Devel lifecycle environment in the Training organization.

    1. Create the /home/student/create-devel-environment.json data file that contains the lifecycle environment parameters. Use the Training organization ID and the Library ID from the previous command output.

      [student@satellite ~]$ cat /home/student/create-devel-environment.json
      {"organization_id":5, "name":"Devel", "prior":6}
    2. Create the Devel lifecycle environment by submitting the parameter file as a POST request. Note the id number for the Devel lifecycle environment.

      [student@satellite ~]$ curl --header "Content-Type:application/json" \
      --request POST --user admin:redhat \
      --data @create-devel-environment.json \
      https://satellite.lab.example.com/katello/api/environments \
      | python3 -m json.tool
      ...output omitted...
          "created_at": "2022-07-18 10:17:04 UTC",
          "description": null,
          "id": 7,
          "label": "Devel",
          "library": false,
          "name": "Devel",
          "organization": {
              "id": 5,
              "label": "Training",
              "name": "Training"
          },
          "organization_id": 5,
          "permissions": {
              "create_lifecycle_environments": true,
              "destroy_lifecycle_environments": true,
              "edit_lifecycle_environments": true,
              "promote_or_remove_content_views_to_environments": true,
              "view_lifecycle_environments": true
          },
          "prior": {
              "id": 6,
              "name": "Library"
          },
      ...output omitted...
  7. Modify the Devel lifecycle environment by adding a Pre-testing development description.

    1. Create a /home/student/update-devel-environment.json data file with the lifecycle environment parameters to update.

      [student@satellite ~]$ cat /home/student/update-devel-environment.json
      {"description":"Pre-testing development"}
    2. Modify the Devel lifecycle environment by submitting the parameter file as a PUT request. Verify that your command uses a PUT request for modifying an existing object. Use the Devel lifecycle environment ID from the previous command output.

      [student@satellite ~]$ curl --header "Content-Type:application/json" \
      --request PUT --user admin:redhat \
      --data @update-devel-environment.json \
      https://satellite.lab.example.com/katello/api/environments/7 \
      | python3 -m json.tool
      ...output omitted...
          "created_at": "2022-07-18 10:17:04 UTC",
          "description": "Pre-testing development",
          "id": 7,
          "label": "Devel",
          "library": false,
          "name": "Devel",
          "organization": {
              "id": 5,
              "label": "Training",
              "name": "Training"
          },
      ...output omitted...
          "prior": {
              "id": 6,
              "name": "Library"
          },
      ...output omitted...
  8. Add the Test lifecycle environment with a Pre-production testing description. The Test lifecycle environment follows the Devel lifecycle environment.

    1. Create the /home/student/create-test-environment.json data file with the lifecycle environment parameters, including a description. Use the ID value for the Devel lifecycle environment from the previous command output as the prior environment value for the Test environment.

      [student@satellite ~]$ cat /home/student/create-test-environment.json
      {"organization_id":"5", "name":"Test", "description":"Pre-production testing", "prior":7}
    2. Create the Test lifecycle environment by submitting the parameter file as a POST request. Note the id number for the Test lifecycle environment.

      [student@satellite ~]$ curl --header "Content-Type:application/json" \
      --request POST --user admin:redhat \
      --data @create-test-environment.json \
      https://satellite.lab.example.com/katello/api/environments \
      | python3 -m json.tool
      ...output omitted...
          "created_at": "2022-07-18 10:22:09 UTC",
          "description": "Pre-production testing",
          "id": 8,
          "label": "Test",
          "library": false,
          "name": "Test",
          "organization": {
              "id": 5,
              "label": "Training",
              "name": "Training"
          },
      ...output omitted...
          "prior": {
              "id": 7,
              "name": "Devel"
          },
      ...output omitted...
  9. Add the Prod lifecycle environment with a Production environment description. The Prod lifecycle environment follows the Test lifecycle environment.

    1. Create the /home/student/create-prod-environment.json data file with lifecycle environment parameters, including a description. Use the ID value for the Test lifecycle environment from the previous command output as the prior environment value for the Prod environment.

      [student@satellite ~]$ cat /home/student/create-prod-environment.json
      {"organization_id":5, "name":"Prod", "description":"Production environment", "prior":8}
    2. Create the Prod lifecycle environment by submitting the parameter file as a POST request.

      [student@satellite ~]$ curl --header "Content-Type:application/json" \
      --request POST --user admin:redhat \
      --data @create-prod-environment.json \
      https://satellite.lab.example.com/katello/api/environments \
      | python3 -m json.tool
      ...output omitted...
          "created_at": "2022-07-18 10:24:41 UTC",
          "description": "Production environment",
          "id": 9,
          "label": "Prod",
          "library": false,
          "name": "Prod",
          "organization": {
              "id": 5,
              "label": "Training",
              "name": "Training"
          },
      ...output omitted...
          "prior": {
              "id": 8,
              "name": "Test"
          },
      ...output omitted...
  10. Delete the Training organization and its lifecycle environments. Deleting an organization also deletes its subordinate objects.

    1. Delete the Training organization by submitting a DELETE request by using the Training organization ID.

      [student@satellite ~]$ curl --header "Content-Type:application/json" \
      --request DELETE --user admin:redhat \
      https://satellite.lab.example.com/katello/api/organizations/5 \
      | python3 -m json.tool
      ...output omitted...
          "action": "Destroy organization 'Training'",
          "available_actions": {
              "cancellable": false,
              "resumable": false
          },
          "cli_example": null,
          "ended_at": null,
          "humanized": {
              "action": "Destroy",
              "errors": [],
      ...output omitted...
              "organization": {
                  "id": 5,
                  "label": "Training",
                  "name": "Training"
              },
      ...output omitted...
    2. List the organization information to verify that the Training organization no longer exists.

      [student@satellite ~]$ curl --request GET --user admin:redhat \
      https://satellite.lab.example.com/katello/api/organizations \
      | python3 -m json.tool
      ...output omitted...
  11. Return to the workstation system as the student user.

    [student@satellite ~]$ exit
    logout
    Connection to satellite closed.
    [student@workstation ~]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish api-overview

Revision: rh403-6.11-3ad886e