更新时间:2025-01-14 GMT+08:00

查询所有实例列表

功能介绍

查询租户的缓存实例列表,支持按照条件查询。

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

项目ID。获取方法请参见获取项目ID

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

表2 Query参数

参数

是否必选

参数类型

描述

instance_id

String

参数解释

实例ID。可通过DCS控制台进入实例详情界面查看。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

include_failure

String

参数解释

是否返回创建失败的实例数。

约束限制

不涉及。

取值范围

  • true:返回创建失败的实例数。

  • false:不返回创建失败的实例数。

默认取值

false

include_delete

String

参数解释

是否返回已删除的实例数。

约束限制

不涉及。

取值范围

  • true:返回已删除的实例数。

  • false:不返回已删除的实例数。

默认取值

false

name

String

参数解释

实例名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

offset

Integer

参数解释

偏移量,表示从此偏移量开始查询。

约束限制

不涉及。

取值范围

大于等于0。

默认取值

0

limit

Integer

参数解释

每页显示的条目数量。

约束限制

不涉及。

取值范围

1-1000

默认取值

10

status

String

参数解释

实例状态。

约束限制

不涉及。

取值范围

详细状态说明见缓存实例状态说明

默认取值

不涉及。

name_equal

String

参数解释

是否按照实例名称进行精确匹配查询。

约束限制

不涉及。

取值范围

  • true:表示按照实例名称进行精确匹配查询。

  • false:表示模糊匹配实例名称查询。

默认取值

false

tags

String

参数解释

根据实例标签键值对进行查询。{key}表示标签键,{value}表示标签值。

约束限制

如果同时使用多个标签键值对进行查询,中间使用逗号分隔开,表示查询同时包含指定标签键值对的实例。

取值范围

不涉及。

默认取值

不涉及。

ip

String

参数解释

连接缓存实例的IP地址,如192.168.7.146。可以通过DCS控制台进入实例详情界面查看。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

capacity

String

参数解释

缓存实例的容量,单位:GB。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

请求参数

响应参数

状态码: 200

表3 响应Body参数

参数

参数类型

描述

instance_num

Integer

参数解释

实例个数。

取值范围

不涉及。

instances

Array of InstanceListInfo objects

参数解释

实例的详情数组。

取值范围

不涉及。

表4 InstanceListInfo

参数

参数类型

描述

publicip_id

String

参数解释

Redis缓存实例绑定的弹性IP地址的ID。

如果未开启公网访问功能,该字段值为null。

取值范围

不涉及。

vpc_name

String

参数解释

VPC的名称。

取值范围

不涉及。

charging_mode

Integer

参数解释

计费模式。

取值范围

  • 0:按需计费。

  • 1:包年/包月计费。

vpc_id

String

参数解释

Redis缓存实例所在的虚拟私有云ID。

取值范围

不涉及。

subnet_id

String

参数解释

Redis缓存实例绑定的子网ID。

取值范围

不涉及。

security_group_id

String

参数解释

Redis缓存实例绑定的安全组ID。

取值范围

不涉及。

created_at

String

参数解释

实例的创建时间。格式为:2017-03-31T12:24:46.297Z。

取值范围

不涉及。

updated_at

String

参数解释

实例的更新时间。格式为:2017-03-31T19:24:46.297Z。

取值范围

不涉及。

enable_ssl

Boolean

参数解释

Redis缓存实例开启公网访问功能时,是否选择选择开启SSL。

取值范围

  • true:开启

  • false:不开启

max_memory

Integer

参数解释

实例的总内存大小,单位:MB。

取值范围

不涉及。

used_memory

Integer

参数解释

实例已使用的内存大小,单位:MB。

取值范围

不涉及。

publicip_address

String

参数解释

Redis缓存实例绑定的弹性IP地址。

如果未开启公网访问功能,该字段值为null。

取值范围

不涉及。

capacity

Integer

参数解释

实例的缓存容量规格大小,单位:GB。

取值范围

不涉及。

capacity_minor

String

参数解释

小于1GB规格缓存实例的容量,单位:GB。

取值范围

不涉及。

order_id

String

参数解释

订单ID,按需实例时此值为null。

取值范围

不涉及。

maintain_begin

String

参数解释

维护时间窗开始时间,为UTC时间,格式为HH:mm:ss。

取值范围

不涉及。

maintain_end

String

参数解释

维护时间窗结束时间,为UTC时间,格式为HH:mm:ss。

取值范围

不涉及。

engine

String

参数解释

缓存引擎。

取值范围

  • Redis

  • Memcached

engine_version

String

参数解释

缓存版本。

取值范围

Redis缓存引擎的取值范围如下:

  • 3.0

  • 4.0

  • 5.0

  • 6.0

当缓存引擎为Memcached时,取值为空。

service_upgrade

Boolean

参数解释

实例是否存在升级任务。

取值范围

  • true:存在

  • false:不存在

no_password_access

String

参数解释

是否允许免密码访问缓存实例。

取值范围

  • true:该实例无需密码即可访问。

  • false:该实例必须通过密码认证才能访问。

service_task_id

String

参数解释

升级任务的ID。

  • 当service_upgrade为true时,为升级任务的ID。

  • 当service_upgrade为false时,该参数为空。

取值范围

不涉及。

ip

String

参数解释

连接缓存实例的IP地址。如果是集群实例,返回多个IP地址,使用逗号分隔。如:192.168.0.1,192.168.0.2。

取值范围

不涉及。

access_user

String

参数解释

通过密码认证访问缓存实例的认证用户名。

取值范围

不涉及。

instance_id

String

参数解释

实例ID。

取值范围

不涉及。

enable_publicip

Boolean

参数解释

Redis 3.0缓存实例是否开启公网访问功能。

取值范围

  • true:开启

  • false:不开启

port

Integer

参数解释

连接缓存实例的端口号。

取值范围

不涉及。

user_id

String

参数解释

实例所在的用户ID。

取值范围

不涉及。

user_name

String

参数解释

实例所在的用户名。

取值范围

不涉及。

domain_name

String

参数解释

实例的域名。

取值范围

不涉及。

readonly_domain_name

String

参数解释

实例的只读域名,只有主备实例有该字段。

取值范围

不涉及。

name

String

参数解释

实例名称。

取值范围

不涉及。

spec_code

String

参数解释

产品规格编码。

取值范围

不涉及。

status

String

参数解释

实例状态。

取值范围

详细状态说明见缓存实例状态说明

tags

Array of ResourceTag objects

参数解释

实例标签键值。

取值范围

不涉及。

enterprise_project_id

String

参数解释

企业项目ID。

取值范围

不涉及。

description

String

参数解释

实例描述信息。

取值范围

不涉及。

cpu_type

String

参数解释

实例CPU类型。

取值范围

  • x86_64:x86计算

  • aarch64:Arm计算

az_codes

Array of strings

参数解释

有资源的可用区编码。

取值范围

不涉及。

features

Features object

参数解释

实例支持特性。

取值范围

不涉及。

sub_status

String

参数解释

实例子状态。

取值范围

不涉及。

表5 ResourceTag

参数

参数类型

描述

key

String

参数解释

标签键。

  • 不能为空。

  • 对于同一资源键值唯一。

  • 长度不超过36个字符。

  • 标签的键必须唯一且输入不能为空。

取值范围

不涉及。

value

String

参数解释

标签值。

  • action为create时必选。action为delete时非必选。

  • 长度不超过43个字符。

取值范围

不涉及。

表6 Features

参数

参数类型

描述

support_acl

Boolean

参数解释

实例是否支持ACL。

取值范围

  • true:是

  • false:否

support_transparent_client_ip

Boolean

参数解释

实例是否支持客户端IP透传。

取值范围

  • true:是

  • false:否

support_ssl

Boolean

参数解释

实例是否支持SSL。

取值范围

  • true:是

  • false:否

support_audit_log

Boolean

参数解释

实例是否支持审计日志。

取值范围

  • true:是

  • false:否

状态码: 400

表7 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 401

表8 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 403

表9 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 404

表10 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码: 500

表11 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

请求示例

GET https://{dcs_endpoint}/v2/{project_id}/instances?offset=0&limit=10&name={name}&status={status}&id={id}&include_failure=true&include_delete=true&name_equal=false

响应示例

状态码: 400

非法请求。

{
  "error_code" : "DCS.4800",
  "error_msg" : "Invalid offset in the request."
}

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.dcs.v2.region.DcsRegion;
import com.huaweicloud.sdk.dcs.v2.*;
import com.huaweicloud.sdk.dcs.v2.model.*;


public class ListInstancesSolution {

    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);

        DcsClient client = DcsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListInstancesRequest request = new ListInstancesRequest();
        try {
            ListInstancesResponse response = client.listInstances(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 huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdcs.v2 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 = DcsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DcsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListInstancesRequest()
        response = client.list_instances(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"
    dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/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 := dcs.NewDcsClient(
        dcs.DcsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListInstancesRequest{}
	response, err := client.ListInstances(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

查询所有实例列表成功。

400

非法请求。

401

认证信息非法。

403

请求被拒绝访问。

404

所请求的资源不存在。

500

内部服务错误。

错误码

请参见错误码