6.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。
6.2.1. 列出生命周期环境 复制链接链接已复制到粘贴板!
使用此 API 调用列出您 Satellite 上 ID 为 1 的默认组织的所有当前生命周期环境。
API 请求
$ curl \
--header "Accept:application/json" \
--header "Content-Type:application/json" \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/katello/api/organizations/1/environments \
| python3 -m json.tool`
API 响应
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
6.2.2. 创建链接的生命周期环境 复制链接链接已复制到粘贴板!
使用本示例创建生命周期环境的路径。此流程使用 ID 为 1 的默认库环境,作为创建生命周期环境的起点。
API 流程
选择您要用作起点的现有生命周期环境。使用其 ID 列出环境。在这种情况下,ID 为
1的环境:请求示例:
$ curl \ --request GET \ --user My_User_Name:My_Password \ 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 文件,如
life-cycle.json:{"organization_id":1,"label":"api-dev","name":"API Development","prior":1}使用
prior选项设置为1来创建生命周期环境。请求示例:
$ curl \ --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request POST \ --user My_User_Name:My_Password \ --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。使用 ID2的生命周期环境来创建此环境的后续者。编辑之前创建的
life-cycle.json文件,以更新标签、name和before值。{"organization_id":1,"label":"api-qa","name":"API QA","prior":2}将
prior选项设置为2来创建生命周期环境。请求示例:
$ curl \ --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request POST \ --user My_User_Name:My_Password \ --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。
6.2.3. 更新生命周期环境 复制链接链接已复制到粘贴板!
您可以使用 PUT 命令更新生命周期环境。这个示例请求使用 ID 3 更新生命周期环境的描述。
API 请求
$ curl \
--header "Accept:application/json" \
--header "Content-Type:application/json" \
--request POST \
--user My_User_Name:My_Password \
--data '{"description":"Quality Acceptance Testing"}' \
https://satellite.example.com/katello/api/environments/3 \
| python3 -m json.tool
API 响应
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
6.2.4. 删除生命周期环境 复制链接链接已复制到粘贴板!
如果没有后续者,您可以删除生命周期环境。因此,使用以下格式的命令以相反的顺序删除它们:
API 请求
$ curl \
--request DELETE \
--user My_User_Name:My_Password \
https://satellite.example.com/katello/api/environments/:id