更新时间:2024-03-28 GMT+08:00
分享

批量创建安全组规则

功能介绍

在特定安全组下批量创建安全组规则

URI

POST /v3/{project_id}/vpc/security-groups/{security_group_id}/security-group-rules/batch-create

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID

security_group_id

String

安全组ID

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

security_group_rules

Array of BatchCreateSecurityGroupRulesOption objects

待创建的安全组规则列表,上限200条规则。

ignore_duplicate

Boolean

创建时是否忽略重复的安全组规则 默认为false

缺省值:false

dry_run

Boolean

功能说明:是否只预检此次请求

取值范围:

-true:发送检查请求,不会创建安全组规则。检查项包括是否填写了必需参数、请求格式、权限校验。如果检查不通过,则返回对应错误。如果检查通过,则返回响应码202。

-false(默认值):发送正常请求,并直接创建安全组规则。

表3 BatchCreateSecurityGroupRulesOption

参数

是否必选

参数类型

描述

description

String

功能说明:安全组的描述信息

取值范围:0-255个字符,不能包含“<”和“>”

direction

String

功能说明:安全组规则的出入控制方向

取值范围:ingress 表示入方向;egress 表示出方向

ethertype

String

功能说明:IP地址协议类型

取值范围:IPv4,IPv6

约束:不填默认值为IPv4

protocol

String

功能说明:协议类型

取值范围:icmp、tcp、udp、icmpv6或IP协议号(0~255)

约束:为空表示支持所有协议。协议为icmpv6时,网络类型应该为IPv6;协议为icmp时,网络类型应该为IPv4

multiport

String

功能说明:端口取值范围

取值范围:支持单端口(80),连续端口(1-30)以及不连续端口(22,3389,80)

约束:端口值的范围1~65535

remote_ip_prefix

String

功能说明:远端IP地址,当direction是egress时为虚拟机访问端的地址,当direction是ingress时为访问虚拟机的地址

取值范围:IP地址,或者cidr格式

约束:

  • 与remote_group_id、remote_address_group_id互斥
  • 为空,表示没有限制远端IP地址,允许或拒绝所有远端地址的流量

remote_group_id

String

功能说明:远端安全组ID,表示该安全组内的流量允许或拒绝

取值范围:租户下存在的安全组ID

约束:与remote_ip_prefix,remote_address_group_id功能互斥

remote_address_group_id

String

功能说明:远端地址组ID

取值范围:租户下存在的地址组ID

约束:与remote_ip_prefix,remote_group_id功能互斥

action

String

功能说明:安全组规则生效策略

取值范围:allow 允许,deny 拒绝

约束:默认值为allow

priority

String

功能说明:规则在安全组中的优先级

取值范围:1~100,1代表最高优先级

约束:默认值为1

响应参数

状态码: 201

表4 响应Body参数

参数

参数类型

描述

security_group_rules

Array of SecurityGroupRule objects

批量创建安全组规则的响应体

request_id

String

请求ID

表5 SecurityGroupRule

参数

参数类型

描述

id

String

功能描述:安全组规则对应的唯一标识

取值范围:带“-”的标准UUID格式

description

String

功能说明:安全组的描述信息

取值范围:0-255个字符,不能包含“<”和“>”

security_group_id

String

功能说明:安全组规则所属的安全组ID

direction

String

功能说明:安全组规则的出入控制方向

取值范围:ingress 表示入方向;egress 表示出方向

protocol

String

功能说明:协议类型

取值范围:icmp、tcp、udp、icmpv6或IP协议号

约束:为空表示支持所有协议。协议为icmpv6时,网络类型应该为IPv6;协议为icmp时,网络类型应该为IPv4

ethertype

String

功能说明:IP地址协议类型

取值范围:IPv4,IPv6

约束:不填默认值为IPv4

缺省值:IPv4

multiport

String

功能说明:端口取值范围

取值范围:支持单端口(80),连续端口(1-30)以及不连续端口(22,3389,80)

action

String

功能说明:安全组规则生效策略

取值范围:allow 允许,deny 拒绝

约束:默认值为deny

priority

Integer

功能说明:优先级

取值范围:1~100,1代表最高优先级

remote_group_id

String

功能说明:远端安全组ID,表示该安全组内的流量允许或拒绝

取值范围:租户下存在的安全组ID

约束:与remote_ip_prefix,remote_address_group_id功能互斥

remote_ip_prefix

String

功能说明:远端IP地址,当direction是egress时为虚拟机访问端的地址,当direction是ingress时为访问虚拟机的地址

取值范围:IP地址,或者cidr格式

约束:与remote_group_id、remote_address_group_id互斥

remote_address_group_id

String

功能说明:远端地址组ID

取值范围:租户下存在的地址组ID

约束:与remote_ip_prefix,remote_group_id功能互斥

created_at

String

功能说明:安全组规则创建时间

取值范围:UTC时间格式:yyyy-MM-ddTHH:mm:ss

updated_at

String

功能说明:安全组规则更新时间

取值范围:UTC时间格式:yyyy-MM-ddTHH:mm:ss

project_id

String

功能说明:安全组规则所属项目ID

请求示例

在安全组15457509-18f9-4387-bae6-d4ed1898b301中创建规则,忽略重复规则,两条规则相同。

POST https://{Endpoint}/v3/{project_id}/vpc/security-groups/15457509-18f9-4387-bae6-d4ed1898b301/security-group-rules/batch-create

{
  "ignore_duplicate" : true,
  "security_group_rules" : [ {
    "direction" : "ingress",
    "description" : "",
    "protocol" : "tcp",
    "action" : "allow",
    "priority" : 1,
    "ethertype" : "IPv4",
    "multiport" : "22",
    "remote_ip_prefix" : "117.78.12.122/32"
  }, {
    "direction" : "ingress",
    "description" : "",
    "protocol" : "tcp",
    "action" : "allow",
    "priority" : 1,
    "ethertype" : "IPv4",
    "multiport" : "22",
    "remote_ip_prefix" : "117.78.12.122/32"
  } ]
}

响应示例

状态码: 201

Created

{
  "security_group_rules" : [ {
    "id" : "abef369b-d646-4b8a-9f44-fcd248a6c421",
    "project_id" : "5f6387106c2048b589b369d96c2f23a2",
    "security_group_id" : "15457509-18f9-4387-bae6-d4ed1898b301",
    "remote_group_id" : null,
    "direction" : "ingress",
    "protocol" : "tcp",
    "description" : "",
    "created_at" : "2023-04-28T04:08:52Z",
    "updated_at" : "2023-04-28T04:08:52Z",
    "ethertype" : "IPv4",
    "remote_ip_prefix" : "117.78.12.122/32",
    "multiport" : "22",
    "remote_address_group_id" : null,
    "action" : "allow",
    "priority" : 1
  } ],
  "request_id" : "f1ae2c6f9e94babf077cd3b3e1570c81"
}

状态码

状态码

描述

201

Created

错误码

请参见错误码

分享:

    相关文档

    相关产品