Creating a Route

Sample Code

You can use the API to create a route. Sample code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// 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 | 
String peeringId = "peeringId_example"; // String | 
CreateRouteRequest body = new CreateRouteRequest(); // CreateRouteRequest | Create a route with the request parameters being in the JSON format.
try {
    CreateRouteResponse result = apiInstance.createRoute(xProjectId, clusterId, peeringId, body);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling ClusterApi#createRoute");
    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

ID of an exclusive cluster.

peeringId

Yes

String

ID of a VPC peering connection.

body

Yes

-

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

Table 2 Parameters involved in GCreateRouteRequest

Parameter

Mandatory

Type

Description

destination

No

String

DestinationCIDR of a route.

Table 3 Parameters involved in CreateRouteResponse

Parameter

Mandatory

Type

Description

route

No

-

Information about a route. For details about parameter types, see Table 4.

Table 4 Parameters involved in Route

Parameter

Mandatory

Type

Description

type

No

String

Route type. Generally, this parameter is set to peering.

nexthop

No

String

Next-hop address, which is the ID of the VPC peering connection.

destination

No

String

DestinationCIDR of a route.

vpcId

No

String

ID of the VPC for which a route is to be added.

tenantId

No

String

ID of the tenant who requests to add a route.

id

No

String

ID of a route.