创建虚拟接口对等体
功能介绍
每个虚拟接口可支持两个对等体,IPv4和IPv6对等体,在创建虚拟接口时默认创建IPv4对等体, 本接口一般用于增加ipv6对等体。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/dcaas/vif-peers
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
租户项目ID |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 获取Token,请参考《统一身份认证服务API参考》的“获取用户Token”章节。请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。 最小长度:0 最大长度:10240 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
vif_peer |
否 |
CreateVifPeer object |
创建虚拟接口对等体参数 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
VIF对等体名字 最小长度:0 最大长度:64 |
description |
否 |
String |
VIF对等体名字描述信息 最小长度:0 最大长度:128 |
address_family |
是 |
String |
接口的地址簇类型,ipv4,ipv6 |
local_gateway_ip |
是 |
String |
VIF对等体云侧接口地址 |
remote_gateway_ip |
是 |
String |
VIF对等体客户侧接口地址 |
route_mode |
否 |
String |
路由模式:static/bgp 最大长度:255 枚举值:
|
bgp_asn |
否 |
Integer |
BGP邻居的AS号 最小值:1 最大值:4294967295 |
bgp_md5 |
否 |
String |
BGP邻居的MD5密码 |
remote_ep_group |
否 |
Array of strings |
远端子网列表,记录租户侧的cidrs |
vif_id |
是 |
String |
vif对等体对应的虚拟接口ID 最小长度:36 最大长度:36 |
响应参数
状态码: 201
参数 |
参数类型 |
描述 |
---|---|---|
vif_peer |
VifPeer object |
虚拟接口对等体对象 |
request_id |
String |
操作请求ID |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
资源ID 最小长度:36 最大长度:36 |
tenant_id |
String |
归属租户ID 最小长度:36 最大长度:36 |
name |
String |
VIF对等体名字 最小长度:0 最大长度:64 |
description |
String |
VIF对等体名字描述信息 最小长度:0 最大长度:128 |
address_family |
String |
接口的地址簇类型,ipv4,ipv6 |
local_gateway_ip |
String |
VIF对等体云侧接口地址 |
remote_gateway_ip |
String |
VIF对等体客户侧接口地址 |
route_mode |
String |
路由模式:static/bgp 最大长度:255 枚举值:
|
bgp_asn |
Integer |
BGP邻居的AS号 最小值:1 最大值:4294967295 |
bgp_md5 |
String |
BGP邻居的MD5密码 |
remote_ep_group |
Array of strings |
远端子网列表,记录租户侧的cidrs |
service_ep_group |
Array of strings |
该字段用于公网专线接口,表示租户可以访问云上公网服务地址列表 |
device_id |
String |
归属的设备ID |
bgp_route_limit |
Integer |
BGP的路由配置规格 |
bgp_status |
String |
接口BGP协议状态,如果是静态路由接口则状态为 null 最大长度:10 |
status |
String |
VIF对等体状态 |
vif_id |
String |
vif对等体对应的虚拟接口ID 最小长度:36 最大长度:36 |
receive_route_num |
Integer |
路由模式为bgp:receive_route_num值为接收搭配BGP的路由数目; 路由模式为static:该字段无意义,值为-1; 注:若早期接入云上的部分用户无法获取该字段信息,如需要请联系客服迁移专线端口。 |
enable_nqa |
Boolean |
是否使能nqa功能:true或false |
enable_bfd |
Boolean |
是否使能bfd功能:true或false |
请求示例
创建一个虚拟接口对等体,远端子网列表为20.1.1.0/24。
POST https://{endpoint}/v3/cfa563efb77d4b6d9960781d82530fd8/dcaas/vif-peers { "vif_peer" : { "name" : "vif-0819", "address_family" : "ipv4", "description" : "mytest", "local_gateway_ip" : "12.3.4.1/30", "remote_gateway_ip" : "12.3.4.2/30", "vif_id" : "5d6c17bc-0ebe-420b-8734-21f519e9d7ad", "remote_ep_group" : [ "20.1.1.0/24" ] } }
响应示例
状态码: 201
Created
{ "vif_peer" : { "name" : "vif-0819", "description" : "mytest", "id" : "4c95de3e-9f75-4357-9c79-b22498dd71c7", "tenant_id" : "ed28c294165741faaeccab26913122a1", "address_family" : "ipv4", "local_gateway_ip" : "12.3.4.1/30", "remote_gateway_ip" : "12.3.4.2/30", "route_mode" : "static", "bgp_asn" : null, "bgp_md5" : null, "bgp_route_limit" : 100, "bgp_status" : null, "status" : "ACTIVE", "vif_id" : "5d6c17bc-0ebe-420b-8734-21f519e9d7ad", "receive_route_num" : -1, "remote_ep_group" : [ "12.3.4.0/30 172.56.0.0/16" ] } }
SDK代码示例
SDK代码示例如下。
创建一个虚拟接口对等体,远端子网列表为20.1.1.0/24。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.dc.v3.region.DcRegion; import com.huaweicloud.sdk.dc.v3.*; import com.huaweicloud.sdk.dc.v3.model.*; import java.util.List; import java.util.ArrayList; public class CreateVifPeerSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); DcClient client = DcClient.newBuilder() .withCredential(auth) .withRegion(DcRegion.valueOf("<YOUR REGION>")) .build(); CreateVifPeerRequest request = new CreateVifPeerRequest(); CreateVifPeerRequestBody body = new CreateVifPeerRequestBody(); List<String> listVifPeerRemoteEpGroup = new ArrayList<>(); listVifPeerRemoteEpGroup.add("20.1.1.0/24"); CreateVifPeer vifPeerbody = new CreateVifPeer(); vifPeerbody.withName("vif-0819") .withDescription("mytest") .withRemoteEpGroup(listVifPeerRemoteEpGroup); body.withVifPeer(vifPeerbody); request.withBody(body); try { CreateVifPeerResponse response = client.createVifPeer(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
创建一个虚拟接口对等体,远端子网列表为20.1.1.0/24。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdc.v3.region.dc_region import DcRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdc.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = DcClient.new_builder() \ .with_credentials(credentials) \ .with_region(DcRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateVifPeerRequest() listRemoteEpGroupVifPeer = [ "20.1.1.0/24" ] vifPeerbody = CreateVifPeer( name="vif-0819", description="mytest", remote_ep_group=listRemoteEpGroupVifPeer ) request.body = CreateVifPeerRequestBody( vif_peer=vifPeerbody ) response = client.create_vif_peer(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
创建一个虚拟接口对等体,远端子网列表为20.1.1.0/24。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dc/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dc/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dc/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := dc.NewDcClient( dc.DcClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateVifPeerRequest{} var listRemoteEpGroupVifPeer = []string{ "20.1.1.0/24", } nameVifPeer:= "vif-0819" descriptionVifPeer:= "mytest" vifPeerbody := &model.CreateVifPeer{ Name: &nameVifPeer, Description: &descriptionVifPeer, RemoteEpGroup: &listRemoteEpGroupVifPeer, } request.Body = &model.CreateVifPeerRequestBody{ VifPeer: vifPeerbody, } response, err := client.CreateVifPeer(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
201 |
Created |
错误码
请参见错误码。