Red Hat Training

A Red Hat training course is available for Red Hat Satellite

4.6. Working with Life Cycle Environments

As explained in the Life Cycle Environments section of the Server Administration Guide, Application life cycles are divided into life cycle environments, which represent each stage of the application life cycle. Life cycle environments are linked to form an environment path. To create linked Life Cycle Environments using the API, make use of the prior_id parameter.
You can find the built-in API reference for Life Cycle Environments at https://satellite6.example.com/apidoc/v2/lifecycle_environments.html. The API routes include /katello/api/environments and /katello/api/organizations/:organization_id/environments.
You can list all the current Life Cycle Environments on your Satellite, for the default organization 1, as follows:
$ curl -H "Accept:application/json,version=2" \
-H "Content-Type:application/json" -X GET \
-u sat_user:sat_password -k \
https://satellite6.example.com/katello/api/organizations/1/environments | python -m json.tool
A newly installed Satellite would have an output with a section similar to the following:
      output omitted
   "description": null,
   "id": 1,
   "label": "Library",
   "library": true,
   "name": "Library",
   "organization": {
        "id": 1,
        "label": "Default_Organization",
        "name": "Default Organization"
   },
   "permissions": {
       "destroy_lifecycle_environments": false,
       "edit_lifecycle_environments": true,
       "promote_or_remove_content_views_to_environments": true,
       "view_lifecycle_environments": true
   },
   "prior": null,
   "successor": null,
      output truncated
In the procedure below the default Library environment, with ID 1, is used as the starting point for creating Life Cycle Environments.

Procedure 4.3. Creating Linked Life Cycle Environments

  1. Choose an existing Life Cycle Environment that you want to use as a starting point. List the environment using its ID, in this case the environment with ID 1:
    $ curl -X GET -s -k -u sat_user:sat_password \
    https://satellite6.example.com/katello/api/environments/1 | python -m json.tool
    	output omitted
       "id": 1,
       "label": "Library",
    	output omitted
        "prior": null,
        "successor": null,
    	output truncated
  2. Create a new Life Cycle Environment using the prior option set to 1:
    1. Create a JSON file, for example, life-cycle.json, with the following contents: {"organization_id":1,"label":"api-dev","name":"API Development","prior":1}
    2. Enter a command as follows:
      $ curl -H "Accept:application/json,version=2" \
      -H "Content-Type:application/json" -X POST \
      -u sat_user:sat_password -k \
      -d @life-cycle.json \
      https://satellite6.example.com/katello/api/environments \
      | python -m json.tool
            output omitted
          "description": null,
          "id": 2,
          "label": "api-dev",
          "library": false,
          "name": "API Development",
          "organization": {
              "id": 1,
              "label": "Default_Organization",
              "name": "Default Organization"
          },
          "permissions": {
              "destroy_lifecycle_environments": true,
              "edit_lifecycle_environments": true,
              "promote_or_remove_content_views_to_environments": true,
              "view_lifecycle_environments": true
          },
         "prior": {
              "id": 1,
              "name": "Library"
          },
      	output truncated
    In the command output you can see the ID for this Life Cycle Environment is 2, and the Life Cycle Environment prior to this one is 1. This signifies that Life Cycle Environment 1 and 2 are linked. The Life Cycle Environment ID 2 is used when creating a successor to this environment.
  3. Create another Life Cycle Environment, using the prior option set to 2:
    1. Edit the previously created life-cycle.json, updating the label, name, and prior values: {"organization_id":1,"label":"api-qa","name":"API QA","prior":2}
    2. Enter a command as follows:
      $ curl -H "Accept:application/json,version=2" \
      -H "Content-Type:application/json" -X POST \
      -u sat_user:sat_password -k \
      -d @life-cycle.json \
      https://satellite6.example.com/katello/api/environments \
      | python -m json.tool
            output omitted
         "description": null,
         "id": 3,
          "label": "api-qa",
          "library": false,
          "name": "API QA",
          "organization": {
              "id": 1,
              "label": "Default_Organization",
              "name": "Default Organization"
          },
          "permissions": {
              "destroy_lifecycle_environments": true,
              "edit_lifecycle_environments": true,
              "promote_or_remove_content_views_to_environments": true,
              "view_lifecycle_environments": true
          },
         "prior": {
              "id": 2,
              "name": "API Development"
          },
          "successor": null,
      	output truncated
    In the command output you can see the ID for this Life Cycle Environment is 3, and the Life Cycle Environment prior to this one is 2. This signifies that Life Cycle Environment 2 and 3 are linked.

Updating a Life Cycle Environment

A Life Cycle Environment can be updated using a PUT command. For example:
$ curl -H "Accept:application/json,version=2" \
-H "Content-Type:application/json" -X POST \
-u sat_user:sat_password -k \
 -d '{"description":"Quality Acceptance Testing"}' \
https://satellite6.example.com/katello/api/environments/3 \
| python -m json.tool
      output omitted
 "description": "Quality Acceptance Testing",
    "id": 3,
    "label": "api-qa",
    "library": false,
    "name": "API QA",
    "organization": {
        "id": 1,
        "label": "Default_Organization",
        "name": "Default Organization"
    },
    "permissions": {
        "destroy_lifecycle_environments": true,
        "edit_lifecycle_environments": true,
        "promote_or_remove_content_views_to_environments": true,
        "view_lifecycle_environments": true
    },
    "prior": {
        "id": 2,
        "name": "API Development"
    },
	output truncated

Deleting a Life Cycle Environment

A Life Cycle Environment can be deleted provided it has no successor. Therefore, delete them in reverse order using a command in the following format:
curl -X DELETE -s -k -u sat_user:sat_password https://satellite6.example.com/katello/api/environments/:id