云硬盘 EVS-创建云硬盘:Python

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

Python

  • 在DSS存储池1b6198f2-20a6-5dcc-aa21-58c1af5dc488中创建一个共享加密云硬盘,该云硬盘所在的位置为华北-北京四可用区一,该云硬盘的名称为EVS-Test,云硬盘模式为SCSI,云硬盘类型为高IO,容量为10GiB。

     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
    # 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 = CreateVolumeRequest()
            osschhntschedulerhintsbody = CreateVolumeSchedulerHints(
                dedicated_storage_id="1b6198f2-20a6-5dcc-aa21-58c1af5dc488"
            )
            listMetadataVolume = {
                "hw:passthrough": "true",
                "__system__encrypted": "1",
                "__system__cmkid": "94257794-d7aa-462c-9eaa-9f32c05b9966",
                "region": "cn-north-4"
            }
            volumebody = CreateVolumeOption(
                availability_zone="cn-north-4a",
                enterprise_project_id="0",
                metadata=listMetadataVolume,
                multiattach=True,
                name="EVS-Test",
                size=10,
                volume_type="SAS"
            )
            request.body = CreateVolumeRequestBody(
                os_sch_hn_tscheduler_hints=osschhntschedulerhintsbody,
                volume=volumebody
            )
            response = client.create_volume(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个共享云硬盘,该云硬盘所在位置为华北-北京四可用区一,该云硬盘名称为EVS-Test2,云硬盘类型为通用型SSD V2,IOPS性能配置为5000,吞吐量性能配置为500MiB/s,容量为100GiB,并为该云硬盘添加标签。该云硬盘订购周期为3个月,且开通自动续订,下单后立即从帐户余额中自动扣费。

     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
    # 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 = CreateVolumeRequest()
            listTagsVolume = {
                "key_string": "value_string"
            }
            volumebody = CreateVolumeOption(
                availability_zone="cn-north-4a",
                count=1,
                multiattach=1,
                name="EVS-Test2",
                size=100,
                volume_type="GPSSD2",
                tags=listTagsVolume,
                iops=5000,
                throughput=500
            )
            bssParambody = BssParamForCreateVolume(
                charging_mode="prePaid",
                is_auto_pay="true",
                is_auto_renew="true",
                period_num=3,
                period_type="month"
            )
            request.body = CreateVolumeRequestBody(
                volume=volumebody,
                bss_param=bssParambody
            )
            response = client.create_volume(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_2003.html