5.2. 使用生命周期环境
卫星将应用程序生命周期划分为不同的生命周期环境,这些环境代表应用程序生命周期的每个阶段。生命周期环境从路径链接到。要使用 API 创建链接的生命周期环境,请使用 prior_id 参数。
您可以在 https://satellite.example.com/apidoc/v2/lifecycle_environments.html 找到用于生命周期环境的内置 API 参考。API 路由包括 /katello/api/environments 和 /katello/api/organizations/:organization_id/environments。
列出生命周期环境
使用此 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 \
| python -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 \ | python -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}使用之前选项设置为
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 \ | 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在命令输出中,您可以看到此生命周期环境的 ID 为
2,且该生命周期环境是1。使用 ID 为2的生命周期环境,为这个环境创建一个成功。编辑之前创建的
生命周期.json文件,更新标签、名称和之前的值。{"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 \ | 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在命令输出中,您可以看到此生命周期环境的 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 \
| 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
删除生命周期环境
您可以删除一个生命周期环境,只要它没有成功。因此,使用以下格式的命令以相反顺序删除它们:
请求示例:
$ curl --request DELETE --user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/environments/:id