Updated on 2024-04-15 GMT+08:00

Creating an ECS (Pay-per-Use)

Function

This API is used to create one or more ECSs billed in pay-per-use mode.

This API is an asynchronous API. After the creation request is successfully delivered, a job ID is returned. This does not mean the creation is complete. You need to call the API by referring to Querying Task Execution Status to query the job status. The SUCCESS status indicates that the creation is successful.

This API allows you to set the X-Client-Token request header in the HTTP request header to ensure the request idempotence. For details, see Idempotent Requests.

Huawei Cloud no longer provides Windows images. This API cannot be used to create ECSs using Windows images, including public Windows images, private Windows images, shared Windows images, and Marketplace Windows images.

Learn how to authorize and authenticate this API before using it.

Before calling this API, you need to obtain Regions and Endpoints.

Logging in to an ECS can be authenticated using either a key pair or password. For security purposes, you are advised to use key pair authentication.

  • Key pair

    A key pair is used for ECS login authentication.

    Method of calling APIs: Use the key_name field to specify the key file used for logging in to the ECS.

  • Password

    If you choose the initial password for authentication in an ECS, you can log in to the ECS using the username and its initial password. The initial password of user root is used for authentication in Linux, while that of user Administrator is used for authentication in Windows.

    Method of calling APIs: Use the adminPass field to specify the initial login password of the administrator account. For details about how to use the adminPass field, see Table 3. If an encrypted password is required for logging in to a Linux ECS that is created using an image with Cloud-Init installed, you can use the user_data field to inject the password. For details, see Table 3.

    If the user_data field is specified for a Linux ECS that is created using an image with Cloud-Init installed, the adminPass field becomes invalid.

  • Image password

    If you use a Linux private image to create an ECS, you can use the image password for login authentication.

    Method of calling APIs: If the image password is used, the key_name and adminPass fields do not need to be specified.

Constraints

When you create a pay-per-use ECS, the system automatically uses available cash coupons.

URI

POST /v1/{project_id}/cloudservers

Table 1 describes the parameters in the URI.
Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Specifies the project ID.

For details about how to obtain the ID, see Obtaining a Project ID.

Request

Request parameters

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Mandatory

Type

Description

server

Yes

Object

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

dry_run

No

Boolean

Specifies whether to check the request and create the ECS. The default value is false.

  • true: The request is sent, but the ECS will not be created. Check items include mandatory parameters and request format.
    • If the check fails, the system returns an error.
    • If the check is successful, the system returns status code 202.
  • false: The request is sent and the ECS will be created after the check is passed.
Table 3 Parameters for creating an ECS

Parameter

Mandatory

Type

Description

imageRef

Yes

String

Specifies the ID of the system image used for creating ECSs. The ID is in Universally Unique Identifier (UUID) format.

flavorRef

Yes

String

Specifies the flavor ID of the ECS to be created.

For details about the flavors that have been released, see "ECS Specifications and Types" in Elastic Cloud Server User Guide.

name

Yes

String

Specifies the ECS name.

For details, see How Can I Set Sequential ECS Names When Creating Multiple ECSs?

Value requirements:

  • The parameter value consists of 1 to 128 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).
  • If more than one ECS is to be created (the count value is greater than 1), the system automatically adds a hyphen followed by a four-digit incremental number, such as -0000, to the end of each ECS name. If you specify a number, the name of the first new ECS will start from the specified number. In this case, the ECS name contains a maximum of 59 characters.
    NOTE:

    ECS hostnames comply with RFC952 and RFC1123 naming rules. It is recommended that you configure hostnames using digits, lower-case letters, and hyphens (-). Underscores (_) are converted into hyphens (-) by default.

user_data

No

String

Specifies the user data to be injected to the ECS during the creation. Text and text files can be injected.

NOTE:
  • The content of user_data must be encoded with base64.
  • The maximum size of the content to be injected (before encoding) is 32 KB.

For more information about the user data to be injected, see Injecting User Data into ECSs in Elastic Cloud Server User Guide.

Examples

Before base64 encoding:

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

After base64 encoding:

  • Linux
    IyEvYmluL2Jhc2gKZWNobyB1c2VyX3Rlc3QgPiAvaG9tZS91c2VyLnR4dA==
  • Windows
    cmVtIGNtZAplY2hvIDExMSA+IGM6XGFhYS50eHQ=

adminPass

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.
  • The password must contain 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 reverse.
  • The Windows ECS password cannot contain the username, the username in reverse, or more than two consecutive characters in the username.

key_name

No

String

Specifies the name of the SSH key used for logging in to the ECS.

Keys can be created using the key creation API (Creating and Importing an SSH Key Pair) or obtained using the SSH key query API (Querying SSH Key Pairs).

vpcid

Yes

String

Specifies the ID of the VPC to which the ECS belongs. The value is in the format of the UUID.

You can obtain the VPC ID from the management console or by following the instructions provided in "Querying VPCs" in Virtual Private Cloud API Reference.

nics

Yes

Array of objects

Specifies the NIC information of the ECS. For details, see Table 4.

Constraints:

  • The network of the primary NIC must belong to the VPC specified by vpcid. When you create NICs, the first NIC specified is the primary NIC.
  • The value must be the ID of the subnet created in the VPC specified by vpcid and in the format of the UUID.
  • A maximum of 12 NICs can be attached to an ECS.
  • The maximum number of NICs varies depending on ECS specifications. For details, see ECS Specifications.

publicip

No

Object

Specifies the EIP bound to the ECS, which can be configured in one of the following ways:

  • Do not use: In such a case, this parameter is unavailable.
  • Automatically assign: You need to specify the information about the EIP to be created.
  • Use existing: You need to specify an existing EIP for your ECS.

For details, see Table 1.

count

No

Integer

Specifies the number of ECSs to be created.

Constraints:

  • If this parameter is not specified, the default value is 1.
  • If the quota is sufficient, the maximum value is 500.

isAutoRename

No

Boolean

Specifies whether the same name is allowed during batch creation. The default value is False. This parameter takes effect when the count value is greater than 1.

  • True: indicates that the same name is allowed.
  • False: indicates that suffixes are automatically added to each name.

root_volume

Yes

Object

Specifies ECS system disk configurations.

For details, see Table 6.

data_volumes

No

Array of objects

Specifies ECS data disk configurations. Each data structure represents a data disk to be created.

An ECS can be attached with a maximum of 59 data disks (certain flavors support only 23 data disks).

For details, see Table 7.

security_groups

No

Array of objects

Specifies the security groups of the ECS.

If this parameter is left blank, the default security group is bound to the ECS by default.

For details, see Table 2.

availability_zone

No

String

Specifies the name of the AZ where the ECS is located.

NOTE:

If this parameter is not specified, the system automatically selects an AZ.

You can obtain the value of this parameter by referring to Querying AZs or Regions and Endpoints.

batch_create_in_multi_az

No

Boolean

Specifies whether ECSs can be deployed in multiple random AZs. The default value is false.

  • true: The batch created ECSs are deployed in multiple AZs.
  • false: The batch created ECSs are deployed in a single AZ.

This parameter is valid when availability_zone is left blank.

extendparam

No

Object

Provides the supplementary information about the ECS to be created.

For details, see Table 8.

metadata

No

Map<String,String>

Specifies the metadata of the ECS to be created.

You can use metadata to customize key-value pairs.

NOTE:
  • If the metadata contains sensitive data, take appropriate measures to protect the sensitive data, for example, controlling access permissions and encrypting the data.
  • A maximum of 10 key-value pairs can be injected.
  • A metadata key consists of 1 to 255 characters and contains only uppercase letters, lowercase letters, spaces, digits, hyphens (-), underscores (_), colons (:), and decimal points (.).
  • A metadata value consists of a maximum of 255 characters.

For details about reserved key-value pairs, see Table 11.

os:scheduler_hints

No

Object

Schedules ECSs, for example, by configuring an ECS group.

For details, see Table 12.

tags

No

Array of strings

Specifies ECS tags.

A tag is in the format of "key.value", where the maximum lengths of key and value are 36 and 43 characters, respectively.

When adding a tag to an ECS, ensure that the tag complies with the following requirements:

NOTE:
  • When you create ECSs, one ECS supports up to 10 tags.
  • The server_tags field provides the same functions as those of tags, but supports more keys and values, so the server_tags field is recommended.

server_tags

No

Array of objects

Specifies ECS tags. For details, see Table 14.

NOTE:
  • When you create ECSs, one ECS supports up to 10 tags.
  • The server_tags field provides the same functions as those of tags, but supports more keys and values, so the server_tags field is recommended.

description

No

String

Specifies the description of the ECS, which is empty by default.

  • Can contain a maximum of 85 characters.
  • Cannot contain an angle bracket < or >.

auto_terminate_time

No

String

Specifies the scheduled deletion time.

The value is in the format of "yyyy-MM-ddTHH:mm:ssZ" in UTC+0 and complies with ISO8601.

If the value of second (ss) is not 00, the system automatically sets to the current value of minute (mm).

The scheduled deletion time must be at least half an hour later than the current time.

The scheduled deletion time cannot be three years later than the current time.

For example, set the value to 2020-09-25T12:05:00Z.

NOTE:

Scheduled deletion is available only for pay-per-use ECSs.

cpu_options

No

Object

Specifies the CPU options.

For details, see Table 8.

Table 4 nics field description

Parameter

Mandatory

Type

Description

subnet_id

Yes

String

Specifies the subnet of the ECS.

The value must be the ID of the subnet created in the VPC specified by vpcid and in the format of the UUID.

You can obtain the parameter value by calling a VPC API for Querying Subnets.

ip_address

No

String

Specifies the IP address of the NIC used by the ECS. The value is an IPv4 address.

Constraints:
  • If this parameter is left blank or set to "", an unused IP address in the subnet is automatically assigned as the IP address of the NIC.
  • If this parameter is specified, its value must be an unused IP address in the network segment of the subnet.

ipv6_enable

No

Boolean

Specifies whether to support IPv6 addresses. If this parameter is set to true, the NIC supports IPv6 addresses.

ipv6_bandwidth

No

Object

Specifies the bound shared bandwidth. For details, see ipv6_bandwidth Field Description.

allowed_address_pairs

No

Array of allow_address_pairs objects

Specifies the allowed IP or MAC address pairs. For details, see Table 5 (extended attribute).

The IP address cannot be 0.0.0.0/0.

  • Configure an independent security group for the port if a large CIDR block (subnet mask less than 24) is configured for parameter allowed_address_pairs.
  • If the value of allowed_address_pairs is 1.1.1.1/0, the source/destination check is disabled.
  • If a virtual IP address is bound to an ECS:
    • leave the value of mac_address blank or set the MAC address of the NIC bound to the ECS.
    • set allowed_address_pairs of the ECS to 1.1.1.1/0.
Table 5 allow_address_pairs field description

Parameter

Mandatory

Type

Description

ip_address

No

String

Specifies the IP address.

The IP address cannot be 0.0.0.0/0.

Configure an independent security group for the port if a large CIDR block (subnet mask less than 24) is configured for parameter allowed_address_pairs.

mac_address

No

String

Specifies the MAC address.

Table 6 root_volume field description

Parameter

Mandatory

Type

Description

volumetype

Yes

String

Specifies the ECS system disk type, which must be one of available disk types.

The value can be SATA, SAS, GPSSD, SSD, or 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

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

NOTE:

size

No

Integer

Specifies the system disk size in GB. The value ranges from 1 to 1024.

Constraints:

  • The system disk size must be greater than or equal to the minimum system disk size supported by the image (min_disk attribute of the image).
  • If this parameter is not specified or is set to 0, the default system disk size is the minimum value of the system disk in the image (min_disk attribute of the image).
NOTE:

To obtain the minimum system disk size (min_disk) of an image, click the image on the management console for its details. Alternatively, call the native OpenStack API for querying details about an image. For details, see "Querying Image Details (Native OpenStack)" in Image Management Service API Reference.

extendparam

No

Object

Provides the disk information.

For details, see extendparam Field Description for Creating Disks.

cluster_type

No

String

Specifies the storage type of an ECS system disk.

Value: DSS (dedicated storage type)

This parameter must be used together with cluster_id and cluster_id must be specified.

cluster_id

No

String

Specifies the ID of the storage pool used by an ECS system disk.

hw:passthrough

No

Boolean

Specifies the device type of the EVS disks to be created.
  • If this parameter is set to false, VBD disks are created.
  • If this parameter is set to true, SCSI disks are created.
  • If this parameter is not specified or set to a non-Boolean character, VBD disks are created by default.

metadata

No

Object

Specifies the EVS disk metadata. Ensure that key and value in the metadata contain at most 255 bytes.

This field is used only when an encrypted disk is created.

For details, see metadata Field Description for Creating Disks.

iops

No

Integer

Specifies the IOPS configured for an EVS disk. This parameter is mandatory only when volumetype 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 volumetype is set to GPSSD2 and cannot be configured when volumetype 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 7 data_volumes field description

Parameter

Mandatory

Type

Description

volumetype

Yes

String

Specifies the type of the ECS data disk, which must be one of available disk types.

The value can be SATA, SAS, GPSSD, SSD, or 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

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

NOTE:

size

Yes

Integer

Specifies the data disk size, in GB. The value ranges from 10 to 32768.

When you use a data disk image to create a data disk, ensure that the value of this parameter is greater than or equal to the size of the source data disk that is used to create the data disk image.

shareable

No

Boolean

Specifies whether the disk is shared. The value can be true (specifies a shared disk) or false (a common EVS disk).

NOTE:

This field has been discarded. Use multiattach.

multiattach

No

Boolean

Specifies the shared disk information.

  • true: indicates that the created disk is a shared disk.
  • false: indicates that the created disk is a common EVS disk.
NOTE:

The shareable field is not used anymore. If both shareable and multiattach must be used, ensure that the values of the two fields are the same. If this parameter is not specified, common EVS disks are created by default.

hw:passthrough

No

Boolean

Specifies the device type of the EVS disks to be created.
  • If this parameter is set to false, VBD disks are created.
  • If this parameter is set to true, SCSI disks are created.
  • If this parameter is not specified or set to a non-Boolean character, VBD disks are created by default.

extendparam

No

Object

Provides the disk information.

For details, see Table 7.

cluster_type

No

String

Specifies the storage type of an ECS data disk.

Value: DSS (dedicated storage type)

This parameter must be used together with cluster_id and cluster_id must be specified.

cluster_id

No

String

Specifies the ID of the storage pool used by an ECS data disk.

data_image_id

No

String

Specifies ID of the data image. The value is in UUID format.

If data disks are created using a data disk image, this parameter is mandatory and it does not support metadata.

metadata

No

Object

Specifies the EVS disk metadata. Ensure that key and value in the metadata contain at most 255 bytes.

This field is used only when an encrypted disk is created.

If data disks are created using a data disk image, this field cannot be used.

For details, see metadata Field Description for Creating Disks.

delete_on_termination

No

Boolean

Specifies the policy of releasing data disks when the ECS is deleted.

  • true: The data disk is released when the ECS is deleted.
  • false: The data disk is not released when the ECS is deleted.

The default value is false.

NOTE:

This parameter is supported only by pay-per-use and spot ECSs.

iops

No

Integer

Specifies the IOPS configured for an EVS disk. This parameter is mandatory only when volumetype 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 volumetype is set to GPSSD2 and cannot be configured when volumetype 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 8 cpu_options field description

Parameter

Mandatory

Type

Description

hw:cpu_threads

No

integer

Specifies the number of CPU hyperthreads, which determines whether to enable CPU hyper-threading.

Values: 1 and 2

  • 1: Disable hyper-threading.
  • 2: Enable hyper-threading.

This parameter can be set to 1 (disabling hyper-threading) only when all of the following conditions are met:

  • The ECS is being created or resized.
  • The extra_specs parameter of the target flavor contains:
    • hw:cpu_policy, whose value is set to dedicated
    • hw:cpu_threads, whose value is set to 2

Response

Parameter

Type

Description

job_id

String

Specifies the returned task ID after delivering the task. You can query the task progress using this ID. For details about how to query the task execution status based on job_id, see Task Status Management.

For details about abnormal responses, see Responses (Task).

Example Request

  • Create a pay-per-use ECS running CentOS 7.6 64bit, with 4 vCPUs, 8 GiB of memory, SSD disks attached, and 10 Mbit/s of bandwidth-billed EIP bound. Use the key pair for login authentication.
    POST https://{endpoint}/v1/{project_id}/cloudservers
    
    {
        "server": {
            "availability_zone":"az1-dc1",
            "name": "newserver", 
            "imageRef": "67f433d8-ed0e-4321-a8a2-a71838539e09", 
            "root_volume": {
                "volumetype": "SSD"
            }, 
            "data_volumes": [ 
                {
                    "volumetype": "SSD", 
                    "size": 100,
                    "multiattach": true,
                    "hw:passthrough": true
                }
            ], 
            "flavorRef": "s3.xlarge.2", 
            "vpcid": "0dae26c9-9a70-4392-93f3-87d53115d171", 
            "security_groups": [
                {
                    "id": "507ca48f-814c-4293-8706-300564d54620"
                }
            ], 
            "nics": [
                {
                    "subnet_id": "157ee789-03ea-45b1-a698-76c92660dd83"
                }
            ], 
            "publicip": {
                "eip": {
                    "iptype": "5_bgp",
                    "bandwidth": {
                        "size": 10, 
                        "sharetype": "PER"
                    }
                }
            }, 
            "key_name": "sshkey-123", 
            "count": 1, 
            "server_tags": [
                {
                    "key": "key1",
                    "value": "value1"
                }
            ],
            "metadata": {
                   "op_svc_userid": "8ea65f4099ba412883e2a0da72b96873",
                   "agency_name": "test"
            }
        }
    }
  • Send a pre-verification request to check whether mandatory parameters are configured in the request and whether the request format is correct.
    POST https://{endpoint}/v1/{project_id}/cloudservers
    
    {
        "dry_run": true,
        "server": {
            "availability_zone":"az1-dc1",
            "name": "newserver", 
            "imageRef": "1189efbf-d48b-46ad-a823-94b942e2a000", 
            "root_volume": {
                "volumetype": "SSD"
            }, 
            "data_volumes": [
                {                 
                     "volumetype": "SSD",                  
                     "size": 100,                 
                     "multiattach": true,                 
                     "hw:passthrough": true             
                }
            ], 
            "flavorRef": "s3.xlarge.2", 
            "vpcid": "0dae26c9-9a70-4392-93f3-87d53115d171", 
            "security_groups": [
                {
                    "id": "507ca48f-814c-4293-8706-300564d54620"
                }
            ], 
            "nics": [
                {
                    "subnet_id": "157ee789-03ea-45b1-a698-76c92660dd83"
                }
            ], 
            "key_name": "sshkey-123", 
            "count": 1
        }
    }

Example Response

{
    "job_id": "93c82933d6b7827d3016b8771f2070873"
}

Or

{
    "error": {
        "code": "request body is illegal.", 
        "message": "Ecs.0005"
    }
}

Or

{
    "error": {
        "message": "privateIp [%s] is not in this subnet [%s]",
        "code": "Ecs.0005",
        "details": [
            {
                "code": "Ecs.0039"
            }
        ]
    }
}

Error Codes

See Error Codes.