
# 查询VPC列表 - ListVpcs
#### 功能介绍
当您的VPC创建成功后，您可以通过调用此接口查询所有VPC信息，包括VPC名称、ID、网段等。
#### 接口约束
查询提交请求的租户有权限查看的所有vpc信息，单次查询最多返回2000条数据，超过2000后会返回分页标记。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-vpc/vpc_api00_0007.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-vpc/vpc_permission_0000.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项           | 访问级别 | 资源类型（\*为必须） | 条件键                   | 别名 | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | vpc:vpcs:list | List | vpc \*      | -                     | -  | -      |
  | vpc:vpcs:list | List | -           | g:EnterpriseProjectId | -  | -      |
     
  
 
#### URI
GET /v3/{project_id}/vpc/vpcs
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                            |
|:---|:---|:---|:---|
| project_id | 是    | String | - 参数解释：VPC所属的项目ID。获取方式请参见[获取项目ID](https://support.huaweicloud.com/api-vpc/vpc_api_0011.html)。   - 取值范围：无    |
   
表2Query参数 
| 参数          | 是否必选 | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| limit       | 否    | Integer          | - 参数解释：每页返回的个数。   - 取值范围：0-2000。                  |
| marker      | 否    | String           | - 参数解释：分页查询起始的资源ID，为空时查询第一页。   - 取值范围：VPC资源ID。    |
| id          | 否    | Array of strings | - 参数解释：VPC资源ID，可以使用该字段过滤VPC。   - 取值范围：无           |
| name        | 否    | Array of strings | - 参数解释：VPC的名称信息，可以使用该字段过滤VPC。   - 取值范围：无          |
| description | 否    | Array of strings | - 参数解释：VPC的描述信息，可以使用该字段过滤VPC。   - 取值范围：无          |
| cidr        | 否    | Array of strings | - 参数解释：VPC的网段信息，可以使用该字段过滤VPC。   - 取值范围：无          |
   
#### 请求参数
无
#### 响应参数
**状态码：200**
表3响应Body参数 
| 参数         | 参数类型                                                  | 描述                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|
| request_id | String                                                | - 参数解释：请求ID。   - 取值范围：无          |
| vpcs       | Array of [Vpc] objects | - 参数解释：查询VPC列表响应体。   - 取值范围：无    |
| page_info  | [PageInfo] object | - 参数解释：分页信息。   - 取值范围：无          |
   
 表4Vpc 
| 参数                                   | 参数类型                                                                      | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|
| id                                   | String                                                                    | - 参数解释：VPC资源ID。VPC创建成功后，会生成一个VPC ID，是VPC对应的唯一标识。   - 取值范围：带"-"的UUID格式。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| name                                 | String                                                                    | - 参数解释：VPC的名称。   - 取值范围：0-64个字符，支持数字、字母、中文、_(下划线)、-（中划线）、.（点）。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| description                          | String                                                                    | - 参数解释：VPC的描述信息。   - 取值范围：0-255个字符，不能包含"\<"和"\>"。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| cidr                                 | String                                                                    | - 参数解释：VPC下可用子网的范围。   - 取值范围： - 10.0.0.0/8-24：IP地址范围为10.0.0.0-10.255.255.255，掩码范围为8\~24。   - 172.16.0.0/12-24：IP地址范围为172.16.0.0-172.31.255.255，掩码范围为12\~24。   - 192.168.0.0/16-24：IP地址范围为192.168.0.0-192.168.255.255，掩码范围为16\~24。   - 除上述地址外，取值还可以是任何可公共路由的IP地址，但不能包含以下系统预留地址和公网保留地址： - 100.64.0.0/10   - 214.0.0.0/7   - 198.18.0.0/15   - 169.254.0.0/16   - 0.0.0.0/8   - 127.0.0.0/8   - 240.0.0.0/4     - 不指定cidr时，默认值为""。      |
| extend_cidrs                         | Array of strings                                                          | - 参数解释：VPC的扩展网段。   - 取值范围：不能包含以下网段。 - 10.0.0.0/8：IP地址范围为10.0.0.0-10.255.255.255。   - 172.16.0.0/12：IP地址范围为172.16.0.0-172.31.255.255。   - 192.168.0.0/16：IP地址范围为192.168.0.0-192.168.255.255。   - 172.31.0.0/16：IP地址范围为172.31.0.0-172.31.255.255。   - 100.64.0.0/10：IP地址范围为100.64.0.0-100.127.255.255。   - 214.0.0.0/7：IP地址范围为214.0.0.0-215.255.255.255。   - 198.18.0.0/15：IP地址范围为198.18.0.0-198.19.255.255。   - 169.254.0.0/16：IP地址范围为169.254.0.0-169.254.255.255。   - 0.0.0.0/8：IP地址范围为0.0.0.0-0.255.255.255。   - 127.0.0.0/8：IP地址范围为127.0.0.0-127.255.255.255。   - 240.0.0.0/4：IP地址范围为240.0.0.0-255.255.255.255。                |
| status                               | String                                                                    | - 参数解释：VPC对应的状态。   - 取值范围： - PENDING：创建中。   - ACTIVE：创建成功。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| project_id                           | String                                                                    | - 参数解释：VPC所属的项目ID。   - 取值范围：无                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| enterprise_project_id                | String                                                                    | - 参数解释：VPC所属的企业项目ID。   - 取值范围：最大长度36字节，带"-"连字符的UUID格式，或者是字符串"0"。"0"表示默认企业项目。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| created_at                           | String                                                                    | - 参数解释：VPC创建时间。   - 取值范围：UTC时间格式，yyyy-MM-ddTHH:mm:ssZ。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| updated_at                           | String                                                                    | - 参数解释：VPC更新时间。   - 取值范围：UTC时间格式，yyyy-MM-ddTHH:mm:ssZ。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| cloud_resources                      | Array of [CloudResource] objects | - 参数解释：VPC关联资源类型和数量。例如子网、路由表等云资源。   - 取值范围：无                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| tags                                 | Array of [ResponseTag] objects     | - 参数解释：VPC的标签信息，包括标签键和标签值，可用来分类和标识资源。详情请参见Tag对象。   - 取值范围：无                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| block_service_endpoint_states        | String                                                                    | - 参数解释：默认情况下，VPC中的资源可以通过内网访问服务终结点。开启该项后，VPC将无法通过内网访问服务终结点，请谨慎操作。无法访问以下云服务：容器镜像服务SWR、云日志服务LTS、企业主机安全HSS、应用运维管理AOM、应用性能管理APM、对象存储服务OBS、API网关APIG。   - 取值范围： - off：表示禁用。   - on：表示开启。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| enable_network_address_usage_metrics | Boolean                                                                   | - 参数解释：是否开启VPC内所有子网的IPv4地址使用量指标监控。   - 取值范围： - true：表示开启。   - false：表示不开启。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
   
 表5CloudResource 
| 参数             | 参数类型    | 描述                                                                                                                                                                                                                                                                                                           |
|:---|:---|:---|
| resource_type  | String  | - 参数解释：资源类型。   - 取值范围：无    |
| resource_count | Integer | - 参数解释：资源数量。   - 取值范围：无    |
   
 表6ResponseTag 
| 参数    | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|:---|:---|:---|
| key   | String | **参数解释**： 标签键。 **取值范围**： - 最大长度128个unicode字符， key不能为空。   - 同一资源的key不能重复。   - 可以包含的字符范围： - 英文字母   - 数字   - 特殊字符：下划线（_）、点（.）、冒号（:）、加号（+）、中划线（-）、等号（=）   - 中文字符      |
| value | String | **参数解释**： 标签值。 **取值范围**： - 每个值最大长度255个unicode字符，value可以为空。   - 可以包含的字符范围： - 英文字母   - 数字   - 特殊字符：下划线（_）、点（.）、冒号（:）、加号（+）、中划线（-）、等号（=）   - 中文字符                                                                                                                                            |
   
 表7PageInfo 
| 参数              | 参数类型    | 描述                                                                                                                                                             |
|:---|:---|:---|
| previous_marker | String  | **参数解释**： 当前页的第一条记录。 **取值范围**： 不涉及。                      |
| current_count   | Integer | **参数解释**： 当前页的资源总数。 **取值范围**： 不涉及。                       |
| next_marker     | String  | **参数解释**： 当前页的最后一条记录，最后一页时无next_marker字段。 **取值范围**： 不涉及。 |
   
#### 请求示例
- 查询VPC列表。
  ```
  GET https://{Endpoint}/v3/{project_id}/vpc/vpcs
  ```
  
- 使用ID过滤查询VPC列表。
  ```
  GET https://{Endpoint}/v3/{project_id}/vpc/vpcs?id=01ab4be1-4447-45fb-94be-3ee787ed4ebe&id=02cd5ef2-4447-36fb-75be-3ee787ed6adf
  ```
  
- 使用name过滤查询VPC列表。
  ```
  GET https://{Endpoint}/v3/{project_id}/vpc/vpcs?name=vpc-test
  ```
  
- 分页查询VPC列表。
  ```
  GET https://{Endpoint}/v3/{project_id}/vpc/vpcs?limit=2&marker=01ab4be1-4447-45fb-94be-3ee787ed4ebe
  ```
  
 
#### 响应示例
**状态码：200**
GET操作正常返回，更多状态码请参见[状态码](https://support.huaweicloud.com/api-vpc/vpc_api_0002.html)。
-
  ```
  {
    "request_id" : "9c1838ba498249547be43dd618b58d27",
    "vpcs" : [ {
      "id" : "01da5a65-0bb9-4638-8ab7-74c64e24a9a7",
      "name" : "API-PERF-TEST-14bd44c121",
      "description" : "",
      "cidr" : "192.168.0.0/16",
      "extend_cidrs" : [ ],
      "status" : "ACTIVE",
      "project_id" : "087679f0aa80d32a2f4ec0172f5e902b",
      "enterprise_project_id" : "0",
      "tags" : [ ],
      "created_at" : "2020-06-16T02:32:18Z",
      "updated_at" : "2020-06-16T02:32:18Z",
      "enable_network_address_usage_metrics" : false,
      "cloud_resources" : [ {
        "resource_type" : "routetable",
        "resource_count" : 1
      }, {
        "resource_type" : "virsubnet",
        "resource_count" : 0
      } ]
    }, {
      "id" : "43fd79b0-f7d7-4e9b-828b-2d4d7bfae428",
      "name" : "API-PERF-TEST_m2n33",
      "description" : "",
      "cidr" : "192.168.0.0/16",
      "extend_cidrs" : [ ],
      "status" : "ACTIVE",
      "project_id" : "087679f0aa80d32a2f4ec0172f5e902b",
      "enterprise_project_id" : "0",
      "tags" : [ ],
      "created_at" : "2020-06-15T06:29:40Z",
      "updated_at" : "2020-06-15T06:29:41Z",
      "enable_network_address_usage_metrics" : false,
      "cloud_resources" : [ {
        "resource_type" : "routetable",
        "resource_count" : 1
      }, {
        "resource_type" : "virsubnet",
        "resource_count" : 1
      } ]
    }, {
      "id" : "5ed053ba-b46c-4dce-a1ae-e9d8a7015f21",
      "name" : "API-PERF-TEST-c34b1c4b12",
      "description" : "",
      "cidr" : "192.168.0.0/16",
      "extend_cidrs" : [ ],
      "status" : "ACTIVE",
      "project_id" : "087679f0aa80d32a2f4ec0172f5e902b",
      "enterprise_project_id" : "0",
      "tags" : [ ],
      "created_at" : "2020-06-16T02:32:33Z",
      "updated_at" : "2020-06-16T02:32:33Z",
      "enable_network_address_usage_metrics" : false,
      "cloud_resources" : [ {
        "resource_type" : "routetable",
        "resource_count" : 1
      }, {
        "resource_type" : "virsubnet",
        "resource_count" : 0
      } ]
    } ],
    "page_info" : {
      "previous_marker" : "01da5a65-0bb9-4638-8ab7-74c64e24a9a7",
      "current_count" : 3
    }
  }
  ```
  
 
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  package com.huaweicloud.sdk.test;
  import com.huaweicloud.sdk.core.auth.ICredential;
  import com.huaweicloud.sdk.core.auth.BasicCredentials;
  import com.huaweicloud.sdk.core.exception.ConnectionException;
  import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
  import com.huaweicloud.sdk.core.exception.ServiceResponseException;
  import com.huaweicloud.sdk.vpc.v3.region.VpcRegion;
  import com.huaweicloud.sdk.vpc.v3.*;
  import com.huaweicloud.sdk.vpc.v3.model.*;
  public class ListVpcsSolution {
      public static void main(String[] args) {
          // 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
          String ak = System.getenv("CLOUD_SDK_AK");
          String sk = System.getenv("CLOUD_SDK_SK");
          String projectId = "{project_id}";
          ICredential auth = new BasicCredentials()
                  .withProjectId(projectId)
                  .withAk(ak)
                  .withSk(sk);
          VpcClient client = VpcClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(VpcRegion.valueOf("<YOUR REGION>"))
                  .build();
          ListVpcsRequest request = new ListVpcsRequest();
          try {
              ListVpcsResponse response = client.listVpcs(request);
              System.out.println(response.toString());
          } catch (ConnectionException e) {
              e.printStackTrace();
          } catch (RequestTimeoutException e) {
              e.printStackTrace();
          } catch (ServiceResponseException e) {
              e.printStackTrace();
              System.out.println(e.getHttpStatusCode());
              System.out.println(e.getRequestId());
              System.out.println(e.getErrorCode());
              System.out.println(e.getErrorMsg());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkvpc.v3.region.vpc_region import VpcRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkvpc.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.environ["CLOUD_SDK_AK"]
      sk = os.environ["CLOUD_SDK_SK"]
      projectId = "{project_id}"
      credentials = BasicCredentials(ak, sk, projectId)
      client = VpcClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(VpcRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ListVpcsRequest()
          response = client.list_vpcs(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      vpc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3/region"
  )
  func 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")
      projectId := "{project_id}"
      auth, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := vpc.VpcClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := vpc.NewVpcClient(hcClient)
      request := &model.ListVpcsRequest{}
  response, err := client.ListVpcs(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/VPC/sdk?api=ListVpcs&version=v3)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                                                                                  |
|:---|:---|
| 200 | GET操作正常返回，更多状态码请参见[状态码](https://support.huaweicloud.com/api-vpc/vpc_api_0002.html)。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-vpc/vpc_api_0003.html)。
