创建安全组
功能介绍
安全组是一个逻辑上的分组,为具有相同安全保护需求并相互信任的云服务器、云容器、云数据库等实例提供访问策略。安全组创建后,用户可以在安全组中定义各种访问规则,当实例加入该安全组后,即受到这些访问规则的保护。
接口约束
新建的安全组,默认只允许安全组内的实例互相访问。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/vpc/security-groups
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| project_id | 是 | String |
|
请求参数
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| dry_run | 否 | Boolean |
|
| security_group | 是 | CreateSecurityGroupOption object |
|
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| name | 是 | String |
|
| description | 否 | String |
|
| tags | 否 | Array of RequestTag objects |
|
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| key | 是 | String | 参数解释: 标签键。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
| value | 是 | String | 参数解释: 标签值。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
响应参数
状态码:201
| 参数 | 参数类型 | 描述 |
|---|---|---|
| request_id | String |
|
| security_group | SecurityGroupInfo object |
|
| 参数 | 参数类型 | 描述 |
|---|---|---|
| id | String |
|
| name | String |
|
| description | String |
|
| project_id | String |
|
| created_at | String |
|
| updated_at | String |
|
| tags | Array of ResponseTag objects |
|
| security_group_rules | Array of SecurityGroupRule objects |
|
| 参数 | 参数类型 | 描述 |
|---|---|---|
| key | String | 参数解释: 标签键。 取值范围:
|
| value | String | 参数解释: 标签值。 取值范围:
|
| 参数 | 参数类型 | 描述 |
|---|---|---|
| id | String |
|
| description | String |
|
| security_group_id | String |
|
| direction | String |
|
| protocol | String |
|
| ethertype | String |
|
| multiport | String |
|
| action | String |
|
| priority | Integer |
|
| remote_group_id | String |
|
| remote_ip_prefix | String |
|
| created_at | String |
|
| updated_at | String |
|
| project_id | String |
|
状态码:202
| 参数 | 参数类型 | 描述 |
|---|---|---|
| request_id | String |
|
| error_msg | String |
|
| error_code | String |
|
请求示例
-
创建安全组,指定名称为security_group_1,描述为security group description,指定预检该请求。
POST https://{Endpoint}/v3/{project_id}/vpc/security-groups { "security_group" : { "name" : "security_group_1", "description" : "security group description" }, "dry_run" : true } -
创建安全组,指定名称为security_group_1,描述为security group description。
POST https://{Endpoint}/v3/{project_id}/vpc/security-groups { "security_group" : { "name" : "security_group_1", "description" : "security group description" } }
响应示例
状态码:201
POST操作正常返回,更多状态码请参见状态码。
{
"security_group" : {
"id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
"name" : "security_group_1",
"project_id" : "060576782980d5762f9ec014dd2f1148",
"description" : "security group description",
"enterprise_project_id" : "0",
"tags" : [ ],
"security_group_rules" : [ {
"id" : "f11a3824-ac19-4fad-b4f1-c5f4a6dd0a80",
"project_id" : "060576782980d5762f9ec014dd2f1148",
"security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
"remote_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
"direction" : "ingress",
"protocol" : null,
"description" : "",
"created_at" : "2020-07-09T05:56:27Z",
"updated_at" : "2020-07-09T05:56:27Z",
"ethertype" : "IPv6",
"remote_ip_prefix" : null,
"multiport" : null,
"remote_address_group_id" : null,
"action" : "allow",
"priority" : 100
}, {
"id" : "3d6480e8-9ea4-46dc-bb1b-8db190cd5677",
"project_id" : "060576782980d5762f9ec014dd2f1148",
"security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
"remote_group_id" : null,
"direction" : "egress",
"protocol" : null,
"description" : "",
"created_at" : "2020-07-09T05:56:27Z",
"updated_at" : "2020-07-09T05:56:27Z",
"ethertype" : "IPv6",
"remote_ip_prefix" : null,
"multiport" : null,
"remote_address_group_id" : null,
"action" : "allow",
"priority" : 100
}, {
"id" : "9581f18c-1fdd-43da-ace9-7758a56ef28a",
"project_id" : "060576782980d5762f9ec014dd2f1148",
"security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
"remote_group_id" : null,
"direction" : "egress",
"protocol" : null,
"description" : "",
"created_at" : "2020-07-09T05:56:27Z",
"updated_at" : "2020-07-09T05:56:27Z",
"ethertype" : "IPv4",
"remote_ip_prefix" : null,
"multiport" : null,
"remote_address_group_id" : null,
"action" : "allow",
"priority" : 100
}, {
"id" : "a3ba270e-e58b-432d-a912-aeb7eace9fb8",
"project_id" : "060576782980d5762f9ec014dd2f1148",
"security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
"remote_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
"direction" : "ingress",
"protocol" : null,
"description" : "",
"created_at" : "2020-07-09T05:56:27Z",
"updated_at" : "2020-07-09T05:56:27Z",
"ethertype" : "IPv4",
"remote_ip_prefix" : null,
"multiport" : null,
"remote_address_group_id" : null,
"action" : "allow",
"priority" : 100
} ],
"created_at" : "2020-07-09T05:56:27Z",
"updated_at" : "2020-07-09T05:56:27Z"
},
"request_id" : "a8cf4f79ca3c22ca685e7e8872e8c20b"
} 状态码:202
API V3的指定预检请求正常返回,更多状态码请参见状态码。
{
"error_msg" : "Request validation has been passed with dry run...",
"error_code" : "SYS.0202",
"request_id" : "cfd81aea3f59eac7128dba4b36d516c8"
} 错误码
请参见错误码。