更新时间:2024-03-04 GMT+08:00
分享

查询所有实例列表

功能介绍

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

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

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

表2 Query参数

参数

是否必选

参数类型

描述

instance_id

String

实例ID。

include_failure

String

是否返回创建失败的实例数。 当参数值为“true”时,返回创建失败的实例数。参数值为“false”或者其他值,不返回创建失败的实例数。

include_delete

String

是否返回已删除的实例数。 当参数值为“true”时,返回已删除的实例数。参数值为“false”或者其他值,不返回已删除的实例数。

name

String

实例名称。

offset

Integer

偏移量,表示从此偏移量开始查询, offset大于等于0。

limit

Integer

每页显示条数,最小值为1,最大值为1000,若不设置该参数,则为10。

status

String

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

name_equal

String

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

默认为“false”,表示模糊匹配实例名称查询。若参数值为“true”表示按照实例名称进行精确匹配查询。

tags

String

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

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

ip

String

连接缓存实例的IP地址。

capacity

String

缓存实例的容量(G Byte)。

请求参数

响应参数

状态码: 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

VPC ID。

subnet_id

String

子网ID。

security_group_id

String

安全组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

缓存容量(G Byte)。

capacity_minor

String

小规格缓存实例(小于1G)的容量(G Byte)。

order_id

String

订单ID,仅在创建包周期实例时返回,按需实例时此值为null。

maintain_begin

String

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

maintain_end

String

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

engine

String

缓存引擎。

engine_version

String

缓存版本。

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或aarch64

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

错误信息。

最大长度:1024

error_code

String

错误码。

最大长度:9

error_ext_msg

String

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

最大长度:1024

状态码: 401

表8 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

最大长度:1024

error_code

String

错误码。

最大长度:9

error_ext_msg

String

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

最大长度:1024

状态码: 403

表9 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

最大长度:1024

error_code

String

错误码。

最大长度:9

error_ext_msg

String

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

最大长度:1024

状态码: 404

表10 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

最大长度:1024

error_code

String

错误码。

最大长度:9

error_ext_msg

String

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

最大长度:1024

状态码: 500

表11 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

最大长度:1024

error_code

String

错误码。

最大长度:9

error_ext_msg

String

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

最大长度:1024

请求示例

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
48
49
50
51
52
53
54
55
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");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        DcsClient client = DcsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListInstancesRequest request = new ListInstancesRequest();
        request.withInstanceId("<instance_id>");
        request.withIncludeFailure("<include_failure>");
        request.withIncludeDelete("<include_delete>");
        request.withName("<name>");
        request.withOffset(<offset>);
        request.withLimit(<limit>);
        request.withStatus("<status>");
        request.withNameEqual("<name_equal>");
        request.withTags("<tags>");
        request.withIp("<ip>");
        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
32
33
34
35
36
37
38
39
# coding: utf-8

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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = DcsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DcsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListInstancesRequest()
        request.instance_id = "<instance_id>"
        request.include_failure = "<include_failure>"
        request.include_delete = "<include_delete>"
        request.name = "<name>"
        request.offset = <offset>
        request.limit = <limit>
        request.status = "<status>"
        request.name_equal = "<name_equal>"
        request.tags = "<tags>"
        request.ip = "<ip>"
        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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := dcs.NewDcsClient(
        dcs.DcsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListInstancesRequest{}
	instanceIdRequest:= "<instance_id>"
	request.InstanceId = &instanceIdRequest
	includeFailureRequest:= "<include_failure>"
	request.IncludeFailure = &includeFailureRequest
	includeDeleteRequest:= "<include_delete>"
	request.IncludeDelete = &includeDeleteRequest
	nameRequest:= "<name>"
	request.Name = &nameRequest
	offsetRequest:= int32(<offset>)
	request.Offset = &offsetRequest
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	statusRequest:= "<status>"
	request.Status = &statusRequest
	nameEqualRequest:= "<name_equal>"
	request.NameEqual = &nameEqualRequest
	tagsRequest:= "<tags>"
	request.Tags = &tagsRequest
	ipRequest:= "<ip>"
	request.Ip = &ipRequest
	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

内部服务错误。

错误码

请参见错误码

分享:

    相关文档

    相关产品