更新时间:2023-07-31 GMT+08:00
环境管理
场景描述
本章节指导用户通过API实现环境管理。API的调用方法请参见如何调用API。
流程介绍
- 创建环境,添加基础资源
- 为环境添加其他需要的资源
- 根据环境ID查询环境
前提条件
操作步骤
- 创建环境。调用创建环境接口,请求示例如下:
curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X POST "https://{servicestage_endpoint}/v3/{project_id}/cas/environments" -d ' { "name": "env-Kubernetes", "description": "test environment", "enterprise_project_id": "0", "charge_mode": "provided", "vpc_id": "081c539d-ed09-43b0-81d7-a87603e528b7", "labels": [ { "key": "testKey", "value": "testValue" } ], "deploy_mode": "container" }'
返回结果:{ "id": "9cd33350-5d7f-46ec-ba6d-40ed793f0eb7", "name": "env-Kubernetes", "description": "test environment", "creator": "test_user", "enterprise_project_id": "0", "vpc_id": "081c539d-ed09-43b0-81d7-a87603e528b7", "deploy_mode": "container", "vm_cluster_size": 50, "labels": [ { "key": "testKey", "value": "testValue" } ], "create_time": 1689564968283, "update_time": 1689564968283, "resources": [] }
得到的id,后续示例中以{environment_id}代替。
- 为环境添加资源。调用根据环境ID修改环境资源接口。根据自己已有的资源和需求,可以将和环境相同vpc下的ecs/cce(v3接口环境分为了容器环境和虚机环境),elb,cse,eip等多种类型的资源添加到环境中。请求示例如下:
curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X PUT "https://{servicestage_endpoint}/v3/{project_id}/cas/environments/{environment_id}/resources" -d ' { "resources": [ { "id": "d2917177-3436-4e53-a5bc-706c3529e0e7", "name": "elb-pu6a", "type": "elb" } ] }'
返回结果:{ "resources": [ { "id": "d2917177-3436-4e53-a5bc-706c3529e0e7", "type": "elb", "name": "elb-pu6a" } ] }
- 根据环境id查询环境。调用根据环境ID获取环境详细信息接口。查询环境详细信息,请求示例如下:
curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X GET "https://{servicestage_endpoint}/v3/{project_id}/cas/environments/{environment_id}"
返回结果:
{ "id": "9cd33350-5d7f-46ec-ba6d-40ed793f0eb7", "name": "env-Kubernetes", "description": "test environment", "creator": "test_user", "enterprise_project_id": "0", "vpc_id": "081c539d-ed09-43b0-81d7-a87603e528b7", "deploy_mode": "container", "vm_cluster_size": 50, "labels": [ { "key": "testKey", "value": "testValue" } ], "create_time": 1689564968283, "update_time": 1689574181240, "resources": [ { "id": "d2917177-3436-4e53-a5bc-706c3529e0e7", "type": "elb", "name": "elb-pu6a" } ] }
父主题: 应用示例