Help Center/ Auto Scaling/ API Reference/ APIs/ AS Configurations/ Creating an AS Configuration
Updated on 2024-07-22 GMT+08:00

Creating an AS Configuration

Function

This API is used to create an AS configuration.

  • An AS configuration is a template specifying specifications for the instances to be added to an AS group.
  • The AS configuration is decoupled from the AS group. An AS configuration can be used by multiple AS groups.
  • Up to 100 AS configurations can be created for each user.

URI

POST /autoscaling-api/v1/{project_id}/scaling_configuration

Table 1 Parameter description

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

Request

Table 2 Request parameters

Parameter

Mandatory

Type

Description

scaling_configuration_name

No

String

Specifies the AS configuration name. The name contains only letters, digits, underscores (_), and hyphens (-), and cannot exceed 64 characters.

instance_config

No

Object

Specifies the ECS configuration. For details, see Table 3.

source_scaling_configuration_id

No

String

Specifies the ID of the source AS configuration, which will be used together with instance_config to create a new AS configuration.

NOTE:
  • If instance_id is specified in instance_config, instance_id is preferentially used to create the new AS configuration, and source_scaling_configuration_id does not take effect.
  • If instance_id is not specified in instance_config, source_scaling_configuration_id and instance_config are used together to create the new AS configuration.
    • If a parameter in instance_config is set to null, the corresponding setting of the source AS configuration takes effect.
    • If a parameter in instance_config is not set to null or left empty, this parameter overwrites the corresponding setting of the source AS configuration.
  • If source_scaling_configuration_id is not specified, scaling_configuration_name and instance_config are mandatory.
Table 3 instance_config field description

Parameter

Mandatory

Type

Description

instance_id

No

String

Specifies the ECS ID. When you want to create an AS configuration from an ECS, specify this parameter. In this case, the flavorRef, imageRef, disk, tenancy, dedicated_host_id, and security_groups fields do not take effect.

If the instance_id field is not specified, flavorRef, imageRef, and disk fields are mandatory.

flavorRef

No

String

Specifies the ECS flavor ID. A maximum of 10 flavors can be selected. Use a comma (,) to separate multiple flavor IDs. You can obtain an ECS flavor ID from the API for querying details about flavors and extended flavor information. For details, see Querying Details About Flavors and Extended Flavor Information.

imageRef

No

String

Specifies the image ID. Its value is the same as that of image_id for specifying the image selected during ECS creation. You can obtain an image ID by calling the IMS API for querying images. For details, see Querying Images.

disk

No

Array of disk objects

Specifies the disk group information. System disks are mandatory and data disks are optional. For details, see Table 4.

key_name

No

String

Specifies the name of the SSH key pair used to log in to the ECS.

For details about how to obtain a key pair, see Creating and Importing an SSH Key Pair.

NOTE:

If both key_name and user_data are specified, user_data only injects user data.

personality

No

Array of personality objects

Specifies information about the injected file. Only text files can be injected. A maximum of five files can be injected at a time and the maximum size of each file is 1 KB. For details, see Table 6.

public_ip

No

public_ip object

Specifies the EIP of the ECS. The EIP can be configured in two ways. For details, see Table 7.

  • Do not use an EIP. In this case, this parameter is unavailable.
  • Automatically assign an EIP. You need to specify the information about the new EIP.
    NOTE:

    If you enable fine-grained policy and associate the AS configuration with an EIP specified to an AS group, the fine-grained policy granted to you must contain the authorization item that allows the vpc:publicIps:create action.

user_data

No

String

Specifies the user data to be injected during the ECS creation process. Text, text files, and gzip files can be injected. For more information, see Passing User Data to ECSs.

Constraints:

  • The content to be injected must be encoded with base64. The maximum size of the content to be injected (before encoding) is 32 KB.
  • If key_name is not specified, the data injected by user_data is the password of user root for logging in to the ECS by default.
  • This parameter is mandatory when you create a Linux ECS using the password authentication mode. Its value is the initial user root password.

Password complexity requirements:

  • Consists of 8 to 26 characters.
  • Contains at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters !@$%^-_=+[{}]:,./?

Examples:

  • Use a plaintext password (risky in security), for example, Cloud.1234.
    #! /bin/bash
    echo 'root:Cloud.1234' | chpasswd ;
  • Use a ciphertext password (recommended)
    #! /bin/bash
    echo 'root:$6$V6azyeLwcD3CHlpY$BN3VVq18fmCkj66B4zdHLWevqcxlig' | chpasswd -e

In the preceding command output, $6$V6azyeLwcD3CHlpY$BN3VVq18fmCkj66B4zdHLWevqcxlig is the ciphertext password, which can be generated as follows:

1. Generate an encrypted salt value.

[root@test linux]# python -c "import crypt, getpass, pwd;print crypt.mksalt()"  $6$V6azyeLwcD3CHlpY

2. Generate a ciphertext password based on the salt value.

[root@test linux]# python -c "import crypt, getpass, pwd;print crypt.crypt('Cloud.1234','\$6\$V6azyeLwcD3CHlpY')"   $6$V6azyeLwcD3CHlpY$BN3VVq18fmCkj66B4zdHLWevqcxlig

Examples:

  • Linux
    #! /bin/bash
    echo user_test >> /home/user.txt
  • Windows
    rem cmd
    echo 111 > c:\aaa.txt
NOTE:

Data injection is not supported for ECSs that use a Linux image and the password login mode.

metadata

No

metadata object

Specifies the ECS metadata. For details, see Table 10.

NOTE:
  • This parameter is mandatory when a Windows ECS with password authentication is created.
  • This field does not allow users to write data. It is mandatory when the ECS is to be created using a Windows image.

security_groups

No

Array of security_groups objects

Specifies security groups. For details, see Table 11. For how to obtain information about security groups using VPC IDs, see Querying Security Groups in Virtual Private Cloud API Reference.

If a security group is specified both in the AS configuration and AS group, scaled ECS instances will be added to the security group specified in the AS configuration. If a security group is not specified in either of them, scaled ECS instances will be added to the default security group. For your convenience, you are advised to specify the security group in the AS configuration.

server_group_id

No

String

Specifies the ECS group ID. For how to obtain an ECS group ID, see Querying ECS Groups.

tenancy

No

String

Specifies that ECSs are created on DeHs. Options:

  • dedicated: Specifies that ECSs are created on DeHs.
  • This parameter is not specified.

dedicated_host_id

No

String

Specifies the ID of a DeH.

NOTE:
  • This parameter is valid only when tenancy is set to dedicated.
  • If this parameter is specified, ECSs will be created on a specified DeH.
  • If this parameter is not specified, the system automatically selects the DeH with the maximum available memory size from the DeHs that meet specifications requirements to create the ECSs, thereby balancing load of the DeHs.

multi_flavor_priority_policy

No

String

Specifies the priority policy used when there are multiple flavors and instances to be created using an AS configuration.

  • PICK_FIRST (default): When an ECS is added for capacity expansion, the target flavor is determined in the order in the flavorRef list.
  • COST_FIRST: When an ECS is added for capacity expansion, the target flavor is determined for minimal expenses.

market_type

No

String

Specifies a billing mode for an ECS. The options are as follows:

  • Pay-per-use, which is not specified
  • Spot pricing

For a Linux ECS, its password can be injected only using userdata. For a Windows ECS, its password can be injected only using metadata admin_pass.

Table 4 disk field description

Parameter

Mandatory

Type

Description

size

Yes

Integer

Specifies the disk size. The unit is GB.

The system disk size ranges from 1 to 1024 and must be greater than or equal to the minimum size (min_disk value) of the system disk specified in the image.

The data disk size ranges from 10 to 32768.

volume_type

Yes

String

Specifies the ECS system disk type. The disk type must match the available disk type.

The value can be SATA, SAS, GPSSD, SSD, GPSSD2, ESSD2, and ESSD.
  • SSD: the ultra-high I/O type
  • SAS: the high I/O type
  • SATA: the common I/O type
  • GPSSD: the general purpose SSD type
  • ESSD: the extreme SSD type
  • GPSSD2: the general purpose SSD V2 type
  • ESSD2: the extreme SSD V2 type

If the specified disk type is not available in the AZ, the disk will fail to create.

NOTE:

Different ECS flavors support different disk types. The supported disk types will be displayed on the management console.

NOTE:

disk_type

Yes

String

Specifies a disk type. The options are as follows:

  • DATA: indicates a data disk.
  • SYS: indicates a system disk.
    NOTE:

    System disk encryption is not supported.

dedicated_storage_id

No

String

Specifies a DSS device ID for creating an ECS disk.

NOTE:

Specify DSS devices for all disks in an AS configuration or not. If DSS devices are specified, all the data stores must belong to the same AZ, and the disk types supported by a DSS device for a disk must be the same as the volume_type value.

data_disk_image_id

No

String

Specifies the ID of a data disk image used to export data disks of an ECS.

snapshot_id

No

String

Specifies the disk backup snapshot ID for restoring the system disk and data disks using a full-ECS backup when a full-ECS image is used.

NOTE:

You can obtain the disk backup snapshot ID using the full-ECS backup ID in Querying a Single Backup. Each disk in an AS configuration must correspond to a disk backup in the full-ECS backup by snapshot_id.

metadata

No

metadata object

Specifies the metadata for creating disks. For details, see Table 5.

iops

No

Integer

Specifies the IOPS configured for an EVS disk. This parameter is mandatory only when volume_type is set to GPSSD2 or ESSD2.

NOTE:
  • For details about IOPS of GPSSD2 and ESSD2 EVS disks, see Disk Types and Performance.
  • Only pay-per-use billing is supported currently.

throughput

No

Integer

Specifies the throughput of an EVS disk. The unit is MiB/s. This parameter is mandatory when volume_type is set to GPSSD2 and cannot be configured when volume_type is set to other values.

NOTE:
  • For details about the throughput range of GPSSD2 EVS disks, see Disk Types and Performance.
  • Only pay-per-use billing is supported currently.
Table 5 metadata Field Description for Creating Disks

Parameter

Mandatory

Type

Description

__system__encrypted

No

String

Specifies encryption in metadata. The value can be 0 (encryption disabled) or 1 (encryption enabled).

If this parameter does not exist, the disk will not be encrypted by default.

NOTE:

System disk encryption is not supported.

__system__cmkid

No

String

Specifies the CMK ID, which indicates encryption in metadata. This parameter is used with __system__encrypted.

NOTE:
Table 6 personality field description

Parameter

Mandatory

Type

Description

path

Yes

String

Specifies the path of the injected file.

  • For Linux OSs, specify the path, for example, /etc/foo.txt, for storing the injected file.
  • For Windows, the injected file is automatically stored in the root directory of drive C. You only need to specify the file name, for example, foo. The file name contains only letters and digits.

content

Yes

String

Specifies the content of the injected file.

The value must be the information after the content of the injected file is encoded using Base64.

Table 7 public_ip field description

Parameter

Mandatory

Type

Description

eip

Yes

eip object

Specifies the EIP automatically assigned to the ECS. For details, see Table 8.

Table 8 eip field description

Parameter

Mandatory

Type

Description

ip_type

Yes

String

Specifies the EIP type.

Enumerated values of the IP address type:

  • 5_bgp: indicates the dynamic BGP.
  • 5_sbgp: indicates the static BGP.

For details, see the Public IP field in Assigning an EIP in Virtual Private Cloud API Reference.

bandwidth

Yes

bandwidth object

Specifies the bandwidth of an IP address. For details, see Table 9.

Table 9 bandwidth field description

Parameter

Mandatory

Type

Description

size

No

Integer

Specifies the bandwidth (Mbit/s). The value range for bandwidth billed by duration is 1 to 2000 and that for bandwidth billed by traffic is 1 to 300.

NOTE:
  • If share_type is set to PER, this parameter is mandatory. If share_type is set to WHOLE, this parameter is invalid.
  • The specific range may vary depending on the configuration in each region. You can see the bandwidth range of each region on the management console.
  • The minimum unit for bandwidth varies depending on the bandwidth range.
    • The minimum unit is 1 Mbit/s if the allowed bandwidth size ranges from 0 to 300 Mbit/s (with 300 Mbit/s included).
    • The minimum unit is 50 Mbit/s if the allowed bandwidth size ranges 300 Mbit/s to 1000 Mbit/s (with 1000 Mbit/s included).
    • The minimum unit is 500 Mbit/s if the allowed bandwidth size is greater than 1000 Mbit/s.

share_type

Yes

String

Specifies the bandwidth sharing type.

Enumerated values of the sharing type:

  • PER: dedicated
  • WHOLE: shared

charging_mode

No

String

Specifies the bandwidth billing mode.

The options are as follows:

  • bandwidth: billed by bandwidth.
  • traffic: billed by traffic.
If the parameter value is out of the preceding options, creating the ECS will fail.
NOTE:
  • If share_type is set to PER, this parameter is mandatory.
  • If share_type is set to WHOLE, this parameter is invalid.

id

No

String

Specifies the bandwidth ID. When using a shared bandwidth, you can select an existing shared bandwidth to create an EIP. For details, see Querying Bandwidths.

NOTE:
  • If share_type is set to PER, this parameter is invalid.
  • If share_type is set to WHOLE, this parameter is mandatory.
Table 10 metadata field description

Parameter

Mandatory

Type

Description

admin_pass

No

String

Specifies the initial login password of the administrator account for logging in to an ECS using password authentication. The Linux administrator is root, and the Windows administrator is Administrator.

Password complexity requirements:
  • Consists of 8 to 26 characters.
  • Contains at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters !@$%^-_=+[{}]:,./?
  • The password cannot contain the username or the username in reversed order.
  • The Windows ECS password cannot contain the username, the username in reversed order, or more than two consecutive characters in the username.
Table 11 security_groups field description

Parameter

Mandatory

Type

Description

id

Yes

String

Specifies the ID of the security group.

Example Request

This example creates an AS configuration with name as-config-tlzp, image ID 627a1223-2ca3-46a7-8d5f-7aef22c74ee6, flavor ID s3.xlarge.4, 40 GB SATA system disk, and SSH key name 100vm_key.
POST https://{Endpoint}/autoscaling-api/v1/{project_id}/scaling_configuration

{ 
    "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" ,
	"security_groups": [{
		"id": "6c22a6c0-b5d2-4a84-ac56-51090dcc33be"
	}], 
        "multi_flavor_priority_policy": "PICK_FIRST"
    } 
}

Response

Table 12 Response parameters

Parameter

Type

Description

scaling_configuration_id

String

Specifies the AS configuration ID.

Example Response

{
    "scaling_configuration_id": "f8327883-6a07-4497-9a61-68c03e8e72a2"
}

Returned Values

  • Normal

    200

  • Abnormal

    Returned Value

    Description

    400 Bad Request

    The server failed to process the request.

    401 Unauthorized

    You must enter the username and password to access the requested page.

    403 Forbidden

    You are forbidden to access the requested page.

    404 Not Found

    The server could not find the requested page.

    405 Method Not Allowed

    You are not allowed to use the method specified in the request.

    406 Not Acceptable

    The response generated by the server could not be accepted by the client.

    407 Proxy Authentication Required

    You must use the proxy server for authentication to process the request.

    408 Request Timeout

    The request timed out.

    409 Conflict

    The request could not be processed due to a conflict.

    500 Internal Server Error

    Failed to complete the request because of an internal service error.

    501 Not Implemented

    Failed to complete the request because the server does not support the requested function.

    502 Bad Gateway

    Failed to complete the request because the request is invalid.

    503 Service Unavailable

    Failed to complete the request because the system is unavailable.

    504 Gateway Timeout

    A gateway timeout error occurred.

Error Codes

See Error Codes.