查询VPC列表
功能介绍
当您的VPC创建成功后,您可以通过调用此接口查询所有VPC信息,包括VPC名称、ID、网段等。
接口约束
查询提交请求的租户有权限查看的所有vpc信息,单次查询最多返回2000条数据,超过2000后会返回分页标记。
调用方法
请参见如何调用API。
URI
GET /v3/{project_id}/vpc/vpcs
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
limit |
否 |
Integer |
|
marker |
否 |
String |
|
id |
否 |
Array of strings |
|
name |
否 |
Array of strings |
|
description |
否 |
Array of strings |
|
cidr |
否 |
Array of strings |
|
请求参数
无
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
request_id |
String |
|
vpcs |
Array of Vpc objects |
|
page_info |
PageInfo object |
|
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
|
name |
String |
|
description |
String |
|
cidr |
String |
|
extend_cidrs |
Array of strings |
|
status |
String |
|
project_id |
String |
|
enterprise_project_id |
String |
|
created_at |
String |
|
updated_at |
String |
|
cloud_resources |
Array of CloudResource objects |
|
tags |
Array of ResponseTag objects |
|
参数 |
参数类型 |
描述 |
---|---|---|
resource_type |
String |
|
resource_count |
Integer |
|
请求示例
-
查询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操作正常返回,更多状态码请参见状态码。
{ "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", "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", "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", "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代码示例如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := vpc.NewVpcClient( vpc.VpcClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListVpcsRequest{} response, err := client.ListVpcs(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
GET操作正常返回,更多状态码请参见状态码。 |
错误码
请参见错误码。