示例一:创建迁移任务
场景描述
本章节指导用户通过API创建迁移任务。API的调用方法请参见如何调用API。
涉及接口
- 获取IAM用户Token(使用密码):用于鉴权认证。
- 上报源端服务器基本信息:上报源端服务器信息注册源端。
- 创建迁移任务:通过源端和目的端的AK和SK创建迁移任务。
- 查询指定ID的迁移任务:根据迁移任务ID查询任务详情,确定迁移任务是否创建成功。
前提条件
- 已获取目的端AK/SK,参见创建访问密钥(AK/SK)。
操作步骤
- 获取IAM用户Token。
- 接口相关信息
详情请参见获取IAM用户Token(使用密码)。
- 请求示例
POST: https://{iam_endpoint}/v3/auth/tokens
{endpoint}信息请从地区和终端节点获取。
Body:{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", "domain": { "name": "domainname" }, "password": "******" } } }, "scope": { "project": { "id": "0215ef11e49d4743be23dd97a1561xxx" } } } }
响应Header中“X-Subject-Token”的值即为Token:
X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...
- 接口相关信息
- 上报源端服务器信息注册源端。
- 接口相关信息
POST /v3/sources
详情请参见上报源端服务器基本信息。
- 请求示例
POST https://sms.ap-southeast-1.myhuaweicloud.com/v3/sources
Header:
Content-Type: application/json X-Auth-Token: "Token"
Body:
{ "os_type": "LINUX", "name": "bike-centos", "os_version": "CENTOS_7_4_64BIT", "linux_block_check": "{\"release_type\": \"CENTOS\", \"release_version\": \"7.4.1708\", \"kernel_simplification\": \"3.10.0\", \"architecture\": \"x86_64\", \"kernel_version\": \"3.10.0-1062.1.1.el7.x86_64\"}", "kernel_version": "3.10.0-1062.1.1.el7.x86_64", "virtualization_type": "HVM", "paravirtualization": true, "firmware": "BIOS", "has_rsync": true, "boot_loader": "GRUB", "disks": [{ "name": "/dev/vda", "size": 42949672960, "device_use": "BOOT", "partition_style": "MBR", "physical_volumes": [{ "name": "/dev/vda1", "size": 42948624384, "device_use": "OS", "used_size": 2854862848, "inode_size": "256", "file_system": "ext4", "mount_point": "/" }] }], "volume_groups": [], "cpu_quantity": 1, "memory": 1038716928, "networks": [{ "name": "eth0", "ip": "192.168.77.77", "mac": "ef05f3911eeccb12a0a8931dc198af84e848b0e9e3edd0812805429fc649xxxx" }], "ip": "192.168.77.77", "agent_version": "1.2.3-beta" }
- 响应示例
{ "id": "33b798a8-4f80-49ce-8b8a-18a85adfe13e" }
- 接口相关信息
- 调用创建任务接口创建迁移任务。
- 接口相关信息
POST /v3/tasks
详情请参见创建迁移任务。
- 请求示例
POST https://sms.ap-southeast-1.myhuaweicloud.com/v3/tasks
Header:
Content-Type: application/json X-Auth-Token: "Token"
Body:
{ "auto_install_pvdriver" : true, "auto_start" : true, "syncing": false, "migration_ip" : "172.16.0.xxx", "name" : "MigrationTask", "os_type" : "WINDOWS", "project_id" : "05825205120026802xxxx01721bc1xxx", "project_name" : "project_name", "region_id" : "region_id", "region_name" : "region_name", "source_server" : { "id" : "9a01cb97-3eec-440e-xxxx-04016a8d7502" }, "start_target_server" : true, "target_server" : { "name" : "name", "vm_id" : "6dac09d8-5835-4888-xxxx-787453c4e1d4", "disks" : [{ "device_use" : "OS", "disk_id" : "354419d9-bd41-4b50-xxxx-e4f6f57c6xxx", "name" : "Disk 0", "physical_volumes" : [{ "device_use" : "BOOT", "file_system" : "NTFS", "index" : 1, "name" : "(Reserved)", "size" : 367001600, "used_size" : 31244288, "uuid" : "\\\\?\\Volume{b99b1c6f-75ef-xxxx-80b3-806e6f6e6963}\\" }, { "device_use" : "OS", "file_system" : "NTFS", "index" : 2, "name" : "C:\\", "size" : 42580574208, "used_size" : 16148279296, "uuid" : "\\\\?\\Volume{b99b1c70-75ef-xxxx-80b3-806e6f6e6963}\\" } ], "size" : 42949672960, "used_size" : 42949672960 }, { "device_use" : "NORMAL", "disk_id" : "ef409e5f-2321-49d1-xxxx-027fc93985ef", "name" : "Disk 1", "physical_volumes" : [{ "file_system" : "NTFS", "index" : 1, "name" : "D:\\", "size" : 53684994048, "used_size" : 3462647808, "uuid" : "\\\\?\\Volume{9f817be3-2cea-xxxx-816f-e995816380e2}\\" } ], "size" : 53687091200, "used_size" : 53687091200 } ], "btrfs_list" : null }, "type" : "MIGRATE_BLOCK", "use_public_ip" : false }
- 响应示例
{ "id": "8abda8635e09d185015e09d188dd0001xx" }
- 接口相关信息
- 调用查看任务接口,查看任务状态。
- 接口相关信息
GET /v3/tasks/{task_id}
详情请参见查询指定ID的迁移任务。
- 请求示例
GET https://sms.ap-southeast-1.myhuaweicloud.com/v3/tasks/8abda8635e09d185015e09d188dd0001xx
Header:
Content-Type: application/json X-Auth-Token: “Token”
- 响应示例
{ "id": "8abda8635e09d185015e09d188dd0001xx", "name": "MigrationTask", "type": "MIGRATE_FILE", "os_type": "LINUX", "state": "READY", "estimate_complete_time": 1600391014000, "create_date": 1600159831000, "start_date": 1600159831000, "finish_date": 1600343128000, "priority": 1, "speed_limit": 0, "migrate_speed": 0, "start_target_server": true, "error_json": "", "total_time": 935000, "float_ip": "192.168.0.xxx", "migration_ip": "192.168.0.xxx", "vm_template_id": null, "region_name": "region_name", "region_id": "region_id", "project_name": "project_name", "project_id": "05825205120026802ff0c01721bc1xxx", "sub_tasks": [ { "id": 3514, "name": "SSL_CONFIG", "progress": 100, "start_date": 1600159847000, "end_date": 1600159851000, "user_op": "REPLICATE" }, { "id": 3515, "name": "ATTACH_AGENT_IMAGE", "progress": 100, "start_date": 1600159851000, "end_date": 1600160027000, "user_op": "REPLICATE" }, { "id": 3516, "name": "FORMAT_DISK_LINUX_FILE", "progress": 100, "start_date": 1600160027000, "end_date": 1600160030000, "user_op": "REPLICATE" }, { "id": 3517, "name": "MIGRATE_LINUX_FILE", "progress": 100, "start_date": 1600160080000, "end_date": 1600160088000, "user_op": "REPLICATE" }, { "id": 3582, "name": "CONFIGURE_LINUX_FILE", "progress": 100, "start_date": 1600333914000, "end_date": 1600334025000, "user_op": "CUTOVER0" }, { "id": 3583, "name": "DETTACH_AGENT_IMAGE", "progress": 100, "start_date": 1600334029000, "end_date": 1600334103000, "user_op": "CUTOVER0" }, { "id": 3584, "name": "SSL_CONFIG", "progress": 100, "start_date": 1600334185000, "end_date": 1600334188000, "user_op": "RESYNC0" }, { "id": 3585, "name": "ATTACH_AGENT_IMAGE", "progress": 100, "start_date": 1600334189000, "end_date": 1600334375000, "user_op": "RESYNC0" }, { "id": 3586, "name": "SYNC_LINUX_FILE", "progress": 100, "start_date": 1600334375000, "end_date": 1600334376000, "user_op": "RESYNC0" }, { "id": 3587, "name": "CONFIGURE_LINUX_FILE", "progress": 100, "start_date": 1600342952000, "end_date": 1600343052000, "user_op": "CUTOVER1" }, { "id": 3588, "name": "DETTACH_AGENT_IMAGE", "progress": 100, "start_date": 1600343056000, "end_date": 1600343128000, "user_op": "CUTOVER1" }, { "id": 3589, "name": "SSL_CONFIG", "progress": 100, "start_date": 1600390756000, "end_date": 1600390760000, "user_op": "RESYNC1" }, { "id": 3590, "name": "ATTACH_AGENT_IMAGE", "progress": 100, "start_date": 1600390760000, "end_date": 1600390953000, "user_op": "RESYNC1" }, { "id": 3591, "name": "SYNC_LINUX_FILE", "progress": 100, "start_date": 1600390954000, "end_date": 1600390954000, "user_op": "RESYNC1" } ], "source_server": { "id": "621f2cb5-ba4f-4819-b00d-ee48ca2c3xxx", "ip": "192.168.0.176", "name": "ecs-4bb4", "os_type": "LINUX", "os_version": "CENTOS_7_6_64BIT", "oem_system": false, "state": "syncing", "migration_cycle": "syncing" }, "target_server": { "id": "de35f45d-b6d5-4769-9148-984c8fab4xxx", "vm_id": "6d51477f-0a02-4917-8d7d-b13969f4axxx", "name": "ecs-4bb4", "ip": null, "os_type": "LINUX", "os_version": null, "system_dir": null, "disks": [ { "id": 86364, "name": "/dev/sda", "relation_name": "/dev/vda", "disk_id": "ed3c78d0-3166-48d1-bee0-d29e7d834xxx", "partition_style": "MBR", "size": 42949672960, "used_size": 42948624384, "device_use": "BOOT", "os_disk": false, "physical_volumes": [ { "id": 132594, "uuid": null, "index": 0, "name": "/dev/sda1", "relation_name": "/dev/vda1", "device_use": "OS", "file_system": "ext4", "mount_point": "/", "size": 42948624384, "used_size": 2467393536, "free_size": 40481230848 } ], "disk_index": "z" } ], "volume_groups": [], "image_disk_id": "9700f5ce-02ae-4a71-a057-deffe9b69xxx", "rollback_snapshot_ids": null }, "clone_server": null, "target_snapshot_id": null, "remain_seconds": 60000 }
state表示任务执行状态,READY代表任务准备就绪。
- 接口相关信息