Updated on 2024-06-19 GMT+08:00

Changing a VPC for an ECS

Function

This API is used to change a VPC for an ECS.

This API is an asynchronous API. After the VPC change request is successfully delivered, job_id is returned. This does not mean the VPC change 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 change is successful.

Changing the VPC will detach the primary NIC from the ECS. Then, create a new primary NIC for the ECS in the changed VPC.

If the original primary NIC has an EIP bound, after the VPC is changed, this EIP will be bound to the new primary NIC.

  • Changing the VPC will interrupt ECS network connections and change the subnet, IP address, and MAC address of the ECS.
  • After the VPC is changed, you are required to reconfigure network-related application software and services, such as ELB, VPN, NAT, and DNS.
  • During the change process, do not perform operations on the ECS, including its EIP.

Constraints

  • The VPC of an ECS can be changed if the ECS has the primary NIC only.
  • The VPC of an ECS cannot be changed if the ECS has an IPv6 NIC added.

URI

POST /v1/{project_id}/cloudservers/{server_id}/changevpc

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.

server_id

Yes

Specifies the ECS ID.

Request

Table 2 describes the request parameters.
Table 2 Request parameters

Parameter

Mandatory

Type

Description

vpc_id

Yes

String

Specifies the VPC ID in UUID format.

nic

Yes

Object

Specifies the NICs to be added. For details, see Table 3.

Table 3 nic field description

Parameter

Mandatory

Type

Description

port_id

No

String

Specifies the NIC ID in UUID format. If this parameter is not left blank, the specified NIC is attached.

NOTE:

Either port_id or subnet_id must be specified.

You can obtain the NIC ID by querying the ports for accessing VPCs.

Note:

  • The NIC must be in a security group.
  • The NIC must be in DOWN state.
  • The VPC ID of the NIC must be the same as the specified VPC ID.
  • If both port_id and subnet_id are specified, port_id is used preferentially.
  • If port_id is specified, a network interface is used. In such a case, security_groups and ip_address do not take effect.

subnet_id

No

String

Specifies the information about the NICs to be added to an ECS.

Set the parameter value to the ID (in UUID format) of the network created in the VPC to which the target ECS belongs.

security_groups

No

Array of objects

Specifies the security groups for NICs. For details, see Table 4.

ip_address

No

String

Specifies the IP address. If this parameter is left blank, the IP address is automatically assigned.

Table 4 security_groups field description

Parameter

Mandatory

Type

Description

id

Yes

String

Specifies the ID of the security group.

Response

See Responses (Task).

Example Request

Change a VPC, add a NIC, select a security group, and specify an IP address for an ECS.

POST  https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/changevpc

{
    "vpc_id": "d32019d3-bc6e-4319-9c1d-6722fc136a23",
    "nic": {
        "subnet_id": "d32019d3-bc6e-4319-9c1d-6722fc136a23",
        "security_groups": [
            {
                "id": "f0ac4394-7e4a-4409-9701-ba8be283dbc3"
            }
        ],
        "ip_address": "192.168.255.1"
    }
}

Example Response

{
    "job_id": "ff8080829029501f01902e4a1703000f"
}

Error Codes

See Error Codes.