文档首页> 云硬盘 EVS> API参考> API> 快照管理> 查询云硬盘快照详情列表
更新时间:2024-01-02 GMT+08:00
分享

查询云硬盘快照详情列表

功能介绍

查询云硬盘快照详情列表。

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/cloudsnapshots/detail

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

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

表2 Query参数

参数

是否必选

参数类型

描述

offset

Integer

偏移量。 说明:分页查询快照时使用,与limit配合使用。假如共有30个快照,设置offset为11,limit为10,即为从第12个快照开始查询,一次最多可读取10个快照。

limit

Integer

返回结果个数限制,值为大于0的整数。默认值为1000。

name

String

云硬盘快照名称。最大支持64个字符。

status

String

云硬盘快照状态,具体请参见云硬盘快照状态

volume_id

String

快照所属云硬盘的ID。

availability_zone

String

快照所属云硬盘的可用区。

id

String

指定快照id进行过滤。可以传入多个id过滤查询,格式:id=id1&id=id2&id=id3

dedicated_storage_name

String

专属存储的名称。

dedicated_storage_id

String

专属存储ID。

service_type

String

服务类型。仅支持EVS、DSS、DESS。

enterprise_project_id

String

指定企业项目id进行过滤。 传入“all_granted_eps”,代表查询权限范围内的所有企业项目下的云硬盘。

说明:

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

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

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

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

count

Integer

快照的总数量,不受limi参数的影响。

snapshots

Array of SnapshotList objects

快照信息。

snapshots_links

Array of Link objects

云硬盘快照列表查询位置标记。当查询时指定limit时会返回该字段,返回该字段表示本次查询只查出了部分云硬盘快照信息。

表5 SnapshotList

参数

参数类型

描述

id

String

云硬盘快照ID。

status

String

云硬盘快照的状态。

name

String

云硬盘快照名称。

description

String

云硬盘快照描述信息。

created_at

String

云硬盘快照创建时间。

updated_at

String

云硬盘快照更新时间。

metadata

Map<String,String>

云硬盘快照的元数据信息。

volume_id

String

快照所属的云硬盘。

size

Integer

云硬盘快照大小。

os-extended-snapshot-attributes:project_id

String

项目ID。

os-extended-snapshot-attributes:progress

String

快照进度。

dedicated_storage_id

String

专属存储ID。

dedicated_storage_name

String

专属存储名称。

service_type

String

服务类型。

状态码: 400

表7 响应Body参数

参数

参数类型

描述

error

Error object

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

表8 Error

参数

参数类型

描述

code

String

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

message

String

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

请求示例

  • 查询快照id为c311bb8d-17f1-4e99-aaf9-e132c0391a73和c7691083-15fa-4045-956c-2bcbfe1b9976的快照详情,从第1条记录开始查询,返回结果中的记录数不超过100个。

    GET https://{endpoint}/v2/{project_id}/cloudsnapshots/detail?id=c311bb8d-17f1-4e99-aaf9-e132c0391a73&id=c7691083-15fa-4045-956c-2bcbfe1b9976&offset=0&limit=100
  • 查询id为f8c7cce6-ec47-43ca-9297-b5604668b08f的云硬盘的所有快照详情。

    GET https://{endpoint}/v2/{project_id}/cloudsnapshots/detail?volume_id=f8c7cce6-ec47-43ca-9297-b5604668b08f&service_type=EVS

响应示例

状态码: 200

OK

{
  "count" : 3,
  "snapshots_links" : [ {
    "href" : "https://{endpoint}/v2/20a68d6b7a124ae2b6b8a22046ee5966/cloudsnapshots/detail?limit=1&marker=fc05d5d7-7e99-42fb-b6f2-9ddd1b990e67",
    "rel" : "next"
  } ],
  "snapshots" : [ {
    "status" : "available",
    "updated_at" : "2018-06-06T10:58:47.349051",
    "volume_id" : "f687bd70-37b3-4f00-a900-0ba1cfaa5196",
    "id" : "fc05d5d7-7e99-42fb-b6f2-9ddd1b990e67",
    "size" : 1,
    "os-extended-snapshot-attributes:progress" : "100%",
    "name" : "test03",
    "os-extended-snapshot-attributes:project_id" : "20a68d6b7a124ae2b6b8a22046ee5966",
    "service_type" : "EVS",
    "created_at" : "2018-05-30T03:14:44.457975",
    "metadata" : { }
  } ]
}

状态码: 400

Bad Request

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

SDK代码示例

SDK代码示例如下。

Java

 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
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.*;


public class ListSnapshotsSolution {

    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();
        ListSnapshotsRequest request = new ListSnapshotsRequest();
        request.withOffset(<offset>);
        request.withLimit(<limit>);
        request.withName("<name>");
        request.withStatus("<status>");
        request.withVolumeId("<volume_id>");
        request.withAvailabilityZone("<availability_zone>");
        request.withId("<id>");
        request.withDedicatedStorageName("<dedicated_storage_name>");
        request.withDedicatedStorageId("<dedicated_storage_id>");
        request.withServiceType("<service_type>");
        request.withEnterpriseProjectId("<enterprise_project_id>");
        try {
            ListSnapshotsResponse response = client.listSnapshots(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

 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
# 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 = ListSnapshotsRequest()
        request.offset = <offset>
        request.limit = <limit>
        request.name = "<name>"
        request.status = "<status>"
        request.volume_id = "<volume_id>"
        request.availability_zone = "<availability_zone>"
        request.id = "<id>"
        request.dedicated_storage_name = "<dedicated_storage_name>"
        request.dedicated_storage_id = "<dedicated_storage_id>"
        request.service_type = "<service_type>"
        request.enterprise_project_id = "<enterprise_project_id>"
        response = client.list_snapshots(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

 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
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.ListSnapshotsRequest{}
	offsetRequest:= int32(<offset>)
	request.Offset = &offsetRequest
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	nameRequest:= "<name>"
	request.Name = &nameRequest
	statusRequest:= "<status>"
	request.Status = &statusRequest
	volumeIdRequest:= "<volume_id>"
	request.VolumeId = &volumeIdRequest
	availabilityZoneRequest:= "<availability_zone>"
	request.AvailabilityZone = &availabilityZoneRequest
	idRequest:= "<id>"
	request.Id = &idRequest
	dedicatedStorageNameRequest:= "<dedicated_storage_name>"
	request.DedicatedStorageName = &dedicatedStorageNameRequest
	dedicatedStorageIdRequest:= "<dedicated_storage_id>"
	request.DedicatedStorageId = &dedicatedStorageIdRequest
	serviceTypeRequest:= "<service_type>"
	request.ServiceType = &serviceTypeRequest
	enterpriseProjectIdRequest:= "<enterprise_project_id>"
	request.EnterpriseProjectId = &enterpriseProjectIdRequest
	response, err := client.ListSnapshots(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

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

状态码

状态码

描述

200

OK

400

Bad Request

错误码

请参见错误码

分享:

    相关文档

    相关产品