批量更新任务
功能介绍
批量更新迁移任务,可指定单个迁移任务组下所有的迁移任务或通过迁移任务ID来执行。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/tasks/batch-update
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID 最小长度:1 最大长度:1024 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
IAM Token认证,需要确认Token中包含的Project ID与请求URI中修改资源的Project ID匹配。 最小长度:1 最大长度:16384 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
group_id |
否 |
String |
迁移任务组ID,表示批量更新该任务组下所有任务。 group_id和ids为二选一参数,不可同时存在或同时缺失。 最小长度:1 最大长度:36 |
ids |
否 |
Array of longs |
迁移任务id数组,包含所有需要批量更新操作的任务id。 group_id和ids为二选一参数,不可同时存在或同时缺失。 最小值:0 最大值:9223372036854775807 数组长度:0 - 20 |
bandwidth_policy |
是 |
Array of BandwidthPolicyDto objects |
配置流量控制策略。数组中一个元素对应一个时段的最大带宽,最多允许5个时段,且时段不能重叠。 数组长度:0 - 5 |
task_priority |
否 |
String |
任务优先级配置,存在高中低三个优先级档次,限制仅在等待中、已暂停、已失败的任务进行修改 HIGH:高优先级 MEDIUM:中优先级 LOW:低优先级 枚举值:
|
响应参数
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_msg |
String |
错误信息。 |
error_code |
String |
错误码。 |
请求示例
-
将group_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/s
/v2/{project_id}/tasks/batch-update { "group_id" : "xxxxxxxx", "bandwidth_policy" : [ { "start" : "00:01", "end" : "23:59", "max_bandwidth" : 50000000 } ] }
-
将id为111,222的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/s
/v2/{project_id}/tasks/batch-update { "ids" : [ 111, 222 ], "bandwidth_policy" : [ { "start" : "00:01", "end" : "23:59", "max_bandwidth" : 50000000 } ] }
响应示例
无
SDK代码示例
SDK代码示例如下。
Java
-
将group_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/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 58 59 60
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 BatchUpdateTasksSolution { 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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); OmsClient client = OmsClient.newBuilder() .withCredential(auth) .withRegion(OmsRegion.valueOf("<YOUR REGION>")) .build(); BatchUpdateTasksRequest request = new BatchUpdateTasksRequest(); BatchUpdateTasksReq body = new BatchUpdateTasksReq(); List<BandwidthPolicyDto> listbodyBandwidthPolicy = new ArrayList<>(); listbodyBandwidthPolicy.add( new BandwidthPolicyDto() .withEnd("23:59") .withMaxBandwidth(50000000L) .withStart("00:01") ); body.withBandwidthPolicy(listbodyBandwidthPolicy); body.withGroupId("xxxxxxxx"); request.withBody(body); try { BatchUpdateTasksResponse response = client.batchUpdateTasks(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()); } } }
-
将id为111,222的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/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 58 59 60 61 62 63
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 BatchUpdateTasksSolution { 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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); OmsClient client = OmsClient.newBuilder() .withCredential(auth) .withRegion(OmsRegion.valueOf("<YOUR REGION>")) .build(); BatchUpdateTasksRequest request = new BatchUpdateTasksRequest(); BatchUpdateTasksReq body = new BatchUpdateTasksReq(); List<BandwidthPolicyDto> listbodyBandwidthPolicy = new ArrayList<>(); listbodyBandwidthPolicy.add( new BandwidthPolicyDto() .withEnd("23:59") .withMaxBandwidth(50000000L) .withStart("00:01") ); List<Long> listbodyIds = new ArrayList<>(); listbodyIds.add(111L); listbodyIds.add(222L); body.withBandwidthPolicy(listbodyBandwidthPolicy); body.withIds(listbodyIds); request.withBody(body); try { BatchUpdateTasksResponse response = client.batchUpdateTasks(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
-
将group_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/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
# 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"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = OmsClient.new_builder() \ .with_credentials(credentials) \ .with_region(OmsRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchUpdateTasksRequest() listBandwidthPolicybody = [ BandwidthPolicyDto( end="23:59", max_bandwidth=50000000, start="00:01" ) ] request.body = BatchUpdateTasksReq( bandwidth_policy=listBandwidthPolicybody, group_id="xxxxxxxx" ) response = client.batch_update_tasks(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
将id为111,222的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/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
# 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"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = OmsClient.new_builder() \ .with_credentials(credentials) \ .with_region(OmsRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchUpdateTasksRequest() listBandwidthPolicybody = [ BandwidthPolicyDto( end="23:59", max_bandwidth=50000000, start="00:01" ) ] listIdsbody = [ 111, 222 ] request.body = BatchUpdateTasksReq( bandwidth_policy=listBandwidthPolicybody, ids=listIdsbody ) response = client.batch_update_tasks(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
-
将group_id为xxxxxxxx的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/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
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := oms.NewOmsClient( oms.OmsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchUpdateTasksRequest{} var listBandwidthPolicybody = []model.BandwidthPolicyDto{ { End: "23:59", MaxBandwidth: int64(50000000), Start: "00:01", }, } groupIdBatchUpdateTasksReq:= "xxxxxxxx" request.Body = &model.BatchUpdateTasksReq{ BandwidthPolicy: listBandwidthPolicybody, GroupId: &groupIdBatchUpdateTasksReq, } response, err := client.BatchUpdateTasks(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
将id为111,222的任务的限速时段设置为00:01-23:59,限速值设置为50000000Byte/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
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := oms.NewOmsClient( oms.OmsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchUpdateTasksRequest{} var listBandwidthPolicybody = []model.BandwidthPolicyDto{ { End: "23:59", MaxBandwidth: int64(50000000), Start: "00:01", }, } var listIdsbody = []int64{ int64(111), int64(222), } request.Body = &model.BatchUpdateTasksReq{ BandwidthPolicy: listBandwidthPolicybody, Ids: &listIdsbody, } response, err := client.BatchUpdateTasks(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
OK 批量更新任务操作成功 |
400 |
Bad Request 请求参数错误 |
错误码
请参见错误码。