Creating a VPC Peering Connection

Sample Code

You can use the API to create a VPC peering connection. Sample code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
// Import classes:
import com.huaweicloud.cs.java.v1.client.ApiException;
import com.huaweicloud.cs.java.v1.ClusterApi;


ClusterApi apiInstance = new ClusterApi(apiClient);//apiClient is created when initializing a CS API client.
String xProjectId = "xProjectId_example"; // String | 
Integer clusterId = 56; // Integer | 
CreatePeeringRequest body = new CreatePeeringRequest(); // CreatePeeringRequest | Create a VPC peering connection with request parameters being in the JSON format.
try {
    CreatePeeringResponse result = apiInstance.createPeering(xProjectId, clusterId, body);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling ClusterApi#createPeering");
    System.err.println(e.getResponseBody());
    e.printStackTrace();
}

Parameters

Table 1 Parameters

Parameter

Mandatory

Type

Description

xProjectId

Yes

String

Project ID. This parameter is used to obtain the token for the project.

ClusterId

Yes

Integer

User ID.

body

Yes

-

Whether to create a VPC peering connection with request parameters being in the JSON format. For details about parameter types, see Table 2.

Table 2 Parameters involved in CreatePeeringRequest

Parameter

Mandatory

Type

Description

vpcId

No

String

ID of a VPC.

name

No

String

Name of a VPC.

acceptTenantId

No

String

ID of the tenant to which the peer VPC belongs.

Table 3 Parameters involved in CreatePeeringResponse

Parameter

Mandatory

Type

Description

peering

No

-

VPC peering connection information. For details about parameter types, see Table 4.

Table 4 Parameters involved in Peering

Parameter

Mandatory

Type

Description

name

No

String

Name of a VPC peering connection.

id

No

String

ID of a VPC peering connection.

requestVpcInfo

No

-

Information about the local VPC. For details, see Table 5.

acceptVpcInfo

No

-

Information about the peer VPC. For details, see Table 5.

status

No

String

Status of a VPC peering connection.

Table 5 Parameters involved in VpcInfo

Parameter

Mandatory

Type

Description

vpcId

No

String

ID of a VPC peering connection.

tenantId

No

String

Tenant ID.