文档首页> 云硬盘 EVS> API参考> API> 云硬盘标签管理> 通过标签查询云硬盘资源实例详情
更新时间:2024-02-27 GMT+08:00

通过标签查询云硬盘资源实例详情

功能介绍

通过标签查询云硬盘资源实例详情。

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/cloudvolumes/resource_instances/action

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

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

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

表3 请求Body参数

参数

是否必选

参数类型

描述

action

String

操作标识。

根据标签查询云硬盘实例详情时使用“filter”。

缺省值:filter

枚举值:

  • filter

limit

Integer

查询记录数。最小值1,最大值1000,默认为1000。返回的结果中记录数不超过limit值

最小值:1

最大值:1000

缺省值:1000

matches

Array of Match objects

资源本身支持的查询条件。标签列表中的标签key值不允许重复。

offset

Integer

索引位置。最小值0,默认为0。返回的结果中第一条记录为符合查询条件的第“offset值+1”条记录。与limit配合使用,假如共有30个云硬盘,设置offset为11,limit为10,即为从第12个云硬盘开始查询,一次最多可读取10个云硬盘。

缺省值:0

tags

Array of TagsForListVolumes objects

标签的键值对。标签列表中最多包含10个key 。标签列表中的标签key值不允许重复。标签列表中多个key之间是“与”的关系,云硬盘必须满足请求中所有key才会匹配出来。

表4 Match

参数

是否必选

参数类型

描述

key

String

键。取值范围如下: resource_name:资源名称。 service_type:服务类型。

枚举值:

  • resource_name

  • service_type

value

String

值。最大长度255个字符。 key为“resource_name”时,value为模糊匹配。

表5 TagsForListVolumes

参数

是否必选

参数类型

描述

key

String

标签键。

values

Array of strings

标签值。

标签列表中最多包含10个value。

标签列表中的标签value值不允许重复。

标签列表如果为空列表,表示匹配任意值。标签列表中多个value之间是“或”的关系,在key已经满足要求的前提下,云硬盘满足请求中的某个value就会匹配出来。

响应参数

状态码: 200

表6 响应Body参数

参数

参数类型

描述

total_count

Integer

符合查询条件的云硬盘资源个数

resources

Array of Resource objects

符合查询条件的资源列表

表7 Resource

参数

参数类型

描述

resource_id

String

资源ID。

resource_name

String

资源名称。

resource_detail

VolumeDetailForTag object

资源详情。

tags

Array of Map<String,String> objects

标签列表。

表8 VolumeDetailForTag

参数

参数类型

描述

id

String

云硬盘的ID。

links

Array of Link objects

云硬盘URI自描述信息。

name

String

云硬盘名称。

status

String

云硬盘状态,请参见云硬盘状态。。

attachments

Array of Attachment objects

云硬盘的挂载信息。

availability_zone

String

云硬盘所属的AZ信息。

os-vol-host-attr:host

String

预留属性。

source_volid

String

源云硬盘ID,如果是从源云硬盘创建,则有值。

当前云硬盘服务不支持该字段。

snapshot_id

String

快照ID,如果是从快照创建,则有值。

description

String

云硬盘描述。

created_at

String

云硬盘创建时间。 时间格式:UTC YYYY-MM-DDTHH:MM:SS.XXXXXX

os-vol-tenant-attr:tenant_id

String

云硬盘所属的租户ID。租户ID就是项目ID。

volume_image_metadata

Map<String,Object>

云硬盘镜像的元数据。

说明:

关于“volume_image_metadata”字段的详细说明,具体请参见查询镜像详情

volume_type

String

云硬盘类型。 目前支持“SSD”,“SAS”和“SATA”三种。

  • “SSD”为超高IO云硬盘

  • “SAS”为高IO云硬盘

  • “SATA”为普通IO云硬盘

size

Integer

云硬盘大小,单位为GiB。

consistencygroup_id

String

预留属性。

bootable

String

是否为启动云硬盘。 true:表示为启动云硬盘。 false:表示为非启动云硬盘。

metadata

VolumeMetadata object

云硬盘的元数据。

updated_at

String

云硬盘更新时间。 时间格式:UTC YYYY-MM-DDTHH:MM:SS.XXXXXX

encrypted

Boolean

当前云硬盘服务不支持该字段。

replication_status

String

预留属性。

os-volume-replication:extended_status

String

预留属性。

os-vol-mig-status-attr:migstat

String

预留属性。

os-vol-mig-status-attr:name_id

String

预留属性。

shareable

Boolean

是否为共享云硬盘。true为共享盘,false为普通云硬盘。 该字段已经废弃,请使用multiattach。

user_id

String

预留属性。

service_type

String

服务类型,结果为EVS、DSS、DESS。

multiattach

Boolean

是否为共享云硬盘。

dedicated_storage_id

String

云硬盘所属的专属存储池ID。

dedicated_storage_name

String

云硬盘所属的专属存储池的名称。

tags

Map<String,String>

云硬盘的标签。 如果云硬盘有标签,则会有该字段,否则该字段为空。

wwn

String

云硬盘挂载时的唯一标识。

enterprise_project_id

String

云硬盘上绑定的企业项目ID。

关于企业项目ID的获取及企业项目特性的详细信息,请参见:"企业管理用户指南"。

表10 Attachment

参数

参数类型

描述

attached_at

String

挂载的时间信息。

时间格式:UTC YYYY-MM-DDTHH:MM:SS.XXXXXX

attachment_id

String

挂载信息对应的ID。

device

String

挂载点。

host_name

String

云硬盘挂载到的云服务器对应的物理主机的名称。

id

String

挂载的资源ID。

server_id

String

云硬盘挂载到的云服务器的 ID。

volume_id

String

云硬盘ID。

表11 VolumeMetadata

参数

参数类型

描述

__system__cmkid

String

metadata中的加密cmkid字段,与__system__encrypted配合表示需要加密,cmkid长度固定为36个字节。

请求获取密钥ID的方法请参考:"查询密钥列表"。

__system__encrypted

String

metadata中的表示加密功能的字段,0代表不加密,1代表加密。 不指定该字段时,云硬盘的加密属性与数据源保持一致,如果不是从数据源创建的场景,则默认不加密。

full_clone

String

从快照创建云硬盘时的创建方式。

  • 0表示使用链接克隆方式。

  • 1表示使用全量克隆方式。

hw:passthrough

String

  • true表示云硬盘的设备类型为SCSI类型,即允许ECS操作系统直接访问底层存储介质。支持SCSI锁命令。

  • false表示云硬盘的设备类型为VBD (虚拟块存储设备 , Virtual Block Device)类型,即为默认类型,VBD只能支持简单的SCSI读写命令。

  • 该字段不存在时,云硬盘默认为VBD类型。

orderID

String

metadata中的表示云硬盘计费类型的字段。 当该字段有值时,表示该云硬盘的计费类型为包周期计费,否则计费类型为按需计费。

状态码: 400

表12 响应Body参数

参数

参数类型

描述

error

Error object

出现错误时,返回的错误码。错误码和其对应的含义请参考错误码说明

表13 Error

参数

参数类型

描述

code

String

出现错误时,返回的错误码。错误码和其对应的含义请参考错误码说明

message

String

出现错误时,返回的错误消息。

请求示例

使用标签(key_string:value_string、key_string02:value_string02)查询名称为shared01的云硬盘资源实例详情,从第10条记录开始查询,返回结果中的记录数不超过100个。

POST https://{endpoint}/v2/{project_id}/cloudvolumes/resource_instances/action

{
  "offset" : 9,
  "limit" : 100,
  "action" : "filter",
  "tags" : [ {
    "key" : "key_string",
    "values" : [ "value_string" ]
  }, {
    "key" : "key_string02",
    "values" : [ "value_string02" ]
  } ],
  "matches" : [ {
    "key" : "resource_name",
    "value" : "shared01"
  }, {
    "key" : "service_type",
    "value" : "EVS"
  } ]
}

响应示例

状态码: 200

云硬盘信息。

{
  "total_count" : 1,
  "resources" : [ {
    "resource_name" : "resource1",
    "resource_detail" : {
      "attachments" : [ {
        "server_id" : "2080869e-ba46-4ea5-b45e-3191ac0f1d54",
        "attachment_id" : "1335f039-7a42-4d1e-be49-ac584db0ba0b",
        "attached_at" : "2019-08-06T07:00:21.842812",
        "volume_id" : "7fa6b592-ac75-460d-a28a-bb17429d1eb2",
        "device" : "/dev/vda",
        "id" : "7fa6b592-ac75-460d-a28a-bb17429d1eb2"
      } ],
      "links" : [ {
        "href" : "https://volume.Region.dc1.domainname.com/v2/051375756c80d5eb2ff0c014498645fb/volumes/7fa6b592-ac75-460d-a28a-bb17429d1eb2",
        "rel" : "self"
      }, {
        "href" : "https://volume.Region.dc1.domainname.com/051375756c80d5eb2ff0c014498645fb/volumes/7fa6b592-ac75-460d-a28a-bb17429d1eb2",
        "rel" : "bookmark"
      } ],
      "availability_zone" : "kvmxen.dc1",
      "os-vol-host-attr:host" : "az21.dc1#2",
      "enterprise_project_id" : "0",
      "updated_at" : "2019-08-09T06:19:35.874737",
      "replication_status" : "disabled",
      "id" : "7fa6b592-ac75-460d-a28a-bb17429d1eb2",
      "size" : 40,
      "user_id" : "75f26e17348643bfb7718578b04635c2",
      "os-vol-tenant-attr:tenant_id" : "051375756c80d5eb2ff0c014498645fb",
      "service_type" : "EVS",
      "metadata" : { },
      "status" : "in-use",
      "volume_image_metadata" : {
        "size" : "0",
        "__quick_start" : "False",
        "container_format" : "bare",
        "min_ram" : "0",
        "image_name" : "test-hua-centos7.3-0725",
        "image_id" : "c6c153a6-dde8-4bac-8e40-3d7619436934",
        "__os_type" : "Linux",
        "min_disk" : "20",
        "__support_kvm" : "true",
        "virtual_env_type" : "FusionCompute",
        "__description" : "",
        "__os_version" : "CentOS 7.3 64bit",
        "__os_bit" : "64",
        "__image_source_type" : "uds",
        "__support_xen" : "true",
        "file_format" : "zvhd2",
        "checksum" : "d41d8cd98f00b204e9800998ecf8427e",
        "__imagetype" : "gold",
        "disk_format" : "zvhd2",
        "__image_cache_type" : "Not_Cache",
        "__isregistered" : "true",
        "__image_location" : "192.149.46.200:5443:pcsimssouthchina:c6c153a6-dde8-4bac-8e40-3d7619436934",
        "__image_size" : "911269888",
        "__platform" : "CentOS"
      },
      "description" : "",
      "multiattach" : false,
      "name" : "resource1",
      "bootable" : "true",
      "created_at" : "2019-08-06T06:59:03.056682",
      "volume_type" : "SAS",
      "shareable" : false
    },
    "tags" : [ {
      "key" : "key1",
      "value" : "value1"
    }, {
      "key" : "key1",
      "value" : "value2"
    } ],
    "resource_id" : "7fa6b592-ac75-460d-a28a-bb17429d1eb2"
  } ]
}

状态码: 400

Bad Request

{
  "error" : {
    "message" : "XXXX",
    "code" : "XXX"
  }
}

SDK代码示例

SDK代码示例如下。

使用标签(key_string:value_string、key_string02:value_string02)查询名称为shared01的云硬盘资源实例详情,从第10条记录开始查询,返回结果中的记录数不超过100个。

 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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.evs.v2.region.EvsRegion;
import com.huaweicloud.sdk.evs.v2.*;
import com.huaweicloud.sdk.evs.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class ListVolumesByTagsSolution {

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

        EvsClient client = EvsClient.newBuilder()
                .withCredential(auth)
                .withRegion(EvsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListVolumesByTagsRequest request = new ListVolumesByTagsRequest();
        ListVolumesByTagsRequestBody body = new ListVolumesByTagsRequestBody();
        List<String> listTagsValues = new ArrayList<>();
        listTagsValues.add("value_string02");
        List<String> listTagsValues1 = new ArrayList<>();
        listTagsValues1.add("value_string");
        List<TagsForListVolumes> listbodyTags = new ArrayList<>();
        listbodyTags.add(
            new TagsForListVolumes()
                .withKey("key_string")
                .withValues(listTagsValues1)
        );
        listbodyTags.add(
            new TagsForListVolumes()
                .withKey("key_string02")
                .withValues(listTagsValues)
        );
        List<Match> listbodyMatches = new ArrayList<>();
        listbodyMatches.add(
            new Match()
                .withKey(Match.KeyEnum.fromValue("resource_name"))
                .withValue("shared01")
        );
        listbodyMatches.add(
            new Match()
                .withKey(Match.KeyEnum.fromValue("service_type"))
                .withValue("EVS")
        );
        body.withTags(listbodyTags);
        body.withOffset(9);
        body.withMatches(listbodyMatches);
        body.withLimit(100);
        body.withAction(ListVolumesByTagsRequestBody.ActionEnum.fromValue("filter"));
        request.withBody(body);
        try {
            ListVolumesByTagsResponse response = client.listVolumesByTags(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());
        }
    }
}

使用标签(key_string:value_string、key_string02:value_string02)查询名称为shared01的云硬盘资源实例详情,从第10条记录开始查询,返回结果中的记录数不超过100个。

 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
56
57
58
59
60
61
62
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkevs.v2.region.evs_region import EvsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkevs.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.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

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

    try:
        request = ListVolumesByTagsRequest()
        listValuesTags = [
            "value_string02"
        ]
        listValuesTags1 = [
            "value_string"
        ]
        listTagsbody = [
            TagsForListVolumes(
                key="key_string",
                values=listValuesTags1
            ),
            TagsForListVolumes(
                key="key_string02",
                values=listValuesTags
            )
        ]
        listMatchesbody = [
            Match(
                key="resource_name",
                value="shared01"
            ),
            Match(
                key="service_type",
                value="EVS"
            )
        ]
        request.body = ListVolumesByTagsRequestBody(
            tags=listTagsbody,
            offset=9,
            matches=listMatchesbody,
            limit=100,
            action="filter"
        )
        response = client.list_volumes_by_tags(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

使用标签(key_string:value_string、key_string02:value_string02)查询名称为shared01的云硬盘资源实例详情,从第10条记录开始查询,返回结果中的记录数不超过100个。

 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    evs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/evs/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 := evs.NewEvsClient(
        evs.EvsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListVolumesByTagsRequest{}
	var listValuesTags = []string{
        "value_string02",
    }
	var listValuesTags1 = []string{
        "value_string",
    }
	var listTagsbody = []model.TagsForListVolumes{
        {
            Key: "key_string",
            Values: listValuesTags1,
        },
        {
            Key: "key_string02",
            Values: listValuesTags,
        },
    }
	var listMatchesbody = []model.Match{
        {
            Key: model.GetMatchKeyEnum().RESOURCE_NAME,
            Value: "shared01",
        },
        {
            Key: model.GetMatchKeyEnum().SERVICE_TYPE,
            Value: "EVS",
        },
    }
	offsetListVolumesByTagsRequestBody:= int32(9)
	limitListVolumesByTagsRequestBody:= int32(100)
	request.Body = &model.ListVolumesByTagsRequestBody{
		Tags: listTagsbody,
		Offset: &offsetListVolumesByTagsRequestBody,
		Matches: &listMatchesbody,
		Limit: &limitListVolumesByTagsRequestBody,
		Action: model.GetListVolumesByTagsRequestBodyActionEnum().FILTER,
	}
	response, err := client.ListVolumesByTags(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

云硬盘信息。

400

Bad Request

错误码

请参见错误码