Help Center/ Auto Scaling/ API Reference/ Application Examples/ Example 1: Creating an AS Configuration
Updated on 2022-10-08 GMT+08:00

Example 1: Creating an AS Configuration

Scenarios

This section describes how to create an AS configuration by calling APIs. For details, see Calling APIs.

An AS configuration defines the specifications of the ECSs to be added to an AS group. The specifications include the ECS flavor, image, and disk size. You can use specifications of an existing ECS or create an AS configuration.

Constraints

  • The AS configuration is decoupled from the AS group. An AS configuration can be used by multiple AS groups.
  • Up to 100 AS configurations per account can be created by default.

Involved APIs

To create an AS configuration, you need to perform several operations, such as querying a user token, ECS flavors, and images. The following APIs are required:

Procedure

  1. Determine the user token that can be used to authenticate the calling of other APIs.

    1. View the user token. For details, see Obtaining a User Token.
    2. Obtain the value of X-Subject-Token in the response header.

  2. Determine the ECS flavor.

    1. View ECS flavors. For details, see Querying Details About ECS Flavors.
    2. Select a flavor based on site requirements and record the flavor ID.

  3. Determine the image.

    1. View images. For details, see Querying Images.
    2. Select an image based on site requirements and record the image ID.

  4. Set the login mode to Key pair.

    1. View SSH key pairs. For details, see Querying SSH Key Pairs.
    2. Select a key pair as required and record the key pair name.

  5. Create an AS configuration using the flavor and image you specify.

    • API

      URI format: POST /autoscaling-api/v1/{project_id}/scaling_configuration

      For details about API request parameters, see Creating an AS Configuration.

    • Example request

      POST: https://{Endpoint}/autoscaling-api/v1/0605767c2e80d5762fd0c0146a10aaf2/scaling_configuration

      Obtain {endpoint} from Regions and Endpoints.

      Body:

      { 
          "scaling_configuration_name": "as-config-tlzq", 
          "instance_config": { 
              "flavorRef": "s3.xlarge.4", 
              "imageRef": "627a1223-2ca3-46a7-8d5f-7aef22c74ee6", 
              "disk": [ 
                  { 
                      "size": 40, 
                      "volume_type": "SATA", 
                      "disk_type": "SYS" 
                  } 
              ], 
              "key_name": "100vm_key",
              "multi_flavor_priority_policy": "PICK_FIRST"
          } 
      }
    • Example response
      {
          "scaling_configuration_id": "f8327883-6a07-4497-9a61-68c03e8e72a2"
      }

  6. Verify the AS configuration creation.

    • API

      URI format: GET /autoscaling-api/v1/{project_id}/scaling_configuration/{scaling_configuration_id}

      For details, see Querying an AS Configuration.

    • Example request

      GET: https://{Endpoint}/autoscaling-api/v1/0605767c2e80d5762fd0c0146a10aaf2/scaling_configuration/f8327883-6a07-4497-9a61-68c03e8e72a2

      where

      f8327883-6a07-4497-9a61-68c03e8e72a2 is the UUID of the created AS configuration.

      Obtain {endpoint} from Regions and Endpoints.

    • Example response
      {
          "scaling_configuration": {
              "tenant": "0605767c2e80d5762fd0c0146a10aaf2",
              "scaling_configuration_id": "f8327883-6a07-4497-9a61-68c03e8e72a2",
              "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"
                      }
                  ],
                  "adminPass": "***",
                  "personality": null,
                  "instance_name": null,
                  "instance_id": null,
                  "flavorRef": "103",
                  "imageRef": "627a1223-2ca3-46a7-8d5f-7aef22c74ee6",
                  "key_name": "keypair01",
                  "public_ip": null,
                  "user_data": null,
                  "metadata": {},
                  "security_groups": null,
                  "multi_flavor_priority_policy": "PICK_FIRST"
              },
              "create_time": "2015-07-23T01:04:07Z"
          }
      }