Batch set sequential instance names or hostnames

更新时间:
复制 MD 格式

When you create multiple ECS instances at once, they are assigned the same instance name and hostname by default. To distinguish, categorize, and manage your instances more easily, you can customize their names and hostnames during creation by applying sorting rules. This practice standardizes instance naming and improves management efficiency.

Specify a sequence for instance names or hostnames

When you create multiple ECS instances, you can configure their instance names or hostnames to follow a numeric sequence.

Specify a sequence

This method generates sequential instance names and hostnames based on a specific parameter format. The sequential number in the format differentiates the names across multiple ECS instances.

To use this method, enter the formatted string directly in the instance name or hostname field when you create ECS instances. The system then automatically generates the names by incrementing the numeric value. The parameter format is name_prefix[begin_number,bits]name_suffix. The following tables describe the parameters and provide examples.

Parameters

Parameter

Description

Example

name_prefix

The prefix for the instance name or hostname.

Note

This naming rule requires a prefix. If you omit the prefix, the system treats the name as a regular name and does not apply sequencing.

k8s-node-

[begin_number,bits]

The sequential numeric part of the name. The number increments for each new instance.

  • begin_number: The starting number for the sequence. Valid values: 0 to 999999. Default value: 0.

  • bits: The number of digits for the sequential number. The system pads the number with leading zeros if necessary. Valid values: 1 to 6. Default value: 6.

Important
  • Do not include spaces in the [begin_number,bits] field.

  • If the number of digits in begin_number exceeds the value of bits, bits defaults to 6.

  • You can create up to 999,999 instances with the same prefix and suffix. For any instances created beyond this limit, the sequential number remains 999999.

  • If you set [begin_number,bits] to [] or [,], begin_number starts from 0 and bits defaults to 6.

  • If, for [begin_number,bits], you specify only begin_number, for example, [99] or [99,], then bits defaults to 6.

[0,6]

name_suffix

The suffix for the instance name or hostname.

-ecshost

Parameter examples

Input example

Generated names

k8s-node-[]-ecshost or k8s-node-[,]-ecshost

  • k8s-node-000000-ecshost

  • k8s-node-000001-ecshost

  • k8s-node-000002-ecshost

k8s-node-[99]-ecshost or k8s-node-[99,]-ecshost

  • k8s-node-000099-ecshost

  • k8s-node-000100-ecshost

  • k8s-node-000101-ecshost

k8s-node-[99,1]-ecshost

  • k8s-node-000099-ecshost

  • k8s-node-000100-ecshost

  • k8s-node-000101-ecshost

k8s-node-[999998]-ecshost

  • k8s-node-999998-ecshost

  • k8s-node-999999-ecshost

  • k8s-node-999999-ecshost

k8s-node-[0,4]

  • k8s-node-0000

  • k8s-node-0001

  • k8s-node-0002

Procedure

This example shows how to create three ECS instances. Their instance names and hostnames start with the prefix k8s-node- and a numeric sequence that begins with 6. The hostnames also include the suffix -ecshost.

Important

The instance name and hostname that you enter must meet the following requirements:

  • Instance name: The name must be 2 to 128 characters long, start with a letter or a Chinese character, and contain only letters, Chinese characters, digits, periods (.), underscores (_), colons (:), or hyphens (-).

  • Hostname:

    • Windows: The hostname must be 2 to 15 characters long. It can contain letters, digits, and hyphens (-). The hostname cannot start or end with a hyphen. It also cannot contain consecutive hyphens or consist only of digits.

    • Other operating systems, such as Linux: The hostname must be 2 to 64 characters long. You can use periods (.) to separate the name into segments. Each segment can contain letters, digits, and hyphens (-). The hostname cannot start or end with a period or a hyphen. It also cannot contain consecutive periods or hyphens.

Console

For detailed instructions on how to create an ECS instance, see Custom launch ECS instances. When you create the instances, complete the following settings:

  • Quantity: On the Custom Launch page, in the Quantity section on the right, click the plus icon to set the quantity to 3.购买实例数量.png

  • To batch set instance names or hostnames, use the format name_prefix[begin_number,bits]name_suffix. For more information about the rules, see Specify a sequence.

    Important

    This example is only for specifying a sequence. The Sequential Suffix option is not selected.

    • Instance Name: Enter the desired instance name. In this example, the names for the three new ECS instances start with k8s-node- and a numeric sequence beginning with 6. Therefore, set Instance Name to k8s-node-[6,4].

    • Hostname: Select Custom Sequential Hostname below Custom Sequential Hostname, and then enter the desired hostname. In this example, the hostnames for the three new ECS instances start with k8s-node-, have a numeric sequence beginning with 6, and end with -ecshost. Therefore, set Hostname to k8s-node-[6,4]-ecshost.

    指定排序.png

After you configure the instances and click Create Order, you can go to the Console to view the instance information:

  • You can view the new instances in the instance list. Based on this example, the generated instance names are k8s-node-0006, k8s-node-0007, and k8s-node-0008.查看批量创建的ECS实例.png

  • On the Instance Details page, in the Other Information section, you can view the hostnames of the new instances. Based on this example, the generated hostnames are k8s-node-0006-ecshost, k8s-node-0007-ecshost, and k8s-node-0008-ecshost.

API

You can call the RunInstances operation to create ECS instances and specify their instance names and hostnames. The following section describes the parameter settings for specifying a sequence.

The format for the InstanceName (instance name) and HostName (hostname) parameters is name_prefix[begin_number,bits]name_suffix. For more information about the rules, see Specify a sequence.

This example creates three instances. Their instance names and hostnames start with k8s-node- and a sequence that begins at 6, and their hostnames end with -ecshost. The parameter settings are as follows:

  • Amount: 3

  • InstanceName: k8s-node-[6,4]

  • HostName: k8s-node-[6,4]-ecshost

Important

This example only uses the sequence specification method. The UniqueSuffix parameter is not enabled and uses its default setting.

Based on this example, the generated instance names are k8s-node-0006, k8s-node-0007, and k8s-node-0008, and the generated hostnames are k8s-node-0006-ecshost, k8s-node-0007-ecshost, and k8s-node-0008-ecshost.

Automatic sorting for instance names or hostnames

When you create multiple ECS instances at once, you can use the automatic sorting feature to add a sequential suffix to their instance names and hostnames.

Automatic sorting

The automatic sorting feature adds a three-digit sequential suffix to instance names and hostnames. When you enable this feature, the suffix starts from 001 and increments for each instance, up to a maximum of 999. This suffix differentiates the names across the instances.

Automatic sorting is disabled by default. To use this feature, you must enable it when you create ECS instances. After you enter an instance name and hostname, the system automatically appends a sequential suffix to generate the final names.

The following naming formats are supported when you enable automatic sorting.

Important

If you want to use the sequence specification method in combination with automatic sorting, you must include a name_suffix in the format string. Otherwise, the automatic sorting feature does not take effect. For more information about the rules for specifying a sequence, see Specify a sequence.

Naming formats for automatic sorting

Format

Input example

Generated names

Regular name (does not use a specified sequence)

ecs

  • ecs001

  • ecs002

  • ecs003

Specify a sequence: name_prefix[begin_number,bits]name_suffix

k8s-node-[]-ecshost or k8s-node-[,]-ecshost

  • k8s-node-000000-ecshost001

  • k8s-node-000001-ecshost002

  • k8s-node-000002-ecshost003

Note

Both specifying a sequence and automatic sorting take effect.

Specify a sequence: name_prefix[begin_number,bits]

k8s-node-[0,4]

  • k8s-node-0000

  • k8s-node-0001

  • k8s-node-0002

Note

Automatic sorting does not take effect because the format string does not specify the name_suffix parameter.

Procedure

This example shows how to create three instances with the instance name ecs and the hostname ecshost. The system automatically adds a sequential suffix to each name.

Important

The instance name and hostname that you enter must meet the following requirements:

  • Instance name: The name must be 2 to 128 characters long, start with a letter or a Chinese character, and contain only letters, Chinese characters, digits, periods (.), underscores (_), colons (:), or hyphens (-).

  • Hostname:

    • Windows: The hostname must be 2 to 15 characters long. It can contain letters, digits, and hyphens (-). The hostname cannot start or end with a hyphen. It also cannot contain consecutive hyphens or consist only of digits.

    • Other operating systems, such as Linux: The hostname must be 2 to 64 characters long. You can use periods (.) to separate the name into segments. Each segment can contain letters, digits, and hyphens (-). The hostname cannot start or end with a period or a hyphen. It also cannot contain consecutive periods or hyphens.

Console

For detailed instructions on how to create an ECS instance, see Custom launch ECS instances. When you create the instances, complete the following settings:

  • Quantity: On the Custom Launch page, in the Quantity section on the right, click the plus icon to set the quantity to 3.购买实例数量.png

  • Batch set instance names or hostnames: For more information about the rules for automatic sorting, see Automatic sorting.

    • Instance Name: Enter the desired instance name. In this example, the base name for the three new ECS instances is ecs. Set Instance Name to ecs.

    • Hostname: Enter the desired hostname. In this example, the base hostname for the three new ECS instances is ecshost. Set Hostname to ecshost.

    • Sequential Suffix: Select this option to automatically append a sequential suffix to the instance names and hostnames.

    自动排序.png

After you configure the instances and click Create Order, you can go to the Console to view the instance information:

  • You can view the new instances in the instance list. Based on this example, the generated instance names are ecs001, ecs002, and ecs003.

  • On the Instance Details page, in the Other Information section, you can view the hostnames of the new instances. Based on this example, the generated hostnames are ecshost001, ecshost002, and ecshost003.

API

You can call the RunInstances operation to create ECS instances and specify their instance names and hostnames. The following section describes the parameter settings for automatic sorting.

Set the UniqueSuffix parameter to true. The system then automatically appends a sequential suffix to the InstanceName and HostName. This suffix starts at 001 and increments for each instance. For more information about the rules for automatic sorting, see Automatic sorting.

This example shows how to create three instances with automatic sorting. The parameter settings are as follows:

  • Amount: 3

  • InstanceName: ecs

  • HostName: ecshost

  • UniqueSuffix: true

Based on this example, the generated instance names are ecs001, ecs002, and ecs003, and the generated hostnames are ecshost001, ecshost002, and ecshost003.

Related documents