doc-exports/docs/vpn/api-ref/vpn_api_0042.html
Hongwei, King Wang 32c06a10a2 vpn_api
Reviewed-by: Sarda, Priya <prsarda@noreply.gitea.eco.tsi-dev.otc-service.com>
Co-authored-by: Hongwei, King Wang <king.wanghongwei@huawei.com>
Co-committed-by: Hongwei, King Wang <king.wanghongwei@huawei.com>
2024-08-15 14:18:28 +00:00

169 lines
13 KiB
HTML

<a name="EN-US_TOPIC_0000001807530320"></a><a name="EN-US_TOPIC_0000001807530320"></a>
<h1 class="topictitle1">Example 3: Creating a VPN Connection</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_section735517714575"><h4 class="sectiontitle">Scenario</h4><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p796611175712">This section describes how to create a VPN connection by calling APIs.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_section947611199575"><h4 class="sectiontitle">Prerequisites</h4><ul id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ul939314165229"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li2393101612213">You have created a VPN gateway. For details, see <a href="vpn_api_0014.html#EN-US_TOPIC_0000001854169133">Creating a VPN Gateway</a>.</li></ul>
<ul id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ul73529180224"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li10352418112218">You have created a customer gateway. For details, see <a href="vpn_api_0021.html#EN-US_TOPIC_0000001807530292">Creating a Customer Gateway</a>.</li></ul>
<ul id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ul124612035154812"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li184618358484">You have obtained a user token if you need to use token authentication. In addition, you need to add <strong id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_b87519134103335">X-Auth-Token</strong> to the request header when calling an API. For details about token authentication, see "Authentication" in the <em id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_i037075511320">Virtual Private Cloud API Reference</em>.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_section2411102135816"><h4 class="sectiontitle">Data Preparation</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_table444111294349" width="100%" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Key parameters in the request for creating a VPN connection</caption><thead align="left"><tr id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_row3459182917345"><th align="left" class="cellrowborder" valign="top" width="21.68%" id="mcps1.3.3.2.2.4.1.1"><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p194595291340">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="35.9%" id="mcps1.3.3.2.2.4.1.2"><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p2459112916345">Description</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="42.42%" id="mcps1.3.3.2.2.4.1.3"><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p11459102913414">Example Value</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_row983893718349"><td class="cellrowborder" valign="top" width="21.68%" headers="mcps1.3.3.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p18990446191511">vgw_id</p>
</td>
<td class="cellrowborder" valign="top" width="35.9%" headers="mcps1.3.3.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p1283814373343">Specifies a VPN gateway ID.</p>
</td>
<td class="cellrowborder" valign="top" width="42.42%" headers="mcps1.3.3.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p197602025143814"><span id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ph343171732420">b32d91a4-demo-a8df-va86-e907174eb11d</span></p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_row337514017345"><td class="cellrowborder" valign="top" width="21.68%" headers="mcps1.3.3.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p2057916524153">vgw_ip</p>
</td>
<td class="cellrowborder" valign="top" width="35.9%" headers="mcps1.3.3.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p83751440153410">Specifies an EIP ID of the VPN gateway.</p>
</td>
<td class="cellrowborder" valign="top" width="42.42%" headers="mcps1.3.3.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p1337564019342"><span id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ph1443251722414">0c464dad-demo-a8df-va86-c22bb0eb0bde</span></p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_row87344317345"><td class="cellrowborder" valign="top" width="21.68%" headers="mcps1.3.3.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p673243183412">cgw_id</p>
</td>
<td class="cellrowborder" valign="top" width="35.9%" headers="mcps1.3.3.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li42631249182519p0">Specifies a customer gateway ID.</p>
</td>
<td class="cellrowborder" valign="top" width="42.42%" headers="mcps1.3.3.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p192514474383"><span id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ph3433201752415">5247ae10-demo-a8df-va86-dd36659a7f5d</span></p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_row1858634414013"><td class="cellrowborder" valign="top" width="21.68%" headers="mcps1.3.3.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p256715317160">peer_subnets</p>
</td>
<td class="cellrowborder" valign="top" width="35.9%" headers="mcps1.3.3.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li119173219119p0">Specifies a customer subnet.</p>
</td>
<td class="cellrowborder" valign="top" width="42.42%" headers="mcps1.3.3.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p1058714418017">192.168.44.0/24</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_row16313347004"><td class="cellrowborder" valign="top" width="21.68%" headers="mcps1.3.3.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p176178817162">psk</p>
</td>
<td class="cellrowborder" valign="top" width="35.9%" headers="mcps1.3.3.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p67772381872">Specifies a pre-shared key.</p>
</td>
<td class="cellrowborder" valign="top" width="42.42%" headers="mcps1.3.3.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_p11682531113716">abcd****</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_section2035717144589"><h4 class="sectiontitle">Procedure</h4><ol id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ol1033516371743"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li133351379413">Create a VPN connection in static routing mode for a VPN gateway associated with a VPC.<ol type="a" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ol7630731105015"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li18354814195019">Send <strong id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_b193873912116">POST https://{endpoint}/v5/{project_id}/vpn-connection</strong>.</li><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li12354121485016">Add <strong id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_b19578924010514">X-Auth-Token</strong> to the request header.</li><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li735414146508">Specify the following parameters in the request body:<pre class="screen" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_screen1778465375316">{
"vpn_connection": {
"vgw_id": "b32d91a4-demo-a8df-va86-e907174eb11d",
"vgw_ip": "0c464dad-demo-a8df-va86-c22bb0eb0bde",
"cgw_id": "5247ae10-demo-a8df-va86-dd36659a7f5d",
"peer_subnets": [
"192.168.44.0/24"
],
"psk": "abcd****"
}
}</pre>
</li><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li1963133185019">Check the response.<ul id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ul1363113195012"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li1463173112507">The request is successful if the following response is displayed. In the response, <strong id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_b1745911442148">id</strong> indicates a VPN connection ID.<pre class="screen" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_screen678017232489">{
"vpn_connection": {
"id": "98c5af8a-demo-a8df-va86-ae2280a6f4c3",
"name": "vpn-1655",
"vgw_id": "b32d91a4-demo-a8df-va86-e907174eb11d",
"vgw_ip": "0c464dad-demo-a8df-va86-c22bb0eb0bde",
"style": "STATIC",
"cgw_id": "5247ae10-demo-a8df-va86-dd36659a7f5d",
"peer_subnets": ["192.168.44.0/24"],
"tunnel_local_address": "169.254.56.225/30",
"tunnel_peer_address": "169.254.56.226/30",
"enable_nqa": false,
"ikepolicy": {
"ike_version": "v2",
"authentication_algorithm": "sha2-256",
"encryption_algorithm": "aes-128",
"dh_group": "group15",
"authentication_method": "pre-share",
"lifetime_seconds": 86400,
"local_id_type": "ip",
"local_id": "10.***.***.134",
"peer_id_type": "ip",
"peer_id": "88.***.***.164",
"dpd": {
"timeout": 15,
"interval": 30,
"msg": "seq-hash-notify"
}
},
"ipsecpolicy": {
"authentication_algorithm": "sha2-256",
"encryption_algorithm": "aes-128",
"pfs": "group15",
"transform_protocol": "esp",
"lifetime_seconds": 3600,
"encapsulation_mode": "tunnel"
},
"created_at": "2022-11-26T13:41:34.626Z",
"updated_at": "2022-11-26T13:41:34.626Z",
"enterprise_project_id": "0",
},
"request_id": "f74da97d-aa27-4f62-a87c-a33b5706964b"
}</pre>
</li></ul>
</li></ol>
</li><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li1355101465012">Query details about the VPN connection.<ol type="a" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ol95722017111819"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li557281720184">Send <strong id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_b108342582111">GET https://{endpoint}/v5/{project_id}/vpn-connection/{vpn_connection_id}</strong>.</li><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li1457214173183">Add <strong id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_b11622862450514">X-Auth-Token</strong> to the request header.</li><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li15572717141815">Check the response.<ul id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_ul1057214178189"><li id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_li155727173189">The request is successful if the following response is displayed. In the response, <strong id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_b8518150191412">id</strong> indicates a VPN connection ID.<pre class="screen" id="EN-US_TOPIC_0000001807530320__en-us_topic_0000001543833180_screen766219718483">{
"vpn_connection": {
"id": "98c5af8a-demo-a8df-va86-ae2280a6f4c3",
"name": "vpn-1655",
"status": "DOWN",
"vgw_id": "b32d91a4-demo-a8df-va86-e907174eb11d",
"vgw_ip": "0c464dad-demo-a8df-va86-c22bb0eb0bde",
"style": "STATIC",
"cgw_id": "5247ae10-demo-a8df-va86-dd36659a7f5d",
"peer_subnets": ["192.168.44.0/24"],
"tunnel_local_address": "169.254.56.225/30",
"tunnel_peer_address": "169.254.56.226/30",
"enable_nqa": false,
"ikepolicy": {
"ike_version": "v2",
"authentication_algorithm": "sha2-256",
"encryption_algorithm": "aes-128",
"dh_group": "group15",
"authentication_method": "pre-share",
"lifetime_seconds": 86400,
"local_id_type": "ip",
"local_id": "10.***.***.134",
"peer_id_type": "ip",
"peer_id": "88.***.***.164",
"dpd": {
"timeout": 15,
"interval": 30,
"msg": "seq-hash-notify"
}
},
"ipsecpolicy": {
"authentication_algorithm": "sha2-256",
"encryption_algorithm": "aes-128",
"pfs": "group15",
"transform_protocol": "esp",
"lifetime_seconds": 3600,
"encapsulation_mode": "tunnel"
},
"created_at": "2022-11-26T13:41:34.626Z",
"updated_at": "2022-11-26T13:41:34.626Z",
"enterprise_project_id": "0",
},
"request_id": "104c5608-b68b-462c-af17-ead2fb5ccee4"
}</pre>
</li></ul>
</li></ol>
</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="vpn_api_0039.html">Application Examples</a></div>
</div>
</div>