
# 查询安全组列表
#### 功能介绍
查询提交请求的租户有权限操作的所有安全组。单次查询最多返回2000条数据，超过2000后会返回分页标记。
#### 调试
您可以在[API Explorer](https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=VPC&version=v2&api=NeutronListSecurityGroups)中调试该接口。
#### URI
GET /v2.0/security-groups
分页查询样例：
```
GET https://{Endpoint}/v2.0/security-groups?limit=2&marker=0431c9c5-1660-42e0-8a00-134bec7f03e2&page_reverse=False
```
参数说明请参见[表1]。
 表1参数说明 
| 名称          | 是否必选 | 参数类型    | 说明                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|:---|
| id          | 否    | String  | 按照安全组对应的ID过滤查询                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| name        | 否    | String  | 按照安全组的名称过滤查询                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| description | 否    | String  | 按照安全组的描述过滤查询                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| tenant_id   | 否    | String  | 按照安全组所属的项目ID过滤查询                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| marker      | 否    | String  | 分页查询的起始资源ID，表示从指定资源的下一条记录开始查询。 marker需要和limit配合使用： - 若不传入marker和limit参数，查询结果返回第一页全部资源记录。  - 若不传入marker参数，limit为10，查询结果返回第1\~10条资源记录。  - 若marker为第10条记录的资源ID，limit为10，查询结果返回第11\~20条资源记录。  - 若marker为第10条记录的资源ID，不传入limit参数，查询结果返回第11\~2000条（limit默认值2000）资源记录。   |
| limit       | 否    | Integer | 分页查询每页返回的记录个数，取值范围为0\~2000，默认值2000。 limit需要和marker配合使用，详细规则请见marker的参数说明。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
   
#### 请求参数
无。
#### 请求示例
```
GET https://{Endpoint}/v2.0/security-groups?limit=1
```
#### 响应参数
表2响应参数 
| 参数名称                  | 类型                                                                                        | 说明                                                                                                                                        |
|:---|:---|:---|
| security_groups       | Array of [Security Group] objects      | security group对象列表。请参见[表3]                                                             |
| security_groups_links | Array of [SecurityGroupsLink] objects | 分页信息。 只有在使用limit过滤，并且资源个数超过limit或者资源个数超过2000时（limit默认值），该参数的rel和href取值才会显示为next和其对应的link。 |
   
 表3Security Group对象 
| 参数名称                 | 类型                                                                                        | 说明                                                                                  |
|:---|:---|:---|
| id                   | String                                                                                    | 安全组的id 使用说明：查询安全组列表非必选               |
| tenant_id            | String                                                                                    | 项目ID                                                                                |
| name                 | String                                                                                    | 安全组名称                                                                               |
| description          | String                                                                                    | 安全组描述                                                                               |
| security_group_rules | Array of [Security Group Rule] objects | security_group_rule列表，参见[表4]     |
| project_id           | String                                                                                    | 项目ID，请参见[获取项目ID](https://support.huaweicloud.com/api-vpc/vpc_api_0011.html)。        |
| created_at           | String                                                                                    | 资源创建时间，UTC时间 格式：yyyy-MM-ddTHH:mm:ss |
| updated_at           | String                                                                                    | 资源更新时间，UTC时间 格式：yyyy-MM-ddTHH:mm:ss |
   
 表4Security Group Rule对象 
| 参数名称                    | 类型      | 说明                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|
| id                      | String  | 安全组规则id 使用说明：查询安全组规则非必选                                                                                                                                                                                                                                                                                                                                                           |
| description             | String  | 安全组规则描述                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| security_group_id       | String  | 所属安全组id                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| remote_group_id         | String  | 所属安全组的对端id                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| direction               | String  | 规则方向                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| remote_ip_prefix        | String  | 对端ip网段                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| protocol                | String  | 协议类型或直接指定IP协议号                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| port_range_max          | Integer | 最大端口，当协议类型为ICMP时，该值表示ICMP的code                                                                                                                                                                                                                                                                                                                                                                                                                 |
| port_range_min          | Integer | 最小端口，当协议类型为ICMP时，该值表示ICMP的type。 protocol为tcp和udp时，port_range_max和port_range_min必须同时输入，且port_range_max应大于等于port_range_min。 protocol为icmp时，指定ICMP code（port_range_max）时，必须同时指定ICMP type（port_range_min）。                                                                                                              |
| ethertype               | String  | 网络类型 支持IPv4，IPv6                                                                                                                                                                                                                                                                                                                                                                   |
| tenant_id               | String  | 项目ID                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| remote_address_group_id | String  | - 功能说明：远端IP地址组ID。  - 约束：和remote_ip_prefix，remote_group_id功能互斥。   |
| project_id              | String  | 项目ID，请参见[获取项目ID](https://support.huaweicloud.com/api-vpc/vpc_api_0011.html)。                                                                                                                                                                                                                                                                                                                                                                   |
| created_at              | String  | 资源创建时间，UTC时间 格式：yyyy-MM-ddTHH:mm:ss                                                                                                                                                                                                                                                                                                                                              |
| updated_at              | String  | 资源更新时间，UTC时间 格式：yyyy-MM-ddTHH:mm:ss                                                                                                                                                                                                                                                                                                                                              |
   
 表5SecurityGroupsLink对象 
| 参数名称 | 类型     | 说明              |
|:---|:---|:---|
| href | String | API链接           |
| rel  | String | API链接与该API版本的关系 |
   
#### 响应示例
```
{
    "security_groups": [
        {
            "id": "0431c9c5-1660-42e0-8a00-134bec7f03e2",
            "name": "sg-ad3f",
            "description": "",
            "tenant_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
            "project_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
            "security_group_rules": [
                {
                    "id": "d90e55ba-23bd-4d97-b722-8cb6fb485d69",
                    "direction": "ingress",
                    "protocol": null,
                    "ethertype": "IPv4",
                    "description": null,
                    "remote_group_id": "0431c9c5-1660-42e0-8a00-134bec7f03e2",
                    "remote_ip_prefix": null,
                    "tenant_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
                    "port_range_max": null,
                    "port_range_min": null,
                    "security_group_id": "0431c9c5-1660-42e0-8a00-134bec7f03e2",
                    "remote_address_group_id": "0150a3a7-82ca-4569-865c-04e46e5e9249" 
                },
                {
                    "id": "aecff4d4-9ce9-489c-86a3-803aedec65f7",
                    "direction": "egress",
                    "protocol": null,
                    "ethertype": "IPv4",
                    "description": null,
                    "remote_group_id": null,
                    "remote_ip_prefix": null,
                    "tenant_id": "bbfe8c41dd034a07bebd592bf03b4b0c",
                    "port_range_max": null,
                    "port_range_min": null,
                    "security_group_id": "0431c9c5-1660-42e0-8a00-134bec7f03e2",
                    "remote_address_group_id": null
                }
            ],
            "created_at": "2018-09-12T08:24:14",
            "updated_at": "2018-09-12T08:24:14"
        }
    ],
    "security_groups_links": [
       {
            "rel": "next", 
            "href": "https://{Endpoint}/v2.0/security-groups?limit=1&marker=0431c9c5-1660-42e0-8a00-134bec7f03e2"
        }, 
       {    "rel": "previous", 
            "href": "https://{Endpoint}/v2.0/security-groups?limit=1&marker=0431c9c5-1660-42e0-8a00-134bec7f03e2&page_reverse=True"
        }
    ]
}
```
#### 状态码
请参见[状态码](https://support.huaweicloud.com/api-vpc/vpc_api_0002.html)。
#### 错误码
请参考[错误码](https://support.huaweicloud.com/api-vpc/vpc_api_0003.html)。
