Updated on 2024-08-01 GMT+08:00

Creating a VPC

Function

This API is used to create a VPC.

URI

POST /v1/{project_id}/vpcs

Table 1 describes the parameters.
Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

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

Request Parameters

Table 2 Request parameter

Parameter

Mandatory

Type

Description

vpc

Yes

vpc object

Specifies the VPC objects.

Table 3 VPC objects

Parameter

Mandatory

Type

Description

name

No

String

  • Specifies the VPC name.
  • The value can contain no more than 64 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).
  • Each VPC name of a tenant must be unique if the VPC name is not left blank.

description

No

String

  • Provides supplementary information about the VPC.
  • The value can contain no more than 255 characters and cannot contain angle brackets (< or >).

cidr

No

String

  • Specifies the available IP address ranges for subnets in the VPC.
  • Possible values are as follows:
    • 10.0.0.0/8-24
    • 172.16.0.0/12-24
    • 192.168.0.0/16-24
  • If cidr is not specified, the default value is left blank.
  • The value must be in CIDR format, for example, 192.168.0.0/16.

enterprise_project_id

No

String

  • Specifies the enterprise project ID. When creating a VPC, you can associate an enterprise project ID with the VPC.
  • The value is 0 or a string that contains a maximum of 36 characters in UUID format with hyphens (-). Value 0 indicates the default enterprise project.
NOTE:

For more information about enterprise projects and how to obtain enterprise project IDs, see the Enterprise Management User Guide.

tags

No

Array of Strings

  • Specifies VPC tags. When creating a VPC, you can add tags to the VPC.
  • Each VPC can have up to 10 tags.
    • key: Tag key. The key cannot be empty and can contain up to 128 characters (36 characters on the console). It can consist of letters, digits, underscores (_), and hyphens (-). Tag keys of a resource must be unique.
    • value: Tag value. The value can contain up to 255 characters (43 characters on the console). It can consist of letters, digits, underscores (_), periods (.), and hyphens (-).
  • Format: [key*value]. The key and value of each tag are connected by an asterisk (*).

Example Request

  • Create a VPC named vpc and set its CIDR block to 192.168.0.0/16.
    POST https://{Endpoint}/v1/{project_id}/vpcs
    
    {
        "vpc": {
            "name": "vpc",
            "description": "test",
            "cidr": "192.168.0.0/16",
            "enterprise_project_id": "0aad99bc-f5f6-4f78-8404-c598d76b0ed2"
        }
    }

Response Parameters

Table 4 Response parameter

Parameter

Type

Description

vpc

vpc object

Specifies the VPC objects.

Table 5 VPC objects

Parameter

Type

Description

id

String

Specifies a resource ID in UUID format.

name

String

  • Specifies the VPC name.
  • The value can contain no more than 64 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).
  • Each VPC name of a tenant must be unique if the VPC name is not left blank.

description

String

  • Provides supplementary information about the VPC.
  • The value can contain no more than 255 characters and cannot contain angle brackets (< or >).

cidr

String

  • Specifies the available IP address ranges for subnets in the VPC.
  • Possible values are as follows:
    • 10.0.0.0/8-24
    • 172.16.0.0/12-24
    • 192.168.0.0/16-24
  • If cidr is not specified, the default value is left blank.
  • The value must be in CIDR format, for example, 192.168.0.0/16.

status

String

  • Specifies the VPC status.
  • Possible values are as follows:
    • CREATING: The VPC is being created.
    • OK: The VPC is created successfully.

routes

Array of route objects

  • Specifies the route information.
  • For details, see the description of the route objects.

enterprise_project_id

String

  • Specifies the enterprise project ID.
  • The value is 0 or a string that contains a maximum of 36 characters in UUID format with hyphens (-). Value 0 indicates the default enterprise project.
NOTE:

For more information about enterprise projects and how to obtain enterprise project IDs, see the Enterprise Management User Guide.

tenant_id

String

  • Project ID

created_at

String

  • Specifies the time (UTC) when the VPC is created.
  • Format: yyyy-MM-ddTHH:mm:ss

updated_at

String

  • Specifies the time (UTC) when the VPC is updated.
  • Format: yyyy-MM-ddTHH:mm:ss
Table 6 route objects

Parameter

Type

Description

destination

String

  • Specifies the destination CIDR block of a route.
  • Constraints: The value must be in the CIDR format. IPv4 and IPv6 CIDR formats are supported.

nexthop

String

  • Specifies the next hop of a route.
  • The value must be an IP address from the subnet of the VPC. IPv4 and IPv6 addresses are supported.

Example Response

{
 "vpc": 
     {
     "id": "99d9d709-8478-4b46-9f3f-2206b1023fd3",
     "name": "vpc",
     "description": "test",
     "cidr": "192.168.0.0/16",
     "status": "CREATING",
     "enterprise_project_id": "0aad99bc-f5f6-4f78-8404-c598d76b0ed2", 
     "routes": [],
     "tenant_id": "087679f0aa80d32a2f4ec0172f5e902b",
     "created_at": "2022-12-15T02:25:11",
     "updated_at": "2022-12-15T02:25:11"
     }
}

Status Code

See Status Codes.

Error Code

See Error Codes.