云硬盘 EVS-为指定云硬盘批量删除标签:Python

时间:2023-12-08 18:03:55

Python

删除一个指定云硬盘的两个标签,一个标签key为key1,另一个标签key为key2。

 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
# 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 = BatchDeleteVolumeTagsRequest()
        listTagsbody = [
            DeleteTagsOption(
                key="key1"
            ),
            DeleteTagsOption(
                key="key2"
            )
        ]
        request.body = BatchDeleteVolumeTagsRequestBody(
            tags=listTagsbody,
            action="delete"
        )
        response = client.batch_delete_volume_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)
support.huaweicloud.com/api-evs/evs_04_2029.html