创建迁移任务 - CreateTask
功能介绍
根据源端服务器创建一个迁移任务。
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
- 如果使用身份策略授权,需具备如下身份策略权限。
授权项
访问级别
资源类型(*为必须)
条件键
别名
依赖的授权项
sms:server:createTask
Write
server *
-
- sms:server:migrationServer
-
-
g:EnterpriseProjectId
URI
POST /v3/tasks
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
name |
是 |
String |
任务名称 |
|
type |
是 |
String |
任务类型 MIGRATE_FILE:文件级迁移 MIGRATE_BLOCK:块级迁移 枚举值:
|
|
start_target_server |
否 |
Boolean |
迁移后是否启动目的端虚拟机 默认取值: true |
|
auto_start |
否 |
Boolean |
是否自动启动 |
|
os_type |
是 |
String |
操作系统类型 |
|
source_server |
是 |
SourceServerByTask object |
源端服务器信息 |
|
target_server |
是 |
TargetServerByTask object |
目的端虚拟机信息 |
|
migration_ip |
否 |
String |
迁移IP,如果是自动创建虚拟机,不需要此参数 |
|
region_name |
是 |
String |
region的名称 |
|
region_id |
是 |
String |
region ID |
|
project_name |
是 |
String |
项目名称 |
|
project_id |
是 |
String |
项目ID |
|
priority |
否 |
Integer |
优先级。默认为1 取值范围: 0~65535 |
|
vm_template_id |
否 |
String |
自动创建虚拟机使用模板 |
|
use_public_ip |
否 |
Boolean |
是否使用公网ip 默认取值: true |
|
use_ipv6 |
否 |
Boolean |
是否使用ipv6 |
|
syncing |
否 |
Boolean |
复制或者同步后是否会继续持续同步,不添加则默认是false 默认取值: false |
|
exist_server |
否 |
Boolean |
是否存在服务,如果存在,则创建任务 |
|
start_network_check |
否 |
Boolean |
是否开启网络检测 |
|
speed_limit |
否 |
Integer |
迁移速率限制值 取值范围: 0~10000 |
|
over_speed_threshold |
否 |
Double |
停止迁移的超速阈值。 是一个迁移速率的保护机制,超出该阈值会停止任务。它主要用于控制迁移过程中资源(特别是网络带宽)的消耗,确保系统的整体性能不受单一迁移任务影响 单位是百分比 取值范围: 10~100 |
|
is_need_consistency_check |
否 |
Boolean |
是否进行一致性校验 |
|
need_migration_test |
否 |
Boolean |
是否开启迁移演练 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
btrfs_list |
否 |
Array of BtrfsFileSystem objects |
btrfs信息,数据从源端获取 |
|
disks |
是 |
Array of TargetDisks objects |
磁盘信息 |
|
name |
是 |
String |
名称 |
|
vm_id |
是 |
String |
虚拟机ID |
|
volume_groups |
否 |
Array of VolumeGroups objects |
卷组,数据从源端获取 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
name |
是 |
String |
文件系统名称 |
|
label |
是 |
String |
文件系统标签,若无标签为空字符串 |
|
uuid |
是 |
String |
文件系统的uuid |
|
device |
是 |
String |
btrfs包含的设备名称 |
|
size |
是 |
Long |
文件系统数据占用大小 取值范围: 0~9223372036854775807 |
|
nodesize |
是 |
Long |
btrfs节点大小 取值范围: 0~9223372036854775807 |
|
sectorsize |
是 |
Integer |
扇区大小 取值范围: 0~2147483647 |
|
data_profile |
是 |
String |
数据配置(RAD) |
|
system_profile |
是 |
String |
文件系统配置(RAD) |
|
metadata_profile |
是 |
String |
元数据配置(RAD) |
|
global_reserve1 |
是 |
String |
Btrfs文件系统信息 |
|
g_vol_used_size |
是 |
Long |
Btrfs卷已使用空间大小 取值范围: 0~9223372036854775807 |
|
default_subvolid |
是 |
String |
默认子卷ID |
|
default_subvol_name |
是 |
String |
默认子卷名称 |
|
default_subvol_mountpath |
是 |
String |
默认子卷挂载路径/BTRFS文件系统的挂载路径 |
|
subvolumn |
是 |
Array of BtrfsSubvolumn objects |
子卷信息 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
uuid |
是 |
String |
父卷的uuid |
|
is_snapshot |
是 |
String |
子卷是否为快照 |
|
subvol_id |
是 |
String |
子卷的ID |
|
parent_id |
是 |
String |
父卷ID |
|
subvol_name |
是 |
String |
子卷的名称 |
|
subvol_mount_path |
是 |
String |
子卷的挂载路径 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
device_use |
否 |
String |
磁盘类型,普通磁盘,OS所在磁盘,BOOT所在磁盘 BOOT:BOOT设备 OS:系统设备 NORMAL:平常 默认取值: NORMAL 枚举值:
|
|
disk_id |
否 |
String |
磁盘ID,自动创建虚拟机不用设置 |
|
name |
是 |
String |
名称,根据磁盘顺序设置为disk X |
|
physical_volumes |
是 |
Array of PhysicalVolumes objects |
物理卷信息 |
|
size |
是 |
Long |
大小 取值范围: 0~9223372036854775807 |
|
used_size |
是 |
Long |
使用大小 取值范围: 0~9223372036854775807 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
device_use |
否 |
String |
分区类型,普通分区,启动分区,系统分区 |
|
file_system |
否 |
String |
文件系统类型 |
|
index |
否 |
Integer |
顺序 取值范围: 0~2147483647 |
|
mount_point |
否 |
String |
挂载点 |
|
name |
否 |
String |
名称,windows表示盘符,Linux表示设备号 |
|
size |
否 |
Long |
大小 取值范围: 0~9223372036854775807 |
|
inode_size |
否 |
Long |
inode数量 取值范围: 0~9223372036854775807 |
|
used_size |
否 |
Long |
使用大小 取值范围: 0~9223372036854775807 |
|
uuid |
否 |
String |
GUID,可从源端查询 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
components |
否 |
String |
Pv信息 |
|
free_size |
否 |
Long |
剩余空间 取值范围: 0~9223372036854775807 |
|
logical_volumes |
否 |
Array of LogicalVolumes objects |
lv信息 |
|
name |
否 |
String |
名称 |
|
size |
否 |
Long |
大小 取值范围: 0~9223372036854775807 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
block_count |
否 |
Integer |
块数量 取值范围: 0~2147483647 默认取值: 0 |
|
block_size |
否 |
Long |
块大小 取值范围: 0~1048576 默认取值: 0 |
|
file_system |
是 |
String |
文件系统 |
|
inode_size |
是 |
Integer |
inode数量 取值范围: 0~2147483647 |
|
inode_nums |
否 |
Long |
inode节点数量 取值范围: 0~9223372036854775807 |
|
device_use |
否 |
String |
分区类型,普通分区,启动分区,系统分区 |
|
mount_point |
是 |
String |
挂载点 |
|
name |
是 |
String |
名称 |
|
size |
是 |
Long |
大小 取值范围: 0~9223372036854775807 |
|
used_size |
是 |
Long |
使用大小 取值范围: 0~9223372036854775807 |
|
free_size |
是 |
Long |
剩余空间 取值范围: 0~9223372036854775807 |
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
id |
String |
创建成功返回的任务ID |
状态码:403
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
error_code |
String |
错误代码 |
|
error_msg |
String |
错误信息 |
|
encoded_authorization_message |
String |
加密授权信息 |
|
error_param |
Array of strings |
错误参数 |
|
details |
Array of details objects |
详细错误信息 |
请求示例
创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_id。
POST https://{endpoint}/v3/tasks
{
"name" : "MigrationTask",
"type" : "MIGRATE_FILE",
"os_type" : "LINUX",
"start_target_server" : true,
"use_public_ip" : true,
"migration_ip" : "192.168.0.1",
"region_name" : "region_name",
"region_id" : "region_id",
"project_name" : "project_name",
"project_id" : "xxxxxxxxxxxxxxxxxxxxxxxx00000001",
"source_server" : {
"id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"
},
"target_server" : {
"vm_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
"name" : "Auto-tar-name",
"disks" : [ {
"name" : "/dev/vda",
"disk_id" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001",
"size" : 42949672960,
"used_size" : 429496,
"device_use" : "BOOT",
"physical_volumes" : [ {
"uuid" : null,
"index" : 0,
"name" : "/dev/vda1",
"device_use" : "OS",
"file_system" : "ext4",
"mount_point" : "/",
"size" : 42947575808,
"used_size" : 5346484224
} ]
} ],
"volume_groups" : [ ]
},
"is_need_consistency_check" : true
}
响应示例
状态码:200
创建迁移任务成功
{
"id" : "xxxxxxxxxxxxxxxxxxxxxxxx00000001"
}
状态码:403
鉴权失败
{
"error_code" : "SMS.9004",
"error_msg" : "The current account does not have the permission to execute policy You do not have permission to perform action XXX on resource XXX.",
"encoded_authorization_message" : "XXXXXX",
"error_param" : [ "You do not have permission to perform action XXX on resource XXX." ],
"details" : [ {
"error_code" : "SMS.9004",
"error_msg" : "You do not have permission to perform action XXX on resource XXX."
} ]
}
SDK代码示例
SDK代码示例如下。
创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_id。
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.GlobalCredentials; 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.sms.v3.region.SmsRegion; import com.huaweicloud.sdk.sms.v3.*; import com.huaweicloud.sdk.sms.v3.model.*; import java.util.List; import java.util.ArrayList; public class CreateTaskSolution { 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 GlobalCredentials() .withAk(ak) .withSk(sk); SmsClient client = SmsClient.newBuilder() .withCredential(auth) .withRegion(SmsRegion.valueOf("<YOUR REGION>")) .build(); CreateTaskRequest request = new CreateTaskRequest(); PostTask body = new PostTask(); List<PhysicalVolumes> listDisksPhysicalVolumes = new ArrayList<>(); listDisksPhysicalVolumes.add( new PhysicalVolumes() .withDeviceUse("OS") .withFileSystem("ext4") .withIndex(0) .withMountPoint("/") .withName("/dev/vda1") .withSize(42947575808L) .withUsedSize(5346484224L) ); List<TargetDisks> listTargetServerDisks = new ArrayList<>(); listTargetServerDisks.add( new TargetDisks() .withDeviceUse(TargetDisks.DeviceUseEnum.fromValue("BOOT")) .withDiskId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001") .withName("/dev/vda") .withPhysicalVolumes(listDisksPhysicalVolumes) .withSize(42949672960L) .withUsedSize(429496L) ); TargetServerByTask targetServerbody = new TargetServerByTask(); targetServerbody.withDisks(listTargetServerDisks) .withName("Auto-tar-name") .withVmId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"); SourceServerByTask sourceServerbody = new SourceServerByTask(); sourceServerbody.withId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001"); body.withIsNeedConsistencyCheck(true); body.withUsePublicIp(true); body.withProjectId("xxxxxxxxxxxxxxxxxxxxxxxx00000001"); body.withProjectName("project_name"); body.withRegionId("region_id"); body.withRegionName("region_name"); body.withMigrationIp("192.168.0.1"); body.withTargetServer(targetServerbody); body.withSourceServer(sourceServerbody); body.withOsType("LINUX"); body.withStartTargetServer(true); body.withType(PostTask.TypeEnum.fromValue("MIGRATE_FILE")); body.withName("MigrationTask"); request.withBody(body); try { CreateTaskResponse response = client.createTask(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()); } } } |
创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_id。
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 71 72 73 74 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import GlobalCredentials from huaweicloudsdksms.v3.region.sms_region import SmsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdksms.v3 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 = GlobalCredentials(ak, sk) client = SmsClient.new_builder() \ .with_credentials(credentials) \ .with_region(SmsRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateTaskRequest() listPhysicalVolumesDisks = [ PhysicalVolumes( device_use="OS", file_system="ext4", index=0, mount_point="/", name="/dev/vda1", size=42947575808, used_size=5346484224 ) ] listDisksTargetServer = [ TargetDisks( device_use="BOOT", disk_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001", name="/dev/vda", physical_volumes=listPhysicalVolumesDisks, size=42949672960, used_size=429496 ) ] targetServerbody = TargetServerByTask( disks=listDisksTargetServer, name="Auto-tar-name", vm_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001" ) sourceServerbody = SourceServerByTask( id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001" ) request.body = PostTask( is_need_consistency_check=True, use_public_ip=True, project_id="xxxxxxxxxxxxxxxxxxxxxxxx00000001", project_name="project_name", region_id="region_id", region_name="region_name", migration_ip="192.168.0.1", target_server=targetServerbody, source_server=sourceServerbody, os_type="LINUX", start_target_server=True, type="MIGRATE_FILE", name="MigrationTask" ) response = client.create_task(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
创建一个迁移任务,迁移任务名称是MigrationTask,迁移类型是MIGRATE_FILE文件级迁移,源端操作系统类型是LINUX,使用公网迁移是true,迁移region名称是region_name,迁移region的ID是region_id。
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global" sms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/sms/v3/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 := global.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := sms.NewSmsClient( sms.SmsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateTaskRequest{} deviceUsePhysicalVolumes:= "OS" fileSystemPhysicalVolumes:= "ext4" indexPhysicalVolumes:= int32(0) mountPointPhysicalVolumes:= "/" namePhysicalVolumes:= "/dev/vda1" sizePhysicalVolumes:= int64(42947575808) usedSizePhysicalVolumes:= int64(5346484224) var listPhysicalVolumesDisks = []model.PhysicalVolumes{ { DeviceUse: &deviceUsePhysicalVolumes, FileSystem: &fileSystemPhysicalVolumes, Index: &indexPhysicalVolumes, MountPoint: &mountPointPhysicalVolumes, Name: &namePhysicalVolumes, Size: &sizePhysicalVolumes, UsedSize: &usedSizePhysicalVolumes, }, } deviceUseDisks:= model.GetTargetDisksDeviceUseEnum().BOOT diskIdDisks:= "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001" var listDisksTargetServer = []model.TargetDisks{ { DeviceUse: &deviceUseDisks, DiskId: &diskIdDisks, Name: "/dev/vda", PhysicalVolumes: listPhysicalVolumesDisks, Size: int64(42949672960), UsedSize: int64(429496), }, } targetServerbody := &model.TargetServerByTask{ Disks: listDisksTargetServer, Name: "Auto-tar-name", VmId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001", } sourceServerbody := &model.SourceServerByTask{ Id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx0001", } isNeedConsistencyCheckPostTask:= true usePublicIpPostTask:= true migrationIpPostTask:= "192.168.0.1" startTargetServerPostTask:= true request.Body = &model.PostTask{ IsNeedConsistencyCheck: &isNeedConsistencyCheckPostTask, UsePublicIp: &usePublicIpPostTask, ProjectId: "xxxxxxxxxxxxxxxxxxxxxxxx00000001", ProjectName: "project_name", RegionId: "region_id", RegionName: "region_name", MigrationIp: &migrationIpPostTask, TargetServer: targetServerbody, SourceServer: sourceServerbody, OsType: "LINUX", StartTargetServer: &startTargetServerPostTask, Type: model.GetPostTaskTypeEnum().MIGRATE_FILE, Name: "MigrationTask", } response, err := client.CreateTask(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
创建迁移任务成功 |
|
403 |
鉴权失败 |
错误码
请参见错误码。