Environment Management
Scenario
This section describes how to manage environments by calling APIs. For details about how to call APIs, see Making an API Request.
Process
- Create an environment and add basic resources.
- Add other required resources to the environment.
- Query the environment based on the environment ID.
Prerequisites
- You have called the API to obtain the Identity and Access Management (IAM) token for authentication. You have also set the token to an environment variable. That is, export Token={token}.
- You have obtained the endpoint of ServiceStage. For details, see Regions and Endpoints. The following uses {servicestage_endpoint} as an example.
Procedure
- Create an environment and add basic resources.
Call the API for creating an environment. The following shows an example request.
curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X POST "https://{servicestage_endpoint}/v2/{project_id}/cas/environments" -d '{ "name": "dev-env", "description": "develop environment", "enterprise_project_id": "0", "charge_mode": "provided", "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", "base_resources": [ { "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", "type": "cce" } ] }'Information similar to the following is displayed.
{ "id": "ea011e01-2eb5-453f-87bf-874e4a855abe", "name": "dev-env", "alias": null, "description": "develop environment", "project_id": "bf8523d898b64e4eb956e3be3555ca16", "enterprise_project_id": "0", "charge_mode": "provided", "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", "base_resources": [ { "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", "type": "cce" } ], "creator": "xxx", "create_time": 1578984198394, "update_time": 1578984198394 }id will be replaced with {environment_id} in the following example.
- Add other required resources to the environment.
Call the API for modifying environment resources. You can add multiple types of resources, such as Elastic Cloud Server (ECS), Cloud Container Engine (CCE), Elastic Load Balance (ELB), Cloud Service Engine (CSE), and Elastic IP (EIP) resources in the same Virtual Private Cloud (VPC) to the environment as required. The following shows an example request.
curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X PATCH "https://{servicestage_endpoint}/v2/{project_id}/cas/environments/{environment_id}/resources" -d '{ "add_optional_resources": [{ "id": "default", "type": "cse" }] }'Information similar to the following is displayed.{ "id": "ea011e01-2eb5-453f-87bf-874e4a855abe", "name": "dev-env", "alias": null, "description": "develop environment", "project_id": "bf8523d898b64e4eb956e3be3555ca16", "enterprise_project_id": "0", "charge_mode": "provided", "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", "base_resources": [ { "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", "type": "cce" } ], "optional_resources": [ { "id": "default", "type": "cse" } ], "creator": "xxx", "create_time": 1578984198394, "update_time": 1578984198394 } - Query the environment based on the environment ID.
Call the API for obtaining environment details based on the environment ID. The following shows an example request.
curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X GET "https://{servicestage_endpoint}/v2/{project_id}/cas/environments/{environment_id}"Information similar to the following is displayed.
{ "id": "ea011e01-2eb5-453f-87bf-874e4a855abe", "name": "dev-env", "alias": null, "description": "develop environment", "project_id": "bf8523d898b64e4eb956e3be3555ca16", "enterprise_project_id": "0", "charge_mode": "provided", "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", "base_resources": [ { "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", "type": "cce" } ], "optional_resources": [ { "id": "default", "type": "cse" } ], "creator": "xxx", "create_time": 1578984198394, "update_time": 1578984198394 }
Last Article: Examples
Next Article: Application Management
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.