文档首页> 主机迁移服务 SMS> API参考> API v3> 任务管理> 更新指定ID的迁移任务
更新时间:2024-03-01 GMT+08:00
分享

更新指定ID的迁移任务

功能介绍

更新指定ID的迁移任务

调用方法

请参见如何调用API

URI

PUT /v3/tasks/{task_id}

表1 路径参数

参数

是否必选

参数类型

描述

task_id

String

迁移任务ID

最小长度:0

最大长度:255

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

最小长度:1

最大长度:16384

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

任务名称(用户自定义)

最小长度:0

最大长度:255

type

String

任务类型,创建时必选,更新时可选 MIGRATE_FILE:文件级迁移 MIGRATE_BLOCK:块级迁移

最小长度:0

最大长度:255

枚举值:

  • MIGRATE_FILE
  • MIGRATE_BLOCK

os_type

String

操作系统类型,分为WINDOWS和LINUX,创建时必选,更新时可选

枚举值:

  • WINDOWS
  • LINUX

id

String

迁移任务ID

最小长度:0

最大长度:255

priority

Integer

进程优先级

0:低

1:标准(默认)

2:高

最小值:0

最大值:2

枚举值:

  • 0
  • 1
  • 2

region_id

String

目的端服务器的区域ID

最小长度:0

最大长度:255

start_target_server

Boolean

迁移完成后是否启动目的端服务器

true:启动

false:停止

缺省值:true

enterprise_project_id

String

企业项目ID

最小长度:1

最大长度:255

migration_ip

String

目的端服务器的IP地址。

公网迁移时请填写弹性IP地址

专线迁移时请填写私有IP地址

最小长度:0

最大长度:255

region_name

String

目的端服务器的区域名称

最小长度:0

最大长度:255

speed_limit

Integer

限制迁移速率,单位:Mbps

最小值:0

最大值:10000

project_name

String

目的端服务器所在项目名称

最小长度:0

最大长度:255

project_id

String

目的端服务器所在项目ID

最小长度:0

最大长度:255

vm_template_id

String

模板ID

最小长度:0

最大长度:255

source_server

PostSourceServerBody object

源端服务器

target_server

TargetServer object

目的端服务器

state

String

任务状态

最小长度:0

最大长度:255

estimate_complete_time

Long

预估完成时间

最小值:0

最大值:9223372036854775807

connected

Boolean

连接状态

create_date

Long

任务创建时间

最小值:0

最大值:9223372036854775807

start_date

Long

任务开始时间

最小值:0

最大值:9223372036854775807

finish_date

Long

任务结束时间

最小值:0

最大值:9223372036854775807

migrate_speed

Double

迁移速率,单位:MB/S

最小值:0

最大值:10000

error_json

String

错误信息

最小长度:0

最大长度:1024

total_time

Long

任务总耗时

最小值:0

最大值:9223372036854775807

float_ip

String

暂时保留float,兼容现网老版本的SMS-Agent

最小长度:0

最大长度:255

remain_seconds

Long

迁移剩余时间(秒)

最小值:0

最大值:9223372036854775807

target_snapshot_id

String

目的端的快照ID

最小长度:0

最大长度:255

clone_server

CloneServer object

克隆服务器类

sub_tasks

Array of SubTask objects

任务包含的子任务列表

数组长度:0 - 65535

表4 PostSourceServerBody

参数

是否必选

参数类型

描述

id

String

源端在SMS数据库中的ID

最小长度:0

最大长度:255

ip

String

源端服务器ip,注册源端时必选,更新非必选

最小长度:0

最大长度:255

name

String

用来区分不同源端服务器的名称

最小长度:0

最大长度:255

hostname

String

源端主机名,注册源端必选,更新非必选

最小长度:0

最大长度:255

os_type

String

源端服务器的OS类型,分为Windows和Linux,注册必选,更新非必选

最小长度:0

最大长度:255

枚举值:

  • WINDOWS
  • LINUX

os_version

String

操作系统版本,注册必选,更新非必选

最小长度:0

最大长度:255

virtualization_type

String

操作系统虚拟化方式

最小长度:0

最大长度:255

linux_block_check

String

Linux操作系统块检查

最小长度:0

最大长度:255

firmware

String

源端服务器启动类型,如BIOS或者UEFI

最小长度:0

最大长度:255

枚举值:

  • BIOS
  • UEFI

cpu_quantity

Integer

CPU个数,单位vCPU

最小值:0

最大值:65535

memory

Long

内存大小,单位MB

最小值:0

最大值:9223372036854775807

disks

Array of ServerDisk objects

源端服务器的磁盘信息

数组长度:0 - 65535

btrfs_list

Array of BtrfsFileSystem objects

Linux 必选,源端的Btrfs信息。如果源端不存在Btrfs,则为[]

数组长度:0 - 65535

networks

Array of NetWork objects

源端服务器的网卡信息

数组长度:0 - 65535

domain_id

String

租户的domainId

最小长度:0

最大长度:255

has_rsync

Boolean

是否安装rsync组件,Linux系统此参数为必选

paravirtualization

Boolean

Linux场景必选,源端是否是半虚拟化

raw_devices

String

Linux必选,裸设备列表

最小长度:0

最大长度:255

driver_files

Boolean

Windows 必选,是否缺少驱动文件

system_services

Boolean

Windows必选,是否存在不正常服务

account_rights

Boolean

Windows必选,权限是否满足要求

boot_loader

String

Linux必选,系统引导类型,BOOT_LOADER(GRUB/LILO)

枚举值:

  • GRUB
  • LILO

system_dir

String

Windows必选,系统目录

最小长度:0

最大长度:255

volume_groups

Array of VolumeGroups objects

Linux必选,如果没有卷组,输入[]

数组长度:0 - 65535

agent_version

String

Agent版本

最小长度:0

最大长度:255

kernel_version

String

内核版本信息

最小长度:0

最大长度:255

migration_cycle

String

迁移周期 cutovering:启动目的端中 cutovered:启动目的端完成 checking:检查中 setting:设置中 replicating:复制中 syncing:同步中

枚举值:

  • cutovering
  • cutovered
  • checking
  • setting
  • replicating
  • syncing

state

String

源端服务器状态 unavailable:环境校验不通过 waiting:等待 initialize:初始化 replicate:复制 syncing:持续同步 stopping:暂停中 stopped:已暂停 deleting:删除中 error:错误 cloning:等待克隆完成 cutovering:启动目的端中 finished:启动目的端完成

最小长度:0

最大长度:255

枚举值:

  • unavailable
  • waiting
  • initialize
  • replicate
  • syncing
  • stopping
  • stopped
  • deleting
  • error
  • cloning
  • cutovering
  • finished

oem_system

Boolean

是否是OEM操作系统(Windows)

start_type

String

启动方式,可以取值MANUAL、MGC或者空。

枚举值:

  • MANUAL
  • MGC
表5 ServerDisk

参数

是否必选

参数类型

描述

name

String

磁盘名称

最小长度:0

最大长度:255

partition_style

String

磁盘的分区类型,添加源端时源端磁盘必选 MBR:mbr格式 GPT:gpt格式

枚举值:

  • MBR
  • GPT

device_use

String

磁盘类型 BOOT:BOOT设备 OS:系统设备

枚举值:

  • BOOT
  • OS

size

Long

磁盘总大小,以字节为单位

最小值:0

最大值:9223372036854775807

used_size

Long

磁盘已使用大小,以字节为单位

最小值:0

最大值:9223372036854775807

physical_volumes

Array of PhysicalVolume objects

磁盘上的物理分区信息

数组长度:0 - 65535

os_disk

Boolean

是否为系统盘

relation_name

String

Linux系统 目的端ECS中与源端关联的磁盘名称

最小长度:0

最大长度:255

inode_size

Integer

inode数量

最小值:0

最大值:4294967296

表6 PhysicalVolume

参数

是否必选

参数类型

描述

device_use

String

分区类型,普通分区,启动分区,系统分区

最小长度:0

最大长度:255

file_system

String

文件系统类型

最小长度:0

最大长度:255

index

Integer

顺序

最小值:0

最大值:2147483647

mount_point

String

挂载点

最小长度:0

最大长度:255

name

String

名称,windows表示盘符,Linux表示设备号

最小长度:0

最大长度:255

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

inode_size

Integer

inode数量

最小值:0

最大值:4294967296

uuid

String

GUID,可从源端查询

最小长度:0

最大长度:255

size_per_cluster

Integer

每个cluster大小

最小值:0

最大值:2147483647

表7 BtrfsFileSystem

参数

是否必选

参数类型

描述

name

String

文件系统名称

最小长度:0

最大长度:255

label

String

文件系统标签,若无标签为空字符串

最小长度:0

最大长度:255

uuid

String

文件系统的uuid

最小长度:0

最大长度:255

device

String

btrfs包含的设备名称

最小长度:0

最大长度:255

size

Long

文件系统数据占用大小

最小值:0

最大值:9223372036854775807

nodesize

Long

btrfs节点大小

最小值:0

最大值:9223372036854775807

sectorsize

Integer

扇区大小

最小值:0

最大值:2147483647

data_profile

String

数据配置(RAD)

最小长度:0

最大长度:255

system_profile

String

文件系统配置(RAD)

最小长度:0

最大长度:255

metadata_profile

String

元数据配置(RAD)

最小长度:0

最大长度:255

global_reserve1

String

Btrfs文件系统信息

最小长度:0

最大长度:255

g_vol_used_size

Long

Btrfs卷已使用空间大小

最小值:0

最大值:9223372036854775807

default_subvolid

String

默认子卷ID

最小长度:0

最大长度:255

default_subvol_name

String

默认子卷名称

最小长度:0

最大长度:255

default_subvol_mountpath

String

默认子卷挂载路径/BTRFS文件系统的挂载路径

最小长度:0

最大长度:255

subvolumn

Array of BtrfsSubvolumn objects

子卷信息

数组长度:0 - 65535

表8 BtrfsSubvolumn

参数

是否必选

参数类型

描述

uuid

String

父卷的uuid

最小长度:0

最大长度:255

is_snapshot

String

子卷是否为快照

最小长度:0

最大长度:255

subvol_id

String

子卷的ID

最小长度:0

最大长度:255

parent_id

String

父卷ID

最小长度:0

最大长度:255

subvol_name

String

子卷的名称

最小长度:0

最大长度:255

subvol_mount_path

String

子卷的挂载路径

最小长度:0

最大长度:255

表9 TargetServer

参数

是否必选

参数类型

描述

id

String

源端在SMS数据库中的ID

最小长度:0

最大长度:255

ip

String

源端服务器IP,注册源端时必选,更新非必选

最小长度:0

最大长度:255

name

String

目的端服务器名称

最小长度:0

最大长度:255

hostname

String

源端主机名,注册源端必选,更新非必选

最小长度:0

最大长度:255

os_type

String

源端服务器的OS类型,分为Windows和Linux,注册必选,更新非必选

最小长度:0

最大长度:255

枚举值:

  • WINDOWS
  • LINUX

os_version

String

操作系统版本,注册必选,更新非必选

最小长度:0

最大长度:255

firmware

String

源端服务器启动类型,如BIOS或者UEFI

最小长度:0

最大长度:255

枚举值:

  • BIOS
  • UEFI

cpu_quantity

Integer

CPU个数,单位vCPU

最小值:0

最大值:65535

memory

Long

内存大小,单位MB

最小值:0

最大值:9223372036854775807

disks

Array of TargetDisk objects

目的端磁盘信息,一般和源端保持一致

数组长度:0 - 65535

btrfs_list

Array of strings

Linux 必选,源端的Btrfs信息。如果源端不存在Btrfs,则为[]

最小长度:0

最大长度:255

数组长度:0 - 65535

networks

Array of NetWork objects

源端服务器的网卡信息

数组长度:0 - 65535

domain_id

String

租户的domainId

最小长度:0

最大长度:255

has_rsync

Boolean

是否安装rsync组件,Linux系统此参数为必选

paravirtualization

Boolean

Linux场景必选,源端是否是半虚拟化

raw_devices

String

Linux必选,裸设备列表

最小长度:0

最大长度:255

driver_files

Boolean

Windows 必选,是否缺少驱动文件

system_services

Boolean

Windows必选,是否存在不正常服务

account_rights

Boolean

Windows必选,权限是否满足要求

boot_loader

String

Linux必选,系统引导类型,BOOT_LOADER(GRUB/LILO)

枚举值:

  • GRUB
  • LILO

system_dir

String

Windows必选,系统目录

最小长度:0

最大长度:255

volume_groups

Array of VolumeGroups objects

lvm信息,一般和源端保持一致

数组长度:0 - 65535

vm_id

String

目的端服务器ID,自动创建虚拟机不需要这个参数

最小长度:0

最大长度:255

flavor

String

目的端服务器的规格

最小长度:0

最大长度:255

image_disk_id

String

目的端代理镜像磁盘ID

最小长度:0

最大长度:255

snapshot_ids

String

目的端快照ID

最小长度:0

最大长度:255

cutovered_snapshot_ids

String

目的端回滚快照ID

最小长度:0

最大长度:255

表10 TargetDisk

参数

是否必选

参数类型

描述

id

Long

磁盘标识ID

最小值:0

最大值:9223372036854775807

device_use

String

判断是普通分区,启动分区还是系统分区 BOOT:BOOT设备 OS:系统设备 NORMAL:平常

缺省值:NORMAL

枚举值:

  • NORMAL
  • OS
  • BOOT

disk_id

String

磁盘ID

最小长度:0

最大长度:255

name

String

磁盘名称

最小长度:0

最大长度:255

physical_volumes

Array of TargetPhysicalVolumes objects

逻辑卷信息

数组长度:0 - 65535

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

已使用大小

最小值:0

最大值:9223372036854775807

disk_index

String

磁盘索引

最小长度:0

最大长度:255

os_disk

Boolean

是否为系统盘

partition_style

String

磁盘的分区类型,添加源端时源端磁盘必选 MBR:mbr格式 GPT:gpt格式

枚举值:

  • MBR
  • GPT

relation_name

String

Linux系统 目的端ECS中与源端关联的磁盘名称

最小长度:0

最大长度:255

表11 TargetPhysicalVolumes

参数

是否必选

参数类型

描述

id

Long

逻辑卷ID

最小值:0

最大值:9223372036854775807

device_use

String

分区类型 NORMAL:平常 OS:系统设备 BOOT:BOOT设备

缺省值:NORMAL

枚举值:

  • NORMAL
  • OS
  • BOOT

file_system

String

文件系统

最小长度:0

最大长度:255

index

Integer

编号

最小值:0

最大值:2147483647

mount_point

String

挂载点

最小长度:0

最大长度:255

name

String

名称

最小长度:0

最大长度:255

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

uuid

String

uuid

最小长度:0

最大长度:255

relation_name

String

Linux系统 目的端ECS中与源端关联的磁盘名称

最小长度:0

最大长度:255

free_size

Long

分区空闲大小

最小值:0

最大值:9223372036854775807

表12 NetWork

参数

是否必选

参数类型

描述

name

String

网卡的名称

最小长度:0

最大长度:255

ip

String

该网卡绑定的IP

最小长度:0

最大长度:255

netmask

String

掩码

最小长度:0

最大长度:255

gateway

String

网关

最小长度:0

最大长度:255

mtu

Integer

Linux必选,网卡的MTU

最小值:0

最大值:2147483647

mac

String

Mac地址

最小长度:0

最大长度:255

id

String

数据库ID

最小长度:0

最大长度:255

表13 VolumeGroups

参数

是否必选

参数类型

描述

components

String

Pv信息

最小长度:0

最大长度:255

free_size

Long

剩余空间

最小值:0

最大值:9223372036854775807

logical_volumes

Array of LogicalVolumes objects

lv信息

数组长度:0 - 255

name

String

名称

最小长度:0

最大长度:255

size

Long

大小

最小值:0

最大值:9223372036854775807

表14 LogicalVolumes

参数

是否必选

参数类型

描述

block_count

Integer

块数量

最小值:0

最大值:4294967296

缺省值:0

block_size

Long

块大小

最小值:0

最大值:1048576

缺省值:0

file_system

String

文件系统

最小长度:0

最大长度:255

inode_size

Integer

inode数量

最小值:0

最大值:4294967296

device_use

String

分区类型,普通分区,启动分区,系统分区

最小长度:0

最大长度:255

mount_point

String

挂载点

最小长度:0

最大长度:256

name

String

名称

最小长度:0

最大长度:1024

size

Long

大小

最小值:0

最大值:9223372036854775807

used_size

Long

使用大小

最小值:0

最大值:9223372036854775807

free_size

Long

剩余空间

最小值:0

最大值:9223372036854775807

表15 CloneServer

参数

是否必选

参数类型

描述

vm_id

String

克隆服务器ID

最小长度:0

最大长度:255

name

String

克隆虚拟机的名称

最小长度:0

最大长度:255

clone_error

String

克隆错误信息

最小长度:0

最大长度:255

clone_state

String

克隆状态

最小长度:0

最大长度:255

error_msg

String

克隆错误信息描述

最小长度:0

最大长度:1024

表16 SubTask

参数

是否必选

参数类型

描述

id

Long

子任务ID

最小值:0

最大值:9223372036854775807

name

String

子任务名称

最小长度:0

最大长度:255

progress

Integer

子任务的进度,取值为0-100之间的整数

最小值:0

最大值:100

start_date

Long

子任务开始时间

最小值:0

最大值:9223372036854775807

end_date

Long

子任务结束时间(如果子任务还没有结束,则为空)

最小值:0

最大值:9223372036854775807

migrate_speed

Double

迁移速率,Mbit/s

最小值:0

最大值:10000

user_op

String

触发子任务的用户操作名称

最小长度:0

最大长度:50

process_trace

String

迁移或同步时,具体的迁移详情

最小长度:0

最大长度:2048

响应参数

请求示例

更新任务ID为ef3b9722-07a0-40ae-89b0-889ee96dxxxx的迁移任务的信息。

put https://{endpoint}/v3/tasks/ef3b9722-07a0-40ae-89b0-889ee96dxxxx

{
  "name" : "MigrationTask",
  "type" : "MIGRATE_BLOCK",
  "os_type" : "WINDOWS",
  "state" : "RUNNING",
  "estimate_complete_time" : null,
  "create_date" : 1598435778000,
  "start_date" : 1598435784000,
  "finish_date" : null,
  "priority" : 1,
  "speed_limit" : 0,
  "migrate_speed" : 0.0,
  "start_target_server" : true,
  "error_json" : "",
  "total_time" : 115,
  "float_ip" : null,
  "migration_ip" : null,
  "vm_template_id" : "38d53ae9-70e3-4587-89c9-6219d3d4e962",
  "region_name" : "region name",
  "region_id" : "region id",
  "project_name" : "project name",
  "project_id" : "b276e6fb38c74aa2ba4598f049745ce9",
  "sub_tasks" : [ {
    "id" : 7278,
    "name" : "CREATE_CLOUD_SERVER",
    "progress" : 0,
    "start_date" : 1598435802000,
    "end_date" : null,
    "user_op" : "REPLICATE"
  }, {
    "id" : 7279,
    "name" : "SSL_CONFIG",
    "progress" : 0,
    "start_date" : null,
    "end_date" : null,
    "user_op" : "REPLICATE"
  }, {
    "id" : 7280,
    "name" : "ATTACH_AGENT_IMAGE",
    "progress" : 0,
    "start_date" : null,
    "end_date" : null,
    "user_op" : "REPLICATE"
  }, {
    "id" : 7281,
    "name" : "FORMAT_DISK_WINDOWS",
    "progress" : 0,
    "start_date" : null,
    "end_date" : null,
    "user_op" : "REPLICATE"
  }, {
    "id" : 7282,
    "name" : "MIGRATE_WINDOWS_BLOCK",
    "progress" : 0,
    "start_date" : null,
    "end_date" : null,
    "user_op" : "REPLICATE"
  } ],
  "source_server" : {
    "id" : "1cce5dab-df33-4abe-b2ac-e94fa05d6a01",
    "ip" : "192.168.0.154",
    "name" : "name-win16",
    "os_type" : "WINDOWS",
    "os_version" : "WINDOWS2016_64BIT",
    "agent_version" : "1.2.0",
    "oem_system" : false,
    "state" : "initialize",
    "migration_cycle" : "replicating"
  },
  "target_server" : {
    "id" : "c1bd67b6-1caa-403e-9e32-81d2feafcda9",
    "vm_id" : "",
    "name" : "",
    "ip" : null,
    "os_type" : "WINDOWS",
    "os_version" : "WINDOWS2016_64BIT",
    "system_dir" : "Y:\\Windows\\System32",
    "disks" : [ {
      "id" : 88008,
      "name" : "Disk 1",
      "relation_name" : null,
      "disk_id" : "0",
      "partition_style" : "MBR",
      "size" : 42949672960,
      "used_size" : 42947575808,
      "device_use" : "OS",
      "os_disk" : true,
      "physical_volumes" : [ {
        "id" : 135055,
        "uuid" : "\\\\?\\Volume{586b7157-0000-0000-0000-100000000000}\\",
        "index" : 1,
        "name" : "Z:",
        "relation_name" : null,
        "device_use" : "BOOT",
        "file_system" : "NTFS",
        "mount_point" : null,
        "size" : 524288000,
        "used_size" : 410275840,
        "free_size" : 114012160
      }, {
        "id" : 135056,
        "uuid" : "\\\\?\\Volume{586b7157-0000-0000-0000-501f00000000}\\",
        "index" : 2,
        "name" : "Y:",
        "relation_name" : null,
        "device_use" : "OS",
        "file_system" : "NTFS",
        "mount_point" : null,
        "size" : 42423287808,
        "used_size" : 23170301952,
        "free_size" : 19252985856
      } ],
      "disk_index" : "0"
    } ],
    "volume_groups" : [ ],
    "image_disk_id" : null,
    "cutovered_snapshot_ids" : null
  },
  "clone_server" : null
}

响应示例

状态码: 200

OK

{
  "id" : "1dcbf9f2-9f2a-4df5-88dc-27a5614a1187"
}

SDK代码示例

SDK代码示例如下。

更新任务ID为ef3b9722-07a0-40ae-89b0-889ee96dxxxx的迁移任务的信息。

  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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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 UpdateTaskSolution {

    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();
        UpdateTaskRequest request = new UpdateTaskRequest();
        PutTaskReq body = new PutTaskReq();
        List<SubTask> listbodySubTasks = new ArrayList<>();
        listbodySubTasks.add(
            new SubTask()
                .withId(7278L)
                .withName("CREATE_CLOUD_SERVER")
                .withProgress(0)
                .withStartDate(1598435802000L)
                .withUserOp("REPLICATE")
        );
        listbodySubTasks.add(
            new SubTask()
                .withId(7279L)
                .withName("SSL_CONFIG")
                .withProgress(0)
                .withUserOp("REPLICATE")
        );
        listbodySubTasks.add(
            new SubTask()
                .withId(7280L)
                .withName("ATTACH_AGENT_IMAGE")
                .withProgress(0)
                .withUserOp("REPLICATE")
        );
        listbodySubTasks.add(
            new SubTask()
                .withId(7281L)
                .withName("FORMAT_DISK_WINDOWS")
                .withProgress(0)
                .withUserOp("REPLICATE")
        );
        listbodySubTasks.add(
            new SubTask()
                .withId(7282L)
                .withName("MIGRATE_WINDOWS_BLOCK")
                .withProgress(0)
                .withUserOp("REPLICATE")
        );
        List<TargetPhysicalVolumes> listDisksPhysicalVolumes = new ArrayList<>();
        listDisksPhysicalVolumes.add(
            new TargetPhysicalVolumes()
                .withId(135055L)
                .withDeviceUse(TargetPhysicalVolumes.DeviceUseEnum.fromValue("BOOT"))
                .withFileSystem("NTFS")
                .withIndex(1)
                .withName("Z:")
                .withSize(524288000L)
                .withUsedSize(410275840L)
                .withUuid("\\?\Volume{586b7157-0000-0000-0000-100000000000}\")
                .withFreeSize(114012160L)
        );
        listDisksPhysicalVolumes.add(
            new TargetPhysicalVolumes()
                .withId(135056L)
                .withDeviceUse(TargetPhysicalVolumes.DeviceUseEnum.fromValue("OS"))
                .withFileSystem("NTFS")
                .withIndex(2)
                .withName("Y:")
                .withSize(42423287808L)
                .withUsedSize(23170301952L)
                .withUuid("\\?\Volume{586b7157-0000-0000-0000-501f00000000}\")
                .withFreeSize(19252985856L)
        );
        List<TargetDisk> listTargetServerDisks = new ArrayList<>();
        listTargetServerDisks.add(
            new TargetDisk()
                .withId(88008L)
                .withDeviceUse(TargetDisk.DeviceUseEnum.fromValue("OS"))
                .withDiskId("0")
                .withName("Disk 1")
                .withPhysicalVolumes(listDisksPhysicalVolumes)
                .withSize(42949672960L)
                .withUsedSize(42947575808L)
                .withDiskIndex("0")
                .withOsDisk(true)
                .withPartitionStyle(TargetDisk.PartitionStyleEnum.fromValue("MBR"))
        );
        TargetServer targetServerbody = new TargetServer();
        targetServerbody.withDisks(listTargetServerDisks)
            .withVolumeGroups()
            .withVmId("")
            .withId("c1bd67b6-1caa-403e-9e32-81d2feafcda9")
            .withOsVersion("WINDOWS2016_64BIT")
            .withSystemDir("Y:\Windows\System32")
            .withOsType(TargetServer.OsTypeEnum.fromValue("WINDOWS"))
            .withName("");
        PostSourceServerBody sourceServerbody = new PostSourceServerBody();
        sourceServerbody.withId("1cce5dab-df33-4abe-b2ac-e94fa05d6a01")
            .withIp("192.168.0.154")
            .withName("name-win16")
            .withOsType(PostSourceServerBody.OsTypeEnum.fromValue("WINDOWS"))
            .withOsVersion("WINDOWS2016_64BIT")
            .withAgentVersion("1.2.0")
            .withMigrationCycle(PostSourceServerBody.MigrationCycleEnum.fromValue("replicating"))
            .withState(PostSourceServerBody.StateEnum.fromValue("initialize"))
            .withOemSystem(false);
        body.withSubTasks(listbodySubTasks);
        body.withTotalTime(115L);
        body.withErrorJson("");
        body.withMigrateSpeed((double)0.0);
        body.withStartDate(1598435784000L);
        body.withCreateDate(1598435778000L);
        body.withState("RUNNING");
        body.withTargetServer(targetServerbody);
        body.withSourceServer(sourceServerbody);
        body.withVmTemplateId("38d53ae9-70e3-4587-89c9-6219d3d4e962");
        body.withProjectId("b276e6fb38c74aa2ba4598f049745ce9");
        body.withProjectName("project name");
        body.withSpeedLimit(0);
        body.withRegionName("region name");
        body.withStartTargetServer(true);
        body.withRegionId("region id");
        body.withPriority(PutTaskReq.PriorityEnum.NUMBER_1);
        body.withOsType(PutTaskReq.OsTypeEnum.fromValue("WINDOWS"));
        body.withType(PutTaskReq.TypeEnum.fromValue("MIGRATE_BLOCK"));
        body.withName("MigrationTask");
        request.withBody(body);
        try {
            UpdateTaskResponse response = client.updateTask(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为ef3b9722-07a0-40ae-89b0-889ee96dxxxx的迁移任务的信息。

  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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# coding: utf-8

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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = GlobalCredentials(ak, sk) \

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

    try:
        request = UpdateTaskRequest()
        listSubTasksbody = [
            SubTask(
                id=7278,
                name="CREATE_CLOUD_SERVER",
                progress=0,
                start_date=1598435802000,
                user_op="REPLICATE"
            ),
            SubTask(
                id=7279,
                name="SSL_CONFIG",
                progress=0,
                user_op="REPLICATE"
            ),
            SubTask(
                id=7280,
                name="ATTACH_AGENT_IMAGE",
                progress=0,
                user_op="REPLICATE"
            ),
            SubTask(
                id=7281,
                name="FORMAT_DISK_WINDOWS",
                progress=0,
                user_op="REPLICATE"
            ),
            SubTask(
                id=7282,
                name="MIGRATE_WINDOWS_BLOCK",
                progress=0,
                user_op="REPLICATE"
            )
        ]
        listPhysicalVolumesDisks = [
            TargetPhysicalVolumes(
                id=135055,
                device_use="BOOT",
                file_system="NTFS",
                index=1,
                name="Z:",
                size=524288000,
                used_size=410275840,
                uuid="\\?\Volume{586b7157-0000-0000-0000-100000000000}\",
                free_size=114012160
            ),
            TargetPhysicalVolumes(
                id=135056,
                device_use="OS",
                file_system="NTFS",
                index=2,
                name="Y:",
                size=42423287808,
                used_size=23170301952,
                uuid="\\?\Volume{586b7157-0000-0000-0000-501f00000000}\",
                free_size=19252985856
            )
        ]
        listDisksTargetServer = [
            TargetDisk(
                id=88008,
                device_use="OS",
                disk_id="0",
                name="Disk 1",
                physical_volumes=listPhysicalVolumesDisks,
                size=42949672960,
                used_size=42947575808,
                disk_index="0",
                os_disk=True,
                partition_style="MBR"
            )
        ]
        targetServerbody = TargetServer(
            disks=listDisksTargetServer,
            vm_id="",
            id="c1bd67b6-1caa-403e-9e32-81d2feafcda9",
            os_version="WINDOWS2016_64BIT",
            system_dir="Y:\Windows\System32",
            os_type="WINDOWS",
            name=""
        )
        sourceServerbody = PostSourceServerBody(
            id="1cce5dab-df33-4abe-b2ac-e94fa05d6a01",
            ip="192.168.0.154",
            name="name-win16",
            os_type="WINDOWS",
            os_version="WINDOWS2016_64BIT",
            agent_version="1.2.0",
            migration_cycle="replicating",
            state="initialize",
            oem_system=False
        )
        request.body = PutTaskReq(
            sub_tasks=listSubTasksbody,
            total_time=115,
            error_json="",
            migrate_speed=0.0,
            start_date=1598435784000,
            create_date=1598435778000,
            state="RUNNING",
            target_server=targetServerbody,
            source_server=sourceServerbody,
            vm_template_id="38d53ae9-70e3-4587-89c9-6219d3d4e962",
            project_id="b276e6fb38c74aa2ba4598f049745ce9",
            project_name="project name",
            speed_limit=0,
            region_name="region name",
            start_target_server=True,
            region_id="region id",
            priority=1,
            os_type="WINDOWS",
            type="MIGRATE_BLOCK",
            name="MigrationTask"
        )
        response = client.update_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)

更新任务ID为ef3b9722-07a0-40ae-89b0-889ee96dxxxx的迁移任务的信息。

  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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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.UpdateTaskRequest{}
	idSubTasks:= int64(7278)
	nameSubTasks:= "CREATE_CLOUD_SERVER"
	startDateSubTasks:= int64(1598435802000)
	userOpSubTasks:= "REPLICATE"
	idSubTasks1:= int64(7279)
	nameSubTasks1:= "SSL_CONFIG"
	userOpSubTasks1:= "REPLICATE"
	idSubTasks2:= int64(7280)
	nameSubTasks2:= "ATTACH_AGENT_IMAGE"
	userOpSubTasks2:= "REPLICATE"
	idSubTasks3:= int64(7281)
	nameSubTasks3:= "FORMAT_DISK_WINDOWS"
	userOpSubTasks3:= "REPLICATE"
	idSubTasks4:= int64(7282)
	nameSubTasks4:= "MIGRATE_WINDOWS_BLOCK"
	userOpSubTasks4:= "REPLICATE"
	var listSubTasksbody = []model.SubTask{
        {
            Id: &idSubTasks,
            Name: &nameSubTasks,
            Progress: int32(0),
            StartDate: &startDateSubTasks,
            UserOp: &userOpSubTasks,
        },
        {
            Id: &idSubTasks1,
            Name: &nameSubTasks1,
            Progress: int32(0),
            UserOp: &userOpSubTasks1,
        },
        {
            Id: &idSubTasks2,
            Name: &nameSubTasks2,
            Progress: int32(0),
            UserOp: &userOpSubTasks2,
        },
        {
            Id: &idSubTasks3,
            Name: &nameSubTasks3,
            Progress: int32(0),
            UserOp: &userOpSubTasks3,
        },
        {
            Id: &idSubTasks4,
            Name: &nameSubTasks4,
            Progress: int32(0),
            UserOp: &userOpSubTasks4,
        },
    }
	idPhysicalVolumes:= int64(135055)
	deviceUsePhysicalVolumes:= model.GetTargetPhysicalVolumesDeviceUseEnum().BOOT
	fileSystemPhysicalVolumes:= "NTFS"
	indexPhysicalVolumes:= int32(1)
	namePhysicalVolumes:= "Z:"
	sizePhysicalVolumes:= int64(524288000)
	usedSizePhysicalVolumes:= int64(410275840)
	uuidPhysicalVolumes:= "\\?\Volume{586b7157-0000-0000-0000-100000000000}\"
	freeSizePhysicalVolumes:= int64(114012160)
	idPhysicalVolumes1:= int64(135056)
	deviceUsePhysicalVolumes1:= model.GetTargetPhysicalVolumesDeviceUseEnum().OS
	fileSystemPhysicalVolumes1:= "NTFS"
	indexPhysicalVolumes1:= int32(2)
	namePhysicalVolumes1:= "Y:"
	sizePhysicalVolumes1:= int64(42423287808)
	usedSizePhysicalVolumes1:= int64(23170301952)
	uuidPhysicalVolumes1:= "\\?\Volume{586b7157-0000-0000-0000-501f00000000}\"
	freeSizePhysicalVolumes1:= int64(19252985856)
	var listPhysicalVolumesDisks = []model.TargetPhysicalVolumes{
        {
            Id: &idPhysicalVolumes,
            DeviceUse: &deviceUsePhysicalVolumes,
            FileSystem: &fileSystemPhysicalVolumes,
            Index: &indexPhysicalVolumes,
            Name: &namePhysicalVolumes,
            Size: &sizePhysicalVolumes,
            UsedSize: &usedSizePhysicalVolumes,
            Uuid: &uuidPhysicalVolumes,
            FreeSize: &freeSizePhysicalVolumes,
        },
        {
            Id: &idPhysicalVolumes1,
            DeviceUse: &deviceUsePhysicalVolumes1,
            FileSystem: &fileSystemPhysicalVolumes1,
            Index: &indexPhysicalVolumes1,
            Name: &namePhysicalVolumes1,
            Size: &sizePhysicalVolumes1,
            UsedSize: &usedSizePhysicalVolumes1,
            Uuid: &uuidPhysicalVolumes1,
            FreeSize: &freeSizePhysicalVolumes1,
        },
    }
	idDisks:= int64(88008)
	deviceUseDisks:= model.GetTargetDiskDeviceUseEnum().OS
	diskIdDisks:= "0"
	nameDisks:= "Disk 1"
	sizeDisks:= int64(42949672960)
	usedSizeDisks:= int64(42947575808)
	diskIndexDisks:= "0"
	osDiskDisks:= true
	partitionStyleDisks:= model.GetTargetDiskPartitionStyleEnum().MBR
	var listDisksTargetServer = []model.TargetDisk{
        {
            Id: &idDisks,
            DeviceUse: &deviceUseDisks,
            DiskId: &diskIdDisks,
            Name: &nameDisks,
            PhysicalVolumes: &listPhysicalVolumesDisks,
            Size: &sizeDisks,
            UsedSize: &usedSizeDisks,
            DiskIndex: &diskIndexDisks,
            OsDisk: &osDiskDisks,
            PartitionStyle: &partitionStyleDisks,
        },
    }
	vmIdTargetServer:= ""
	idTargetServer:= "c1bd67b6-1caa-403e-9e32-81d2feafcda9"
	osVersionTargetServer:= "WINDOWS2016_64BIT"
	systemDirTargetServer:= "Y:\Windows\System32"
	targetServerbody := &model.TargetServer{
		Disks: listDisksTargetServer,
		VmId: &vmIdTargetServer,
		Id: &idTargetServer,
		OsVersion: &osVersionTargetServer,
		SystemDir: &systemDirTargetServer,
		OsType: model.GetTargetServerOsTypeEnum().WINDOWS,
		Name: "",
	}
	idSourceServer:= "1cce5dab-df33-4abe-b2ac-e94fa05d6a01"
	osVersionSourceServer:= "WINDOWS2016_64BIT"
	migrationCycleSourceServer:= model.GetPostSourceServerBodyMigrationCycleEnum().REPLICATING
	stateSourceServer:= model.GetPostSourceServerBodyStateEnum().INITIALIZE
	oemSystemSourceServer:= false
	sourceServerbody := &model.PostSourceServerBody{
		Id: &idSourceServer,
		Ip: "192.168.0.154",
		Name: "name-win16",
		OsType: model.GetPostSourceServerBodyOsTypeEnum().WINDOWS,
		OsVersion: &osVersionSourceServer,
		AgentVersion: "1.2.0",
		MigrationCycle: &migrationCycleSourceServer,
		State: &stateSourceServer,
		OemSystem: &oemSystemSourceServer,
	}
	totalTimePutTaskReq:= int64(115)
	errorJsonPutTaskReq:= ""
	migrateSpeedPutTaskReq:= float64(0.0)
	startDatePutTaskReq:= int64(1598435784000)
	createDatePutTaskReq:= int64(1598435778000)
	statePutTaskReq:= "RUNNING"
	vmTemplateIdPutTaskReq:= "38d53ae9-70e3-4587-89c9-6219d3d4e962"
	projectIdPutTaskReq:= "b276e6fb38c74aa2ba4598f049745ce9"
	projectNamePutTaskReq:= "project name"
	speedLimitPutTaskReq:= int32(0)
	regionNamePutTaskReq:= "region name"
	startTargetServerPutTaskReq:= true
	regionIdPutTaskReq:= "region id"
	priorityPutTaskReq:= model.GetPutTaskReqPriorityEnum().E_1
	osTypePutTaskReq:= model.GetPutTaskReqOsTypeEnum().WINDOWS
	typePutTaskReq:= model.GetPutTaskReqTypeEnum().MIGRATE_BLOCK
	namePutTaskReq:= "MigrationTask"
	request.Body = &model.PutTaskReq{
		SubTasks: &listSubTasksbody,
		TotalTime: &totalTimePutTaskReq,
		ErrorJson: &errorJsonPutTaskReq,
		MigrateSpeed: &migrateSpeedPutTaskReq,
		StartDate: &startDatePutTaskReq,
		CreateDate: &createDatePutTaskReq,
		State: &statePutTaskReq,
		TargetServer: targetServerbody,
		SourceServer: sourceServerbody,
		VmTemplateId: &vmTemplateIdPutTaskReq,
		ProjectId: &projectIdPutTaskReq,
		ProjectName: &projectNamePutTaskReq,
		SpeedLimit: &speedLimitPutTaskReq,
		RegionName: &regionNamePutTaskReq,
		StartTargetServer: &startTargetServerPutTaskReq,
		RegionId: &regionIdPutTaskReq,
		Priority: &priorityPutTaskReq,
		OsType: &osTypePutTaskReq,
		Type: &typePutTaskReq,
		Name: &namePutTaskReq,
	}
	response, err := client.UpdateTask(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK

错误码

请参见错误码

分享:

    相关文档

    相关产品