文档首页/ 主机迁移服务 SMS/ API参考/ 应用示例/ 示例二:启动迁移任务
更新时间:2023-11-29 GMT+08:00
分享

示例二:启动迁移任务

场景描述

本章节指导用户通过API启动迁移任务。API的调用方法请参见如何调用API

启动迁移任务前需要获取Token,启动迁移任务后,需要查询任务状态详情,失败或暂停中的任务才能被启动。

涉及接口

操作步骤

  1. 获取IAM用户Token。

    • 接口相关信息

      URI格式:POST /v3/auth/tokens

      详情请参见获取IAM用户Token(使用密码)

    • 请求示例
      POST: https://{iam_endpoint}/v3/auth/tokens

      {endpoint}信息请从地区和终端节点获取。

      Body:
      {
          "auth": {
              "identity": {
                  "methods": [
                      "password"
                  ],
                  "password": {
                      "user": {
                          "name": "testname",
                          "domain": {
                              "name": "testname"
                          },
                          "password": "Password"
                      }
                  }
              },
              "scope": {
                  "project": {
                      "id": "0215ef11e49d4743be23dd97a1561xxx"
                  }
              }
          }
      }

    响应Header中“X-Subject-Token”的值即为Token:

    X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...

  2. 调用启动任务接口启动迁移任务。

    • 接口相关信息

      URI格式:

      POST /v3/tasks/{task_id}/action

      详情请参见管理迁移任务(启动)

    • 请求示例
      POST  https://sms.ap-southeast-1.myhuaweicloud.com/v3/tasks/8abda8635e09d185015e09d188dd0001xx/action

      Header:

      Content-Type: application/json
      X-Auth-Token: “Token”

      Body:

      {
              "operation" : "start",
      }

      响应200表示调用成功。

  3. 调用查看任务接口,查看任务状态。

    • 接口相关信息

      URI格式:

      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": "RUNNING",
       "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.xxx",
        "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表示任务执行状态,RUNNING代表正在执行,MIGRATE_SUCCESS表示执行成功。

相关文档