Updated on 2022-01-25 GMT+08:00

Creating a VPC

Scenarios

This section describes how to call the VPC creation API to create a VPC. For details about the parameters for creating a VPC and the response message, see section Creating a VPC.

Prerequisites

You have planned the region where you want to create the VPC and obtained the endpoint required for API calls. For details, see Endpoints.

To use token authentication, you need to obtain a token and add X-Auth-Token to the request headers. Obtain the token by performing the steps provided in section Authentication.

The token obtained from IAM is valid for only 24 hours. If you want to use one token for authentication, you can cache it to avoid frequently obtaining the token.

Procedure

  1. Send POST https://VPC endpoint/v1/{project_id}/vpcs. Parameter project_id indicates the project ID.
  2. Add X-Auth-Token to the request header.
  3. Specify the following parameters in the request body:
    {
        "vpc": {
            "name": "vpc", //VPC name
            "cidr": "192.168.0.0/16" //Available subnet IP address ranges in the VPC
        }
    }
  4. Check the response message.
    • The request is successful if the following response is displayed. In the response, id indicates the VPC ID.
      {
          "vpc": {
              "id": "b6684a27-b049-407d-90b4-c9551f2390e1",
              "name": "vpc",
              "cidr": "192.168.0.0/16",
              "status": "CREATING",
              "routes": []
          }
      }
    • For details about the error codes displayed if the request fails, see section Error Codes.
  5. Query the VPC details as well as update or delete the VPC based on the vpc_id and project_id values.