企业路由器 ER-创建静态路由:Python

时间:2023-12-06 15:04:42

Python

在企业路由器的路由表中创建静态路由,该路由不是黑洞路由,目的地址为192.168.0.0/16,下一跳为指定连接

 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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdker.v3.region.er_region import ErRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdker.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 = ErClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(ErRegion.value_of("cn-north-4")) \
        .build()

    try:
        request = CreateStaticRouteRequest()
        routebody = CreateRoute(
            destination="192.168.0.0/16",
            attachment_id="b70aee08-c671-4cad-9fd5-7381d163bcc8",
            is_blackhole=False
        )
        request.body = CreateRouteRequestBody(
            route=routebody
        )
        response = client.create_static_route(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
support.huaweicloud.com/api-er/CreateStaticRoute.html