示例一:创建站点入云VPN网关
操作场景
本章节指导用户通过调用API来创建站点入云VPN网关。
前提条件
- 已创建VPC,具体请参见创建VPC。
- 您需要规划VPN网关所在的区域信息,并根据区域确定调用API的Endpoint。
- 当您使用Token认证方式完成认证鉴权时,需要获取用户Token并在调用接口时增加“X-Auth-Token”到业务接口请求消息头中。Token认证,具体操作请参考认证鉴权章节。
通过IAM服务获取到的Token有效期为24小时,需要使用同一个Token鉴权时,可以先将Token缓存,避免频繁调用。
数据准备
参数 |
说明 |
取值样例 |
---|---|---|
vpc_id |
VPN网关所连接的VPC的ID。 |
cb4a631d-demo-a8df-va86-ca3fa348c36c |
local_subnets |
本端网段。 |
192.168.0.0/24,192.168.1.0/24 |
connect_subnet |
VPN网关所使用的VPC中的子网ID。 |
f5741286-demo-a8df-va86-2c82bd9ee114 |
eip1.id |
VPN网关使用的第一个EIP的ID。 |
cff40e5e-demo-a8df-va86-7366077bf097 |
eip2.id |
VPN网关使用的第二个EIP的ID。 |
d290f1ee-demo-a8df-va86-d701748f0851 |
操作步骤
- 创建关联VPC的VPN网关。
- 发送“POST https://{endpoint}/v5/{project_id}/vpn-gateways”,project_id为项目ID。
- 在Request Header中增加“X-Auth-Token”。
- 在Request Body中传入参数如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{ "vpn_gateway": { "vpc_id": "cb4a631d-demo-a8df-va86-ca3fa348c36c", "local_subnets": [ "192.168.0.0/24", "192.168.1.0/24" ], "connect_subnet": "f5741286-demo-a8df-va86-2c82bd9ee114", "eip1": { "id": "cff40e5e-demo-a8df-va86-7366077bf097" }, "eip2": { "id": "d290f1ee-demo-a8df-va86-d701748f0851" } } }
- 查看请求响应结果。
- 请求成功时,响应参数如下,id就是VPN网关的ID。
{ "vpn_gateway": { "id": "620d99b8-demo-a8df-va86-200b868f2d7d", "name": "vpngw-3caf", "network_type": "public", "attachment_type": "vpc", "vpc_id": "cb4a631d-demo-a8df-va86-ca3fa348c36c", "local_subnets": ["192.168.0.0/24", "192.168.1.0/24"], "connect_subnet": "f5741286-demo-a8df-va86-2c82bd9ee114", "bgp_asn": 64512, "access_vpc_id": "cb4a631d-demo-a8df-va86-ca3fa348c36c", "access_subnet_id": "f5741286-demo-a8df-va86-2c82bd9ee114", "flavor": "Professional1", "used_connection_number": 0, "used_connection_group": 0, "enterprise_project_id": "0" }, "request_id": "4a739f5c-edb7-4122-b31f-b77fb1b94857" }
- 请求成功时,响应参数如下,id就是VPN网关的ID。
- 查询VPN网关详情。
- 发送“GET https://{endpoint}/v5/{project_id}/vpn-gateways/{vgw_id}”,project_id为项目ID。
- 在Request Header中增加“X-Auth-Token”。
- 查看请求响应结果。
- 请求成功时,响应参数如下,id就是VPN网关的ID。
{ "vpn_gateway": { "id": "620d99b8-demo-a8df-va86-200b868f2d7d", "name": "vpngw-3caf", "network_type": "public", "status": "ACTIVE", "attachment_type": "vpc", "vpc_id": "cb4a631d-demo-a8df-va86-ca3fa348c36c", "local_subnets": [ "192.168.0.0/24", "192.168.1.0/24" ], "connect_subnet": "f5741286-demo-a8df-va86-2c82bd9ee114", "access_vpc_id": "cb4a631d-demo-a8df-va86-ca3fa348c36c", "access_subnet_id": "f5741286-demo-a8df-va86-2c82bd9ee114", "bgp_asn": 64512, "flavor": "Professional1", "availability_zone_ids": [ "cn-south-1f", "cn-south-1e" ], "used_connection_number": 0, "used_connection_group": 0, "enterprise_project_id": "0", "eip1": { "id": "cff40e5e-demo-a8df-va86-7366077bf097", "ip_version": 4, "type": "5_bgp", "ip_address": "88.***.***.8", "charge_mode": "bandwidth", "bandwidth_size": 300, "bandwidth_name": "vpngw-bandwidth-1391" }, "eip2": { "id": "d290f1ee-demo-a8df-va86-d701748f0851", "ip_version": 4, "type": "5_bgp", "ip_address": "88.***.***.6", "charge_mode": "bandwidth", "bandwidth_size": 300, "bandwidth_name": "vpngw-bandwidth-1392" }, "created_at": "2022-09-15T08:56:09.386Z", "updated_at": "2022-09-15T11:13:13.677Z" }, "request_id": "d099a7dc-ea71-45a6-a75b-dccbfe17d438" }
- 请求成功时,响应参数如下,id就是VPN网关的ID。