5.2. 使用生命周期阶段
Satellite 将应用程序生命周期分为生命周期,它们代表了应用程序生命周期的每个阶段。生命周期阶段从环境路径链接到。要使用 API 创建链接的生命周期阶段,请使用 prior_id 参数。
您可以在 https://satellite.example.com/apidoc/v2/lifecycle_environments.html 中找到对生命周期阶段的内置 API 引用。API 路由包括 /katello/api/environments 和 /katello/api/organizations/:organization_id/environments。
以下示例请求使用 python3 来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python 而不是 python3。
列出生命周期阶段
使用此 API 调用列出 Satellite 上针对 ID 为 1 的默认组织的所有当前生命周期环境。
请求示例:
$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" \
--request GET --user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/organizations/1/environments \
| python3 -m json.tool`
响应示例:
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
创建链接的生命周期环境
使用此示例创建生命周期阶段的路径。
此流程使用默认 ID 为 1 的库环境,作为创建生命周期阶段的起点。
选择您要用作起点的现有生命周期阶段。使用其 ID 列出环境,本例中为 ID 为
1的环境:请求示例:
$ curl --request GET --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/environments/1 \ | python3 -m json.tool响应示例:
output omitted "id": 1, "label": "Library", output omitted "prior": null, "successor": null, output truncated创建包含以下内容的 JSON 文件,
如 lifecycle-cycle.json:{"organization_id":1,"label":"api-dev","name":"API Development","prior":1}将之前的选项设置为
1,创建生命周期环境。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data @life-cycle.json \ https://satellite.example.com/katello/api/environments \ | python3 -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在命令输出中,您可以看到此生命周期环境的 ID 为
2,并且之前的生命周期阶段为1。使用 ID 为2的生命周期阶段,创建此环境的成功者。编辑之前创建的 Life
-cycle.json文件,更新标签、name和之前的值。{"organization_id":1,"label":"api-qa","name":"API QA","prior":2}创建一个生命周期环境,
使用之前选项设置为2。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data @life-cycle.json \ https://satellite.example.com/katello/api/environments \ | python3 -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在命令输出中,您可以看到此生命周期环境的 ID 为
3,并且之前的生命周期阶段为2。
更新生命周期阶段
您可以使用 PUT 命令更新生命周期阶段。
这个示例请求更新了 ID 为 3 的生命周期阶段的描述。
请求示例:
$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" \
--request POST --user sat_username:sat_password --insecure \
--data '{"description":"Quality Acceptance Testing"}' \
https://satellite.example.com/katello/api/environments/3 \
| python3 -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
删除生命周期阶段
您可以删除一个没有后续者的生命周期环境。因此,使用以下格式的命令以相反的顺序删除它们:
请求示例:
$ curl --request DELETE --user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/environments/:id