Updated on 2025-09-16 GMT+08:00

Creating a Template

Function

This API is used to create a launch template.

The automatically-generated version 1 is the default version.

Constraints

  • The template does not support the yearly/monthly billing mode.
  • The template does not support IPv6 and driver_mode specifications.
  • The template cannot be used to launch ECSs from DeH, DCC, or DSS.
  • This API does not check the existence and validity of the request parameters.

URI

POST /v3/{project_id}/launch-templates

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 project ID, see Obtaining a Project ID.

Request

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Mandatory

Type

Description

launch_template

Yes

Object

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

dry_run

No

Boolean

Specifies whether to check the request and create a template. If this parameter is set to true, no template is created.

  • true: Check the request. Check items include the 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: Do not check the request.
Table 3 launch_template field description

Parameter

Mandatory

Type

Description

template_data

No

Object

Specifies the template creation request information. For details, see Table 4.

name

Yes

String

Specifies the template name.

description

No

String

Specifies the template description.

version_description

No

String

Specifies the version description of the first version.

Table 4 template_data field description

Parameter

Mandatory

Type

Description

flavor_id

No

String

Specifies the flavor ID of the ECS to be created based on the template.

name

No

String

Specifies the ECS name.

description

No

String

Specifies the ECS description.

availability_zone_id

No

String

Specifies the AZ.

enterprise_project_id

No

String

Specifies the enterprise project ID.

auto_recovery

No

Boolean

Enables auto-recovery.

os_profile

No

Object

Specifies the image attribute. For details, see Table 5.

security_group_ids

No

Array of strings

Specifies the security group ID list. This parameter applies to all network interfaces.

network_interfaces

No

Array of Objects

Specifies the network interfaces. For details, see Table 6.

block_device_mappings

No

Array of Objects

Specifies the BDM mounting information. The value is subject to the flavor. For details, see Table 8.

market_options

No

Object

Specifies the billing information. For details, see Table 10.

internet_access

No

Object

Specifies the public network access. For details, see Table 12.

metadata

No

Map<String,String>

Specifies the metadata.

tag_options

No

Array of Objects

Specifies VM tags. Currently, only VMs can be tagged. In the future, associated resources such as volumes can be tagged, too.

For details, see Table 15.

Table 5 os_profile field description

Parameter

Mandatory

Type

Description

key_name

No

String

Specifies the key name.

user_data

No

String

Specifies the custom user data to be injected into the instance during instance creation.

Text and text files can be injected.

iam_agency_name

No

String

Specifies the agency name.

enable_monitoring_service

No

Boolean

Enables HSS.

Table 6 network_interfaces field description

Parameter

Mandatory

Type

Description

virsubnet_id

No

String

Specifies the subnet ID.

attachment

No

Object

Specifies the network interface details. For details, see Table 7.

Table 7 attachment field description of network_interfaces

Parameter

Mandatory

Type

Description

device_index

No

Integer

Specifies the loading sequence. The value 0 indicates the primary network interface.

Table 8 block_device_mappings field description

Parameter

Mandatory

Type

Description

source_id

No

String

Specifies the VM volume data source type.

source_type

No

String

Specifies the source type of the volume device.

encrypted

No

Boolean

Encrypted or not.

cmk_id

No

String

Specifies the key ID.

volume_type

No

String

Specifies the volume type.

volume_size

No

Integer

Specifies the volume size.

attachment

No

Object

Specifies the disk interface. For details, see Table 9.

Table 9 attachment field description

Parameter

Mandatory

Type

Description

boot_index

No

Integer

Specifies the loading sequence. The value 0 indicates the system disk.

Table 10 market_options field description

Parameter

Mandatory

Type

Description

market_type

No

String

Specifies the billing mode.

spot_options

No

Object

Specifies spot instance parameters. For details, see Table 11.

Table 11 spot_options field description

Parameter

Mandatory

Type

Description

spot_price

No

Float

Specifies the highest price per hour you are willing to pay for a spot ECS.

block_duration_minutes

No

Integer

Specifies the predefined duration of the spot ECS.

instance_interruption_behavior

No

String

Specifies the spot ECS interruption policy, which can only be set to immediate currently.

Table 12 internet_access field description

Parameter

Mandatory

Type

Description

publicip

No

Object

Specifies the public network access. For details, see Table 13.

Table 13 publicip field description

Parameter

Mandatory

Type

Description

publicip_type

No

String

Specifies the EIP type.

charging_mode

No

String

Specifies the EIP billing mode.

bandwidth

No

Object

Specifies the bandwidth. For details, see Table 14.

Table 14 bandwidth field description

Parameter

Mandatory

Type

Description

share_type

No

String

Specifies the bandwidth type.

size

No

integer

Specifies the bandwidth size.

charge_mode

No

String

Specifies the billing mode.

id

No

String

Specifies the bandwidth ID. You can use an existing shared bandwidth when applying for an EIP for the bandwidth of type WHOLE.

Table 15 tag_options field description

Parameter

Mandatory

Type

Description

tags

No

Array of Objects

Specifies tags. For details, see Table 16.

Table 16 tags field description

Parameter

Mandatory

Type

Description

key

No

String

Specifies the tag key.

value

No

String

Specifies the tag value.

Response

Table 17 describes the response parameters.

Table 17 Response parameters

Parameter

Type

Description

launch_template_id

String

Specifies the template ID.

Example Request

Create a launch template with the flavor "s3.small.1" and name "ECS_Template".

POST https://{endpoint}/v3/{{projectId}}/launch-templates

{
	"launch_template": {
		"template_data": {
			"flavor_id": "s3.small.1",
			"name": "ECS_Template",
			"description": "aaa",
			"availability_zone_id": "az1",
			"enterprise_project_id": "0",
			"auto_recovery": true,
			"os_profile": {
				"key_name": "string",
				"user_data": "string",
				"iam_agency_name": "",
				"enable_monitoring_service": false
			},
			"security_group_ids": ["76b47fb1-166e-46b9-82e4-1e1c6ecf2af0"],
			"network_interfaces": [{
				"virsubnet_id": "1b223400-8aa1-444f-b3ad-d846fdbeff7e",
				"attachment": {
					"device_index": 0
				}
			}],
			"block_device_mappings": [{
				"source_id": "8e52e33d-1f2f-4d65-bd1f-c42cc420edc1",
				"source_type": "image",
				"encrypted": false,
				"cmk_id": "",
				"volume_type": "SATA",
				"volume_size": 40,
				"attachment": {
					"boot_index": 0				
                                 }
			}],
			"market_options": {
				"market_type": "postpaid",
				"spot_options": {
					"spot_price": 0,
					"block_duration_minutes": 0,
					"instance_interruption_behavior": ""
				}
			},
			"internet_access": {
				"publicip": {
					"publicip_type": "5_union",
					"charging_mode": "postPaid",
					"bandwidth": {
						"share_type": "PER",
						"size": 0,
						"charge_mode": "bandwidth",
						"id": ""
					}
				}
			},
			"metadata": {
				"additionalProp1": "",
				"additionalProp2": "",
				"additionalProp3": ""
			},
			"tag_options": [{
				"tags": [{
					"key": "aaa",
					"value": "bbb"
				}]
			}]
		},
		"name": "",
		"description": "create ecs template",
		"version_description": "1.0"
	},
	"dry_run": false
}

Example Response

{   "launch_template_id": "e6b99563-xxxx-xxxx-xxxx-1820d4fd2a67" }

Error Codes

See Error Codes.