• Native OpenStack API

noa
  1. Help Center
  2. Native OpenStack API
  3. Developer Guide
  4. Development Guide
  5. Application Scenarios of ECSs
  6. Creating an ECS

Creating an ECS

Guidelines

  • Before creating an ECS, apply for EVS system and data disks. For details, see section Application Scenarios of EVS Disks.
  • Before creating an ECS, prepare one primary network interface card (NIC) and apply for a port for the ECS. Ensure that the ECS has only one primary NIC. For details, see section Creating a Port.
  • When creating an ECS, do not delete the image, network, subnet, and security group information.
  • Do not create ECSs in batches.
  • If you create an ECS without observing the preceding guidelines, the ECS creation may fail or the created ECS may be unavailable. In this case, delete the ECS and create one by following the preceding constraints and guidelines.
  • For the parameters that do not have constraints, see the API description of native OpenStack.

Interface Invoking Procedure

Create an ECS as follows:

  1. Invoke the following Neutron API to create a port:

    POST /v2.0/ports

    For descriptions of the parameters, see Application Scenarios of the VPC Service.

  2. Invoke the following Cinder API to create EVS system and data disks. You must create an EVS system disk before performing next step.

    POST /v2/{tenant_id}/volumes

    For descriptions of the parameters, see Application Scenarios of EVS Disks.

  3. Invoke the Nova API to create an ECS:

    POST /v2/{project_id}/servers

    For descriptions of the parameters, see Parameters.

  4. Invoke the PUT /v2.0/ports/{port_id} API to configure the extra_dhcp_opts attribute of the port as follows:

    "extra_dhcp_opts": [{"opt_name": "3","opt_value": "172.16.150.1"},{"opt_name": "121","opt_value":"0.0.0.0/0,172.16.150.1"}]

    172.16.150.1 in the preceding information indicates the gateway of the customized subnet in the VPC.

    This attribute is used to control the default route on the ECS. You can configure the attribute of only one port on each ECS.

    For details, see Updating a Port.

Parameters

Parameter

Type

Mandatory

Description

imageRef

String

No

This parameter is invalid because the ECS is created from a volume.

flavorRef

String

Yes

Specifies the specifications ID. The parameter value cannot be a URL.

name

String

Yes

Specifies the ECS name. The value contains 1 to 254 characters.

metadata

Dict

No

Specifies the ECS metadata. For details, see Table 2-1.

personality

List(dict)

No

Specifies information about the file to be injected. For details, see Table 2-2.

adminPass

String

No

Specifies the administrator password. If this parameter is left blank, the system randomly generates a password.

block_device_mapping

List(dict)

No

Specifies the storage resources of the ECS. This parameter is an extended attribute. It is the storage resource interface of the old version and is not recommended. You cannot create ECSs in batches using the specified volume.

block_device_mapping_v2

List(dict)

No

Specifies the V2 interface of the ECS storage device. This parameter is an extended attribute. It is the storage resource interface of the new version. You cannot create ECSs in batches using the specified volume.

For details, see Table 3.

config_drive

Int

No

Specifies the config_drive disk to be attached to the ECS during the ECS creation for transferring information to the ECS. This parameter is an extended attribute.

security_groups

List(dict)

No

Specifies the security group that the ECS belongs to. This parameter is an extended attribute. The default parameter value is default.

networks

List(dict)

No

Specifies the NIC of the ECS. This parameter is an extended attribute.

For details, see Table 4.

key_name

String

No

Specifies the name of the key pair. This parameter is an extended attribute.

user_data

String

No

Specifies the user data. This parameter is an extended attribute. The parameter value contains 0 to 65,535 characters.

availability_zone

String

No

Specifies the availability zone (AZ) and host that the ECS belongs to. This parameter is an extended attribute.

return_reservation_id

Bool

No

Specifies whether the reservation ID allows batch creation of ECSs. The default value is false. This parameter is an extended attribute.

min_count

Int

No

min_count specifies the minimum number of ECSs that can be created. max_count specifies the maximum number of ECSs that can be created.

Both parameters are extended attributes.

The default value of min_count is 1.

The default value of max_count is the same as the min_count value.

Constraints:

The max_count value must be greater than the min_count value.

If both min_count and max_count are specified, the number of ECSs that can be created depends on host resources. If host resources permit, you can create a maximum number of ECSs ranging from min_count to max_count values.

max_count

Int

No

Table 1 Metadata parameters

Parameter

Type

Mandatory

Description

User-defined parameter key-value pair

String

No

Specifies the key-value pair of the metadata.

The key-value pair contains 0 to 255 characters.

Table 2 personality parameters

Parameter

Type

Mandatory

Description

contents

String

Yes

Specifies the content of the file to be injected. The content is encrypted using Base64, and the file must be smaller than 1 KB.

path

String

Yes

Specifies the directory containing the file to be injected.

If the in-use OS is Linux, enter the directory containing the file to be injected, for example, /etc/foo.txt.

If the in-use OS is Windows, the file to be injected is automatically stored in Drive C. You can enter the file name only, for example, you can enter foo for this parameter. The file name can contain only letters and digits.

Table 3 block_device_mapping_v2 parameters

Parameter

Type

Mandatory

Description

contents

String

Yes

Specifies the content of the file to be injected. The file is encrypted using Base64.

path

String

Yes

Specifies the directory containing the file to be injected.

source_type

String

Yes

Specifies the source type of the disk. The value can only be volume.

destination_type

String

Yes

Specifies the current type of the disk. The value can only be volume.

guest_format

String

No

Specifies the format of the local file system. For example, the value can be swap or ext4.

device_name

String

Yes

Specifies the disk device name. It contains 1 to 254 characters and cannot contain spaces. The recommended system disk device name is /dev/sda.

delete_on_termination

Bool

No

Specifies whether disks are deleted when an ECS is deleted. The default value is false.

boot_index

String

Yes

Specifies the boot sequence.

The value is 0 for the system disk and -1 for data disks.

uuid

String

No

Specifies the UUID of Cinder volumes.

Table 4 networks parameters

Parameter

Type

Mandatory

Description

port

Uuid-str

Yes

Specifies the UUID of the network port.

uuid

Uuid-str

No

Specifies the port used for creating an ECS. The parameter value is the network ID, which is not required during interface invoking.

fixed_ip

String

No

Specifies the fixed IP address of the port used for creating an ECS. The parameter value is a private IP address, which is not required during interface invoking.

The following provides an example of invoking the API for creating an ECS:

{

"server": {

"flavorRef": "2",

"name": "test-vm",

"metadata": {

"name": "test",

"id": "xxx-0123456"

},

"block_device_mapping_v2":[{

"uuid": " c32b7ff9-2ae2-4a89-a826-d9338d67af6f",

"device_name": "/dev/sda",

"source_type": "volume",

"destination_type": "volume",

"delete_on_termination": "True",

"boot_index": "0"

},

{

"uuid": " e730a11c -22ae2-4a89-a826-cee28d672ad6",

"device_name": "/dev/sdb1",

"source_type": "volume",

"destination_type": "volume",

"delete_on_termination": "True",

"boot_index": "-1"

}],

"personality": [{

"contents": "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==",

"path": "/etc/banner.txt"

}],

"adminPass": "test",

"security_groups": [{

"name": "test_sg"

},

{

"name": "test_sg"

}],

"networks": [{

"port": "e730a11c-1a19-49cc-8797-cee2ad67af6f",

},

{

"port": "c32b7ff9-2ae2-4a89-a826-d9338d5f476e",

}],

"user_data": "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==",

"availability_zone": "az1.dc1",

}

}