云服务器内容精选

  • 请求示例 使用标签(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" } }
  • 请求参数 表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就会匹配出来。
  • Python 使用标签(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("cn-north-4")) \ .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)
  • Go 使用标签(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("cn-north-4")). 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) } }