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。
列出生命周期环境
使用此 API 调用列出您卫星上带有 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。使用 ID2的生命周期环境来创建对此环境的后续环境。编辑之前创建的
life-cycle.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 之前的生命周期环境为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