You need to enable JavaScript to run this app.
导航

为安全组添加入方向规则

最近更新时间2023.06.09 11:20:33

首次发布时间2023.06.09 11:20:33

本文介绍如何为安全组添加一条入方向规则。

示例代码

# Example Code generated by Beijing Volcanoengine Technology.
from __future__ import print_function
import volcenginesdkcore
import volcenginesdkvpc
from pprint import pprint
from volcenginesdkcore.rest import ApiException

if __name__ == '__main__':
    configuration = volcenginesdkcore.Configuration()
    # 设置您的ak
    configuration.ak = "AK"
    # 设置您的sk
    configuration.sk = "SK"
    # 设置您要访问的地域
    configuration.region = "cn-beijing"
    
    # 设置默认配置
    volcenginesdkcore.Configuration.set_default(configuration)

    # 使用全局默认配置
    api_instance = volcenginesdkvpc.VPCApi()

    # 为安全组添加一条入方向规则
    authorize_security_group_ingress_request = volcenginesdkvpc.AuthorizeSecurityGroupIngressRequest(
        cidr_ip="10.XX.XX.0/8", # 目的段网段
        policy="accept",        # 访问策略
        port_end=22,            # 端口范围结束值
        port_start=22,          # 端口范围开始值
        priority=1,             # 安全组规则的优先级  
        protocol="tcp",         # 传输层协议
        security_group_id="sg-bp67acfmxazb4p****", # 安全组的ID
    )

    # 发起请求并处理返回或异常
    try:
        resp = api_instance.authorize_security_group_ingress(authorize_security_group_ingress_request)
        pprint(resp)
    except ApiException as e:
        print("Exception when calling api: %s\n" % e)

相关文档