更新时间:2024-09-12 GMT+08:00

更新任务带宽策略

功能介绍

当迁移任务未执行完成时,修改迁移任务的流量控制策略。

调用方法

请参见如何调用API

URI

PUT /v2/{project_id}/tasks/{task_id}/bandwidth-policy

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

最小长度:1

最大长度:1024

task_id

String

任务ID。

最小长度:1

最大长度:1024

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

IAM鉴权Token。

最小长度:1

最大长度:16384

表3 请求Body参数

参数

是否必选

参数类型

描述

bandwidth_policy

Array of BandwidthPolicyDto objects

配置流量控制策略。数组中一个元素对应一个时段的最大带宽,最多允许5个时段,且时段不能重叠。

数组长度:0 - 5

表4 BandwidthPolicyDto

参数

是否必选

参数类型

描述

end

String

流量控制结束时间(包含),格式为“hh:mm”。例如“12:03”表示12时03分。

max_bandwidth

Long

时段内允许的最大流量带宽,单位Byte/s,取值范围为>= 1048576Byte/s(相当于1MB/s)且<=209715200Byte/s(相当于200MB/s)。

最小值:1048576

最大值:209715200

start

String

流量控制开始时间(包含),格式为“hh:mm”。例如“12:03”表示12时03分。

响应参数

状态码: 400

表5 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

error_code

String

错误码。

请求示例

将task_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50MB/s。

/v2/{project_id}/tasks/xxxxxxxx/bandwidth-policy

{
  "bandwidth_policy" : [ {
    "start" : "00:01",
    "end" : "23:59",
    "max_bandwidth" : 50000000
  } ]
}

响应示例

SDK代码示例

SDK代码示例如下。

将task_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50MB/s。

 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 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.oms.v2.region.OmsRegion;
import com.huaweicloud.sdk.oms.v2.*;
import com.huaweicloud.sdk.oms.v2.model.*;

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

public class UpdateBandwidthPolicySolution {

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

        OmsClient client = OmsClient.newBuilder()
                .withCredential(auth)
                .withRegion(OmsRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateBandwidthPolicyRequest request = new UpdateBandwidthPolicyRequest();
        UpdateBandwidthPolicyReq body = new UpdateBandwidthPolicyReq();
        List<BandwidthPolicyDto> listbodyBandwidthPolicy = new ArrayList<>();
        listbodyBandwidthPolicy.add(
            new BandwidthPolicyDto()
                .withEnd("23:59")
                .withMaxBandwidth(50000000L)
                .withStart("00:01")
        );
        body.withBandwidthPolicy(listbodyBandwidthPolicy);
        request.withBody(body);
        try {
            UpdateBandwidthPolicyResponse response = client.updateBandwidthPolicy(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());
        }
    }
}

将task_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50MB/s。

 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

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkoms.v2.region.oms_region import OmsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkoms.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.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = BasicCredentials(ak, sk)

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

    try:
        request = UpdateBandwidthPolicyRequest()
        listBandwidthPolicybody = [
            BandwidthPolicyDto(
                end="23:59",
                max_bandwidth=50000000,
                start="00:01"
            )
        ]
        request.body = UpdateBandwidthPolicyReq(
            bandwidth_policy=listBandwidthPolicybody
        )
        response = client.update_bandwidth_policy(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

将task_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50MB/s。

 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
package main

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

    request := &model.UpdateBandwidthPolicyRequest{}
	var listBandwidthPolicybody = []model.BandwidthPolicyDto{
        {
            End: "23:59",
            MaxBandwidth: int64(50000000),
            Start: "00:01",
        },
    }
	request.Body = &model.UpdateBandwidthPolicyReq{
		BandwidthPolicy: listBandwidthPolicybody,
	}
	response, err := client.UpdateBandwidthPolicy(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK

400

Bad Request

错误码

请参见错误码