网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
云手机服务器 CPH
专属主机 DeH
弹性伸缩 AS
镜像服务 IMS
函数工作流 FunctionGraph
云耀云服务器(旧版)
VR云渲游平台 CVR
Huawei Cloud EulerOS
云化数据中心 CloudDC
网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
CDN与智能边缘
内容分发网络 CDN
智能边缘云 IEC
智能边缘平台 IEF
CloudPond云服务
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
可信智能计算服务 TICS
推荐系统 RES
云搜索服务 CSS
数据可视化 DLV
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
湖仓构建 LakeFormation
智能数据洞察 DataArts Insight
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
开天aPaaS
应用平台 AppStage
开天企业工作台 MSSE
开天集成工作台 MSSI
API中心 API Hub
云消息服务 KooMessage
交换数据空间 EDS
云地图服务 KooMap
云手机服务 KooPhone
组织成员账号 OrgID
云空间服务 KooDrive
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
区块链
区块链服务 BCS
数字资产链 DAC
华为云区块链引擎服务 HBS
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
价格
成本优化最佳实践
专属云商业逻辑
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
其他
管理控制台
消息中心
产品价格详情
系统权限
客户关联华为云合作伙伴须知
公共问题
宽限期保留期
奖励推广计划
活动
云服务信任体系能力说明
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
存储容灾服务 SDRS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
云存储网关 CSG
专属分布式存储服务 DSS
数据工坊 DWR
地图数据 MapDS
键值存储服务 KVS
容器
云容器引擎 CCE
云容器实例 CCI
容器镜像服务 SWR
云原生服务中心 OSC
应用服务网格 ASM
华为云UCS
数据库
云数据库 RDS
数据复制服务 DRS
文档数据库服务 DDS
分布式数据库中间件 DDM
云数据库 GaussDB
云数据库 GeminiDB
数据管理服务 DAS
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
AI开发平台ModelArts
华为HiLens
图引擎服务 GES
图像识别 Image
文字识别 OCR
自然语言处理 NLP
内容审核 Moderation
图像搜索 ImageSearch
医疗智能体 EIHealth
企业级AI应用开发专业套件 ModelArts Pro
人脸识别服务 FRS
对话机器人服务 CBS
语音交互服务 SIS
人证核身服务 IVS
视频智能分析服务 VIAS
城市智能体
自动驾驶云服务 Octopus
盘古大模型 PanguLargeModels
IoT物联网
设备接入 IoTDA
全球SIM联接 GSL
IoT数据分析 IoTA
路网数字化服务 DRIS
IoT边缘 IoTEdge
设备发放 IoTDP
企业应用
域名注册服务 Domains
云解析服务 DNS
企业门户 EWP
ICP备案
商标注册
华为云WeLink
华为云会议 Meeting
隐私保护通话 PrivateNumber
语音通话 VoiceCall
消息&短信 MSGSMS
云管理网络
SD-WAN 云服务
边缘数据中心管理 EDCM
云桌面 Workspace
应用与数据集成平台 ROMA Connect
ROMA资产中心 ROMA Exchange
API全生命周期管理 ROMA API
政企自服务管理 ESM
视频
实时音视频 SparkRTC
视频直播 Live
视频点播 VOD
媒体处理 MPC
视频接入服务 VIS
数字内容生产线 MetaStudio
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
专属云
专属计算集群 DCC
开发者工具
SDK开发指南
API签名指南
DevStar
华为云命令行工具服务 KooCLI
Huawei Cloud Toolkit
CodeArts API
云化转型
云架构中心
云采用框架
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
客户运营能力
国际站常见问题
支持计划
专业服务
合作伙伴支持计划
我的凭证
华为云公共事业服务云平台
工业软件
工业数字模型驱动引擎
硬件开发工具链平台云服务
工业数据转换引擎云服务

创建虚拟接口

更新时间:2024-12-27 GMT+08:00
分享

功能介绍

虚拟接口配置物理专线上与客户互联的IP和路由等相关信息

调用方法

请参见如何调用API

URI

POST /v3/{project_id}/dcaas/virtual-interfaces

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户项目ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。 获取Token,请参考《统一身份认证服务API参考》的“获取用户Token”章节。请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。

最小长度:0

最大长度:10240

表3 请求Body参数

参数

是否必选

参数类型

描述

virtual_interface

CreateVirtualInterface object

创建虚拟接口对象参数

表4 CreateVirtualInterface

参数

是否必选

参数类型

描述

name

String

虚拟接口名字

最小长度:0

最大长度:64

description

String

虚拟接口描述信息

最小长度:0

最大长度:128

direct_connect_id

String

虚拟接口关联的物理专线ID。在创建虚拟接口时,需要关联direct_connect_id或lag_id,当LAG功能在当前局点不支持时,该参数为必选。

type

String

虚拟接口的类型:private

枚举值:private

service_type

String

接入网关的类型:包括VGW、GDGW、LGW等,VGW场景不需要配置该参数。

枚举值:

  • VGW
  • GDGW
  • LGW

vlan

Integer

对接客户侧vlan。当关联物理连接选择托管专线时,vlan需要和托管专线保持一致。

最小值:0

最大值:3999

bandwidth

Integer

虚拟接口接入带宽

最小值:2

最大值:2147483647

local_gateway_v4_ip

String

云侧网关IPv4接口地址,如果address_family是IPv4,是必选参数

remote_gateway_v4_ip

String

客户侧网关IPv4接口地址,如果address_family是IPv4,是必选参数

address_family

String

接口的地址簇类型,ipv4,ipv6

缺省值:ipv4

local_gateway_v6_ip

String

云侧网关IPv6接口地址,如果address_family是IPv6,是必选参数

remote_gateway_v6_ip

String

客户侧网关IPv6接口地址,如果address_family是IPv6,是必选参数

vgw_id

String

虚拟接口连接的虚拟网关的ID

route_mode

String

路由模式:static/bgp

缺省值:static

枚举值:

  • static
  • bgp

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

访问公网服务的子网列表

enable_bfd

Boolean

是否使能bfd功能:true或false。

缺省值:false

enable_nqa

Boolean

是否使能nqa功能:true或false。

缺省值:false

lag_id

String

虚拟接口关联的链路聚合组ID

最小长度:36

最大长度:36

resource_tenant_id

String

目标的租户的ID,用于跨租户创建虚拟接口场景

enterprise_project_id

String

实例所属企业项目ID

最小长度:36

最大长度:36

tags

Array of Tag objects

标签信息

数组长度:0 - 10

表5 Tag

参数

是否必选

参数类型

描述

key

String

标签键,最大长度36个unicode字符,格式为大小写字母,数字,中划线“-”,下划线“_”,中文。

最小长度:0

最大长度:36

value

String

标签值,最大长度43个unicode字符,格式为大小写字母,数字,中划线“-”,下划线“_”,点“.”,中文。

最小长度:0

最大长度:43

响应参数

状态码: 201

表6 响应Body参数

参数

参数类型

描述

request_id

String

操作请求ID

virtual_interface

VirtualInterface object

虚拟接口对象

表7 VirtualInterface

参数

参数类型

描述

id

String

虚拟接口的ID

最大长度:36

name

String

虚拟接口的名字

最大长度:64

admin_state_up

Boolean

管理状态:true或false

bandwidth

Integer

虚拟接口接入带宽

最小值:2

最大值:2147483647

create_time

String

虚拟接口创建时间。采用UTC时间格式,格式为:yyyy-MM-ddTHH:mm:ss.SSSZ

最大长度:255

update_time

String

虚拟接口修改时间。采用UTC时间格式,格式为:yyyy-MM-ddTHH:mm:ss.SSSZ

最大长度:255

description

String

虚拟接口的描述

最大长度:128

direct_connect_id

String

物理专线的ID

最大长度:36

service_type

String

接入网关的类型:包括VGW、GDGW、LGW等。

枚举值:

  • VGW
  • GDGW
  • LGW

status

String

操作状态,合法值是:ACTIVE,DOWN,BUILD,ERROR,PENDING_CREATE,PENDING_UPDATE,PENDING_DELETE,DELETED,AUTHORIZATION,REJECTED

tenant_id

String

租户ID

最小长度:32

最大长度:32

type

String

表示接口类型:private

缺省值:private

最大长度:255

枚举值:private

vgw_id

String

虚拟网关的ID

最小长度:36

最大长度:36

vlan

Integer

同用户网关对接的vlan, 配置范围0-3999

最小值:0

最大值:3999

route_limit

Integer

VIF远端子网路由配置规格

最小值:1

最大值:200

缺省值:50

enable_nqa

Boolean

是否使能nqa功能:true或false

enable_bfd

Boolean

是否使能bfd功能:true或false

lag_id

String

VIF关联的链路聚合组ID

最小长度:36

最大长度:36

device_id

String

归属的设备ID

enterprise_project_id

String

实例所属企业项目ID

最小长度:36

最大长度:36

tags

Array of Tag objects

标签信息

数组长度:0 - 10

local_gateway_v4_ip

String

云侧网关IPv4接口地址,该字段现已经移到vifpeer参数列表中,未来将会废弃。

remote_gateway_v4_ip

String

客户侧网关IPv4接口地址,该字段现已经移到vifpeer参数列表中,未来将会废弃。

ies_id

String

归属的IES站点的ID

reason

String

如果资源的状态是Error的情况下,该参数会显示相关错误信息。

rate_limit

Boolean

标识虚拟接口是否开启限速

address_family

String

接口的地址簇类型,ipv4,ipv6。该字段现已迁移到vifpeer参数列表中,未来将会废弃。

local_gateway_v6_ip

String

云侧网关IPv6接口地址,该字段现已迁移到vifpeer参数列表中,未来将会废弃。

remote_gateway_v6_ip

String

客户侧网关IPv6接口地址,该字段现已迁移到vifpeer参数列表中,未来将会废弃。

lgw_id

String

本地网关的ID,用于IES场景。

gateway_id

String

虚拟接口关联的网关的ID。

remote_ep_group

Array of strings

远端子网列表,记录租户侧的cidrs。该字段现已迁移到vifpeer参数列表中,未来将会废弃。

service_ep_group

Array of strings

该字段用于公网专线接口,表示租户可以访问云上公网服务地址列表。该字段现已迁移到vifpeer参数列表中,未来将会废弃。

bgp_route_limit

Integer

BGP的路由配置规格

priority

String

虚拟接口的优先级,支持两种优先级状态normal和low。 接口优先级相同时表示负载关系,接口优先级不同时表示主备关系,出云流量优先转到优先级更高的normal接口。 目前仅BGP模式接口支持。

缺省值:normal

枚举值:

  • normal
  • low

vif_peers

Array of VifPeer objects

vif的Peer的相关信息

extend_attribute

VifExtendAttribute object

扩展参数信息

表8 Tag

参数

参数类型

描述

key

String

标签键,最大长度36个unicode字符,格式为大小写字母,数字,中划线“-”,下划线“_”,中文。

最小长度:0

最大长度:36

value

String

标签值,最大长度43个unicode字符,格式为大小写字母,数字,中划线“-”,下划线“_”,点“.”,中文。

最小长度:0

最大长度:43

表9 VifPeer

参数

参数类型

描述

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
  • static

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

表10 VifExtendAttribute

参数

参数类型

描述

ha_type

String

虚拟接口的可用性检测类型

枚举值:

  • nqa
  • bfd

ha_mode

String

检测的具体的配置模式

枚举值:

  • auto_single
  • auto_multi
  • static_single
  • static_multi
  • enhance_nqa

detect_multiplier

Integer

检测的重试次数

缺省值:5

min_rx_interval

Integer

检测的接收时长间隔

缺省值:1000

min_tx_interval

Integer

检测的发送时长间隔

缺省值:1000

remote_disclaim

Integer

检测的远端的标识,用于静态BFD

local_disclaim

Integer

检测的本端的标识,用于静态BFD

请求示例

  • 创建一个private类型的虚拟接口,设置带宽为2,VLAN为332,云侧网关IPv4接口地址为1.1.1.1/30,客户侧网关IPv4接口地址为1.1.1.2/30,使用静态路由模式。
    POST https://{dc_endpoint}/v3/0605768a3300d5762f82c01180692873/dcaas/virtual-interfaces
    
    {
      "virtual_interface" : {
        "name" : "vif-0819",
        "description" : "mytest",
        "direct_connect_id" : "4673e339-8412-4ee1-b73e-2ba9cdfa54c1",
        "vgw_id" : "8a47064a-f34c-4f94-b7fe-cac456c9b37b",
        "vlan" : 332,
        "bandwidth" : 2,
        "local_gateway_v4_ip" : "1.1.1.1/30",
        "remote_gateway_v4_ip" : "1.1.1.2/30",
        "type" : "private",
        "route_mode" : "static",
        "remote_ep_group" : [ "1.1.2.0/30" ]
      }
    }

响应示例

状态码: 201

Created
{
  "virtual_interface" : {
    "id" : "0d0fdf63-f2c4-491c-8866-d504796189be",
    "name" : "vif-0819",
    "description" : "mytest",
    "tenant_id" : "0605768a3300d5762f82c01180692873",
    "direct_connect_id" : "4673e339-8412-4ee1-b73e-2ba9cdfa54c1",
    "vgw_id" : "8a47064a-f34c-4f94-b7fe-cac456c9b37b",
    "type" : "private",
    "service_type" : "VGW",
    "vlan" : 332,
    "bandwidth" : 2,
    "device_id" : "18.9.215.131",
    "status" : "ACTIVE",
    "create_time" : "2022-08-19T11:28:06.000Z",
    "update_time" : "2022-08-19T11:28:06.000Z",
    "admin_state_up" : true,
    "enable_bfd" : false,
    "route_limit" : 50,
    "enable_nqa" : false,
    "local_gateway_v4_ip" : "1.1.1.1/30",
    "remote_gateway_v4_ip" : "1.1.1.2/30",
    "ies_id" : null,
    "reason" : null,
    "rate_limit" : false,
    "local_gateway_v6_ip" : null,
    "remote_gateway_v6_ip" : null,
    "lgw_id" : null,
    "lag_id" : null,
    "priority" : "normal",
    "vif_peers" : [ {
      "id" : "c768eb52-12a8-4859-9b43-81194643040c",
      "tenant_id" : "0605768a3300d5762f82c01180692873",
      "name" : "vif-0819",
      "description" : "",
      "address_family" : "ipv4",
      "local_gateway_ip" : "1.1.1.1/30",
      "remote_gateway_ip" : "1.1.1.2/30",
      "route_mode" : "static",
      "bgp_asn" : null,
      "bgp_md5" : null,
      "device_id" : "18.9.215.131",
      "bgp_route_limit" : 100,
      "bgp_status" : null,
      "status" : "ACTIVE",
      "vif_id" : "0d0fdf63-f2c4-491c-8866-d504796189be",
      "receive_route_num" : -1,
      "remote_ep_group" : [ "1.1.2.0/30" ],
      "enable_bfd" : false,
      "enable_nqa" : false,
      "service_ep_group" : null
    } ],
    "enterprise_project_id" : "0"
  },
  "request_id" : "5633df7af874576d819a481c76673236"
}

SDK代码示例

SDK代码示例如下。

创建一个private类型的虚拟接口,设置带宽为2,VLAN为332,云侧网关IPv4接口地址为1.1.1.1/30,客户侧网关IPv4接口地址为1.1.1.2/30,使用静态路由模式。

 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
57
58
59
60
61
62
63
64
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 CreateVirtualInterfaceSolution {

    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();
        CreateVirtualInterfaceRequest request = new CreateVirtualInterfaceRequest();
        CreateVirtualInterfaceRequestBody body = new CreateVirtualInterfaceRequestBody();
        List<String> listVirtualInterfaceRemoteEpGroup = new ArrayList<>();
        listVirtualInterfaceRemoteEpGroup.add("1.1.2.0/30");
        CreateVirtualInterface virtualInterfacebody = new CreateVirtualInterface();
        virtualInterfacebody.withName("vif-0819")
            .withDescription("mytest")
            .withDirectConnectId("4673e339-8412-4ee1-b73e-2ba9cdfa54c1")
            .withType(CreateVirtualInterface.TypeEnum.fromValue("private"))
            .withVlan(332)
            .withBandwidth(2)
            .withLocalGatewayV4Ip("1.1.1.1/30")
            .withRemoteGatewayV4Ip("1.1.1.2/30")
            .withVgwId("8a47064a-f34c-4f94-b7fe-cac456c9b37b")
            .withRouteMode(CreateVirtualInterface.RouteModeEnum.fromValue("static"))
            .withRemoteEpGroup(listVirtualInterfaceRemoteEpGroup);
        body.withVirtualInterface(virtualInterfacebody);
        request.withBody(body);
        try {
            CreateVirtualInterfaceResponse response = client.createVirtualInterface(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());
        }
    }
}

创建一个private类型的虚拟接口,设置带宽为2,VLAN为332,云侧网关IPv4接口地址为1.1.1.1/30,客户侧网关IPv4接口地址为1.1.1.2/30,使用静态路由模式。

 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
# 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 = CreateVirtualInterfaceRequest()
        listRemoteEpGroupVirtualInterface = [
            "1.1.2.0/30"
        ]
        virtualInterfacebody = CreateVirtualInterface(
            name="vif-0819",
            description="mytest",
            direct_connect_id="4673e339-8412-4ee1-b73e-2ba9cdfa54c1",
            type="private",
            vlan=332,
            bandwidth=2,
            local_gateway_v4_ip="1.1.1.1/30",
            remote_gateway_v4_ip="1.1.1.2/30",
            vgw_id="8a47064a-f34c-4f94-b7fe-cac456c9b37b",
            route_mode="static",
            remote_ep_group=listRemoteEpGroupVirtualInterface
        )
        request.body = CreateVirtualInterfaceRequestBody(
            virtual_interface=virtualInterfacebody
        )
        response = client.create_virtual_interface(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

创建一个private类型的虚拟接口,设置带宽为2,VLAN为332,云侧网关IPv4接口地址为1.1.1.1/30,客户侧网关IPv4接口地址为1.1.1.2/30,使用静态路由模式。

 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
57
58
59
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.CreateVirtualInterfaceRequest{}
	var listRemoteEpGroupVirtualInterface = []string{
        "1.1.2.0/30",
    }
	nameVirtualInterface:= "vif-0819"
	descriptionVirtualInterface:= "mytest"
	directConnectIdVirtualInterface:= "4673e339-8412-4ee1-b73e-2ba9cdfa54c1"
	localGatewayV4IpVirtualInterface:= "1.1.1.1/30"
	remoteGatewayV4IpVirtualInterface:= "1.1.1.2/30"
	virtualInterfacebody := &model.CreateVirtualInterface{
		Name: &nameVirtualInterface,
		Description: &descriptionVirtualInterface,
		DirectConnectId: &directConnectIdVirtualInterface,
		Type: model.GetCreateVirtualInterfaceTypeEnum().PRIVATE,
		Vlan: int32(332),
		Bandwidth: int32(2),
		LocalGatewayV4Ip: &localGatewayV4IpVirtualInterface,
		RemoteGatewayV4Ip: &remoteGatewayV4IpVirtualInterface,
		VgwId: "8a47064a-f34c-4f94-b7fe-cac456c9b37b",
		RouteMode: model.GetCreateVirtualInterfaceRouteModeEnum().STATIC,
		RemoteEpGroup: listRemoteEpGroupVirtualInterface,
	}
	request.Body = &model.CreateVirtualInterfaceRequestBody{
		VirtualInterface: virtualInterfacebody,
	}
	response, err := client.CreateVirtualInterface(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

创建一个private类型的虚拟接口,设置带宽为2,VLAN为332,云侧网关IPv4接口地址为1.1.1.1/30,客户侧网关IPv4接口地址为1.1.1.2/30,使用静态路由模式。

 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
57
58
59
60
61
62
63
64
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 CreateVirtualInterfaceSolution {

    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();
        CreateVirtualInterfaceRequest request = new CreateVirtualInterfaceRequest();
        CreateVirtualInterfaceRequestBody body = new CreateVirtualInterfaceRequestBody();
        List<String> listVirtualInterfaceRemoteEpGroup = new ArrayList<>();
        listVirtualInterfaceRemoteEpGroup.add("1.1.2.0/30");
        CreateVirtualInterface virtualInterfacebody = new CreateVirtualInterface();
        virtualInterfacebody.withName("vif-0819")
            .withDescription("mytest")
            .withDirectConnectId("4673e339-8412-4ee1-b73e-2ba9cdfa54c1")
            .withType(CreateVirtualInterface.TypeEnum.fromValue("private"))
            .withVlan(332)
            .withBandwidth(2)
            .withLocalGatewayV4Ip("1.1.1.1/30")
            .withRemoteGatewayV4Ip("1.1.1.2/30")
            .withVgwId("8a47064a-f34c-4f94-b7fe-cac456c9b37b")
            .withRouteMode(CreateVirtualInterface.RouteModeEnum.fromValue("static"))
            .withRemoteEpGroup(listVirtualInterfaceRemoteEpGroup);
        body.withVirtualInterface(virtualInterfacebody);
        request.withBody(body);
        try {
            CreateVirtualInterfaceResponse response = client.createVirtualInterface(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());
        }
    }
}

创建一个private类型的虚拟接口,设置带宽为2,VLAN为332,云侧网关IPv4接口地址为1.1.1.1/30,客户侧网关IPv4接口地址为1.1.1.2/30,使用静态路由模式。

 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
# 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 = CreateVirtualInterfaceRequest()
        listRemoteEpGroupVirtualInterface = [
            "1.1.2.0/30"
        ]
        virtualInterfacebody = CreateVirtualInterface(
            name="vif-0819",
            description="mytest",
            direct_connect_id="4673e339-8412-4ee1-b73e-2ba9cdfa54c1",
            type="private",
            vlan=332,
            bandwidth=2,
            local_gateway_v4_ip="1.1.1.1/30",
            remote_gateway_v4_ip="1.1.1.2/30",
            vgw_id="8a47064a-f34c-4f94-b7fe-cac456c9b37b",
            route_mode="static",
            remote_ep_group=listRemoteEpGroupVirtualInterface
        )
        request.body = CreateVirtualInterfaceRequestBody(
            virtual_interface=virtualInterfacebody
        )
        response = client.create_virtual_interface(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

创建一个private类型的虚拟接口,设置带宽为2,VLAN为332,云侧网关IPv4接口地址为1.1.1.1/30,客户侧网关IPv4接口地址为1.1.1.2/30,使用静态路由模式。

 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
57
58
59
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.CreateVirtualInterfaceRequest{}
	var listRemoteEpGroupVirtualInterface = []string{
        "1.1.2.0/30",
    }
	nameVirtualInterface:= "vif-0819"
	descriptionVirtualInterface:= "mytest"
	directConnectIdVirtualInterface:= "4673e339-8412-4ee1-b73e-2ba9cdfa54c1"
	localGatewayV4IpVirtualInterface:= "1.1.1.1/30"
	remoteGatewayV4IpVirtualInterface:= "1.1.1.2/30"
	virtualInterfacebody := &model.CreateVirtualInterface{
		Name: &nameVirtualInterface,
		Description: &descriptionVirtualInterface,
		DirectConnectId: &directConnectIdVirtualInterface,
		Type: model.GetCreateVirtualInterfaceTypeEnum().PRIVATE,
		Vlan: int32(332),
		Bandwidth: int32(2),
		LocalGatewayV4Ip: &localGatewayV4IpVirtualInterface,
		RemoteGatewayV4Ip: &remoteGatewayV4IpVirtualInterface,
		VgwId: "8a47064a-f34c-4f94-b7fe-cac456c9b37b",
		RouteMode: model.GetCreateVirtualInterfaceRouteModeEnum().STATIC,
		RemoteEpGroup: listRemoteEpGroupVirtualInterface,
	}
	request.Body = &model.CreateVirtualInterfaceRequestBody{
		VirtualInterface: virtualInterfacebody,
	}
	response, err := client.CreateVirtualInterface(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

201

Created

错误码

请参见错误码

提示

您即将访问非华为云网站,请注意账号财产安全

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容