Example 2: Creating an AS Group
Scenarios
This section describes how to create an AS group by calling APIs. For details, see Calling APIs.
An AS group consists of a collection of instances that apply to the same scenario. It is the basis for enabling or disabling AS policies and performing scaling actions. An AS group specifies parameters, such as the maximum number of instances, expected number of instances, minimum number of instances, VPC, subnet, and load balance settings.
Constraints
- Up to 10 AS groups per account can be created by default.
- If ELB is configured, AS automatically binds or unbinds a load balancer to or from an instance when the instance is added or removed from the AS group.
- If an AS group uses ELB health check, the listening ports on the load balancers must be enabled for the instances in the AS group. Enable the listening ports in security groups. For details, see Adding a Security Group Rule.
Involved APIs
To create an AS group, you need to perform several operations, such as querying a user token, security groups, and AS configurations. The following APIs are required:
- Obtaining a User Token: Determine the user token that can be used to authenticate the calling of other APIs.
- Querying VPCs: Determine the VPC for the ECSs in the AS group to be created.
- Querying Security Groups: Determine the security group to which the ECSs in the AS group will be added.
- Querying Subnets: Determine the subnet for the ECSs in the AS group.
- Querying AS configurations: Determine the AS configuration of the AS group.
- Querying AZs: Determine the AZ where the AS group to be created is located.
- Creating an AS Group: Create an AS group using the VPC and AS configuration you specify.
- Querying an AS Group: Verify the AS group creation.
Procedure
- Determine the user token that can be used to authenticate the calling of other APIs.
- View the user token. For details, see Obtaining a User Token.
- Obtain the value of X-Subject-Token in the response header.
- Determine the VPC.
- View VPCs. For details, see Querying VPCs.
- Select a VPC based on site requirements and record the VPC ID.
- Determine the security group.
- View security groups. For details, see Querying Security Groups.
- Select a security group based on site requirements and record the security group ID.
- Determine the subnet.
- View subnets in the specified VPC based on VPC ID. For details, see Querying Subnets.
- Select a subnet based on site requirements and record the subnet ID.
- Determine the AS configuration.
- View AS configurations.
- API
URI format: GET /autoscaling-api/v1/{project_id}/scaling_configuration
For details about the API request parameters, see Querying AS Configurations.
- Example request
GET: https://{Endpoint}/autoscaling-api/v1/0605767c2e80d5762fd0c0146a10aaf2/scaling_configuration?start_number=0&limit=10
Obtain {endpoint} from Regions and Endpoints.
- Example response
{ "limit": 20, "total_number": 2, "start_number": 0, "scaling_configurations": [ { "tenant": "ce061903a53545dcaddb300093b477d2", "scaling_configuration_id": "6afe46f9-7d3d-4046-8748-3b2a1085ad86", "scaling_configuration_name": " config_name_1", "instance_config": { "disk": [ { "size": 40, "volume_type": "SATA", "disk_type": "SYS" }, { "size": 100, "volume_type": "SATA", "disk_type": "DATA" } ], "personality": null, "instance_name": null, "instance_id": null, "flavorRef": "103", "imageRef": "37ca2b35-6fc7-47ab-93c7-900324809c5c", "key_name": "keypair01", "public_ip": null, "user_data": null, "metadata": {}, "security_groups": [{ "id": "6c22a6c0-b5d2-4a84-ac56-51090dcc33be" }], }, "create_time": "2015-07-23T01:04:07Z" } ] }
- Select an AS configuration based on site requirements and record the AS configuration ID.
- View AS configurations.
- Determine the AZ.
- View AZs. For details, see Querying AZs.
- Select an AZ as required and record the AZ name.
- Create an AS group using the VPC and AS configuration you specify.
- API
URI format: POST /autoscaling-api/v1/{project_id}/scaling_group
For details about the API request parameters, see Creating an AS Group.
- Example request
POST: https://{Endpoint}/autoscaling-api/v1/0605767c2e80d5762fd0c0146a10aaf2/scaling_group
Obtain {endpoint} from Regions and Endpoints.
Body:
{ "scaling_group_name": "GroupNameTest", "scaling_configuration_id": "47683a91-93ee-462a-a7d7-484c006f4440", "desire_instance_number": 0, "min_instance_number": 0, "max_instance_number": 10, "health_periodic_audit_method": "NOVA_AUDIT", "vpc_id": "a8327883-6b07-4497-9c61-68d03ee193a", "available_zones": ["XXXa","XXXb"], "networks": [ { "id": "3cd35bca-5a10-416f-8994-f79169559870" } ], "enterprise_project_id": "c92b1a5d-6f20-43f2-b1b7-7ce35e58e413", "multi_az_priority_policy": "PICK_FIRST" }
- Example response
{ "scaling_group_id": "a8327883-6b07-4497-9c61-68d03ee193a1" }
- API
- Verify the AS group creation.
- API
URI format: GET /autoscaling-api/v1/{project_id}/scaling_group/{scaling_group_id}
For details about the API request parameters, see Querying an AS Group.
- Example request
GET: https://{Endpoint}/autoscaling-api/v1/0605767c2e80d5762fd0c0146a10aaf2/scaling_group/a8327883-6b07-4497-9c61-68d03ee193a1
where
a8327883-6b07-4497-9c61-68d03ee193a1 is the UUID of the created AS configuration.
Obtain {endpoint} from Regions and Endpoints.
- Example response
{ "scaling_group": { "networks": [ { "id": "a8327883-6b07-4497-9c61-68d03ee193a ", "ipv6_enable": true, "ipv6_bandwidth": { "id": "076ee2ff-f23e-4338-b8ac-1bc7278532d5" } } ], "available_zones": [ "XXXa", "XXXb" ], "detail": null, "scaling_group_name": "api_gateway_modify", "scaling_group_id": "d4e50321-3777-4135-97f8-9f5e9714a4b0", "scaling_group_status": "INSERVICE", "scaling_configuration_id": "53579851-3841-418d-a97b-9cecdb663a90", "scaling_configuration_name": "press", "current_instance_number": 7, "desire_instance_number": 8, "min_instance_number": 0, "max_instance_number": 100, "cool_down_time": 900, "lb_listener_id": null, "security_groups": [ { "id": "23b7b999-0a30-4b48-ae8f-ee201a88a6ab" } ], "create_time": "2015-09-01T08:36:10Z", "vpc_id": "3e22f934-800d-4bb4-a588-0b9a76108190", "health_periodic_audit_method": "NOVA_AUDIT", "health_periodic_audit_time": 5, "health_periodic_audit_grace_period": 600, "instance_terminate_policy": "OLD_CONFIG_OLD_INSTANCE", "is_scaling": true, "delete_publicip": false, "notifications": null, "enterprise_project_id": "c92b1a5d-6f20-43f2-b1b7-7ce35e58e413", "activity_type": "MODIFY_ELB", "multi_az_priority_policy": "PICK_FIRST" } }
- API
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot